libexplain  1.4.D001
libexplain/asprintf.c
Go to the documentation of this file.
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 #include <libexplain/ac/stdio.h>
00021 
00022 #include <libexplain/asprintf.h>
00023 #include <libexplain/buffer/errno/asprintf.h>
00024 #include <libexplain/common_message_buffer.h>
00025 
00026 
00027 const char *
00028 explain_asprintf(char **data, const char *format, ...)
00029 {
00030     int             errnum;
00031     va_list         ap;
00032     explain_string_buffer_t sb;
00033 
00034     errnum = errno;
00035     va_start(ap, format);
00036     explain_string_buffer_init
00037     (
00038         &sb,
00039         explain_common_message_buffer,
00040         explain_common_message_buffer_size
00041     );
00042     explain_buffer_errno_asprintf(&sb, errnum, data, format, ap);
00043     va_end(ap);
00044     return explain_common_message_buffer;
00045 }
00046 
00047 
00048 const char *
00049 explain_errno_asprintf(int errnum, char **data, const char *format, ...)
00050 {
00051     va_list         ap;
00052     explain_string_buffer_t sb;
00053 
00054     va_start(ap, format);
00055     explain_string_buffer_init
00056     (
00057         &sb,
00058         explain_common_message_buffer,
00059         explain_common_message_buffer_size
00060     );
00061     explain_buffer_errno_asprintf(&sb, errnum, data, format, ap);
00062     va_end(ap);
00063     return explain_common_message_buffer;
00064 }
00065 
00066 
00067 void
00068 explain_message_asprintf(char *message, int message_size, char **data,
00069     const char *format, ...)
00070 {
00071     va_list         ap;
00072     int             errnum;
00073     explain_string_buffer_t sb;
00074 
00075     errnum = errno;
00076     va_start(ap, format);
00077     explain_string_buffer_init(&sb, message, message_size);
00078     explain_buffer_errno_asprintf(&sb, errnum, data, format, ap);
00079     va_end(ap);
00080 }
00081 
00082 
00083 void
00084 explain_message_errno_asprintf(char *message, int message_size, int errnum,
00085     char **data, const char *format, ...)
00086 {
00087     va_list         ap;
00088     explain_string_buffer_t sb;
00089 
00090     va_start(ap, format);
00091     explain_string_buffer_init(&sb, message, message_size);
00092     explain_buffer_errno_asprintf(&sb, errnum, data, format, ap);
00093     va_end(ap);
00094 }
00095 
00096 
00097 /* vim: set ts=8 sw=4 et : */