libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2010, 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/buffer/errno/snprintf.h> 00023 #include <libexplain/common_message_buffer.h> 00024 #include <libexplain/snprintf.h> 00025 00026 00027 const char * 00028 explain_snprintf(char *data, size_t data_size, const char *format, ...) 00029 { 00030 int errnum; 00031 va_list ap; 00032 explain_string_buffer_t sb; 00033 00034 va_start(ap, format); 00035 errnum = errno; 00036 explain_string_buffer_init 00037 ( 00038 &sb, 00039 explain_common_message_buffer, 00040 explain_common_message_buffer_size 00041 ); 00042 explain_buffer_errno_snprintf(&sb, errnum, data, data_size, format, ap); 00043 va_end(ap); 00044 return explain_common_message_buffer; 00045 } 00046 00047 00048 const char * 00049 explain_errno_snprintf(int errnum, char *data, size_t data_size, const char 00050 *format, ...) 00051 { 00052 va_list ap; 00053 explain_string_buffer_t sb; 00054 00055 va_start(ap, format); 00056 explain_string_buffer_init 00057 ( 00058 &sb, 00059 explain_common_message_buffer, 00060 explain_common_message_buffer_size 00061 ); 00062 explain_buffer_errno_snprintf(&sb, errnum, data, data_size, format, ap); 00063 va_end(ap); 00064 return explain_common_message_buffer; 00065 } 00066 00067 00068 void 00069 explain_message_snprintf(char *message, int message_size, char *data, size_t 00070 data_size, const char *format, ...) 00071 { 00072 int errnum; 00073 va_list ap; 00074 explain_string_buffer_t sb; 00075 00076 va_start(ap, format); 00077 errnum = errno; 00078 explain_string_buffer_init(&sb, message, message_size); 00079 explain_buffer_errno_snprintf(&sb, errnum, data, data_size, format, ap); 00080 va_end(ap); 00081 } 00082 00083 00084 void 00085 explain_message_errno_snprintf(char *message, int message_size, int errnum, char 00086 *data, size_t data_size, const char *format, ...) 00087 { 00088 va_list ap; 00089 explain_string_buffer_t sb; 00090 00091 va_start(ap, format); 00092 explain_string_buffer_init(&sb, message, message_size); 00093 explain_buffer_errno_snprintf(&sb, errnum, data, data_size, format, ap); 00094 va_end(ap); 00095 } 00096 00097 00098 /* vim: set ts=8 sw=4 et : */