libexplain  1.4.D001
libexplain/buffer/errno/vsprintf.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2010, 2011, 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/dangerous.h>
00022 #include <libexplain/buffer/efault.h>
00023 #include <libexplain/buffer/errno/vsprintf.h>
00024 #include <libexplain/buffer/errno/vsnprintf.h>
00025 #include <libexplain/buffer/is_the_null_pointer.h>
00026 #include <libexplain/buffer/pathname.h>
00027 #include <libexplain/buffer/pointer.h>
00028 #include <libexplain/buffer/va_list.h>
00029 #include <libexplain/explanation.h>
00030 #include <libexplain/is_efault.h>
00031 #include <libexplain/printf_format.h>
00032 
00033 
00034 static void
00035 explain_buffer_errno_vsprintf_system_call(explain_string_buffer_t *sb, int
00036     errnum, char *data, const char *format, va_list ap)
00037 {
00038     (void)errnum;
00039     explain_string_buffer_puts(sb, "vsprintf(data = ");
00040     explain_buffer_pointer(sb, data);
00041     explain_string_buffer_puts(sb, ", format = ");
00042     explain_buffer_pathname(sb, format);
00043     explain_string_buffer_puts(sb, ", ap = ");
00044     explain_buffer_va_list(sb, ap);
00045     explain_string_buffer_putc(sb, ')');
00046 
00047     explain_string_buffer_puts(sb->footnotes, "; ");
00048     explain_buffer_dangerous_system_call2
00049     (
00050         sb->footnotes,
00051         "vsprintf",
00052         "vsnprintf"
00053     );
00054 }
00055 
00056 
00057 void
00058 explain_buffer_errno_vsprintf_explanation(explain_string_buffer_t *sb,
00059     int errnum, const char *syscall_name, char *data, const char *format,
00060     va_list ap)
00061 {
00062     /*
00063      * http://www.opengroup.org/onlinepubs/009695399/functions/vsprintf.html
00064      */
00065     explain_buffer_errno_vsnprintf_explanation
00066     (
00067         sb,
00068         errnum,
00069         syscall_name,
00070         data,
00071         INT_MAX, /* this right here is why it is dangerous */
00072         format,
00073         ap
00074     );
00075 }
00076 
00077 
00078 void
00079 explain_buffer_errno_vsprintf(explain_string_buffer_t *sb, int errnum,
00080     char *data, const char *format, va_list ap)
00081 {
00082     explain_explanation_t exp;
00083 
00084     explain_explanation_init(&exp, errnum);
00085     explain_buffer_errno_vsprintf_system_call(&exp.system_call_sb, errnum, data,
00086         format, ap);
00087     explain_buffer_errno_vsprintf_explanation(&exp.explanation_sb, errnum,
00088         "vsprintf", data, format, ap);
00089     explain_explanation_assemble(&exp, sb);
00090 }
00091 
00092 
00093 /* vim: set ts=8 sw=4 et : */