libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 3 of the License, or (at 00008 * your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/errno.h> 00020 00021 #include <libexplain/buffer/errno/vasprintf.h> 00022 #include <libexplain/buffer/errno/vsnprintf.h> 00023 #include <libexplain/buffer/is_the_null_pointer.h> 00024 #include <libexplain/buffer/pathname.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/buffer/va_list.h> 00027 #include <libexplain/explanation.h> 00028 00029 00030 static void 00031 explain_buffer_errno_vasprintf_system_call(explain_string_buffer_t *sb, 00032 int errnum, char **data, const char *format, va_list ap) 00033 { 00034 (void)errnum; 00035 explain_string_buffer_puts(sb, "vasprintf(data = "); 00036 explain_buffer_pointer(sb, data); 00037 explain_string_buffer_puts(sb, ", format = "); 00038 explain_buffer_pathname(sb, format); 00039 explain_string_buffer_puts(sb, ", ap = "); 00040 explain_buffer_va_list(sb, ap); 00041 explain_string_buffer_putc(sb, ')'); 00042 } 00043 00044 00045 void 00046 explain_buffer_errno_vasprintf_explanation(explain_string_buffer_t *sb, 00047 int errnum, const char *syscall_name, char **data, const char *format, 00048 va_list ap) 00049 { 00050 char dummy[20]; 00051 if (!data) 00052 { 00053 explain_buffer_is_the_null_pointer(sb, "data"); 00054 return; 00055 } 00056 explain_buffer_errno_vsnprintf_explanation 00057 ( 00058 sb, 00059 errnum, 00060 syscall_name, 00061 dummy, 00062 sizeof(dummy), 00063 format, 00064 ap 00065 ); 00066 } 00067 00068 00069 void 00070 explain_buffer_errno_vasprintf(explain_string_buffer_t *sb, int errnum, 00071 char **data, const char *format, va_list ap) 00072 { 00073 explain_explanation_t exp; 00074 00075 explain_explanation_init(&exp, errnum); 00076 explain_buffer_errno_vasprintf_system_call(&exp.system_call_sb, errnum, 00077 data, format, ap); 00078 explain_buffer_errno_vasprintf_explanation(&exp.explanation_sb, errnum, 00079 "vasprintf", data, format, ap); 00080 explain_explanation_assemble(&exp, sb); 00081 } 00082 00083 00084 /* vim: set ts=8 sw=4 et : */