libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser 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/netdb.h> 00020 00021 #include <libexplain/buffer/gai_strerror.h> 00022 #include <libexplain/buffer/strerror.h> 00023 #include <libexplain/option.h> 00024 #include <libexplain/parse_bits.h> 00025 #include <libexplain/sizeof.h> 00026 00027 00028 static const explain_parse_bits_table_t table[] = 00029 { 00030 { "EAI_BADFLAGS", EAI_BADFLAGS }, 00031 { "EAI_NONAME", EAI_NONAME }, 00032 { "EAI_AGAIN", EAI_AGAIN }, 00033 { "EAI_FAIL", EAI_FAIL }, 00034 { "EAI_FAMILY", EAI_FAMILY }, 00035 { "EAI_SOCKTYPE", EAI_SOCKTYPE }, 00036 { "EAI_SERVICE", EAI_SERVICE }, 00037 { "EAI_MEMORY", EAI_MEMORY }, 00038 { "EAI_SYSTEM", EAI_SYSTEM }, 00039 #ifdef EAI_OVERFLOW 00040 { "EAI_OVERFLOW", EAI_OVERFLOW }, 00041 #endif 00042 #ifdef EAI_NODATA 00043 { "EAI_NODATA", EAI_NODATA }, 00044 #endif 00045 #ifdef EAI_ADDRFAMILY 00046 { "EAI_ADDRFAMILY", EAI_ADDRFAMILY }, 00047 #endif 00048 #ifdef EAI_INPROGRESS 00049 { "EAI_INPROGRESS", EAI_INPROGRESS }, 00050 #endif 00051 #ifdef EAI_CANCELED 00052 { "EAI_CANCELED", EAI_CANCELED }, 00053 #endif 00054 #ifdef EAI_NOTCANCELED 00055 { "EAI_NOTCANCELED", EAI_NOTCANCELED }, 00056 #endif 00057 #ifdef EAI_ALLDONE 00058 { "EAI_ALLDONE", EAI_ALLDONE }, 00059 #endif 00060 #ifdef EAI_INTR 00061 { "EAI_INTR", EAI_INTR }, 00062 #endif 00063 #ifdef EAI_IDN_ENCODE 00064 { "EAI_IDN_ENCODE", EAI_IDN_ENCODE }, 00065 #endif 00066 }; 00067 00068 00069 void 00070 explain_buffer_gai_strerror(explain_string_buffer_t *sb, int errnum) 00071 { 00072 const explain_parse_bits_table_t *tp; 00073 int first; 00074 00075 if (errnum > 0) 00076 { 00077 explain_buffer_strerror(sb, errnum); 00078 return; 00079 } 00080 00081 explain_string_buffer_puts(sb, gai_strerror(errnum)); 00082 00083 first = 1; 00084 if (explain_option_numeric_errno()) 00085 { 00086 explain_string_buffer_printf(sb, " (%d", errnum); 00087 first = 0; 00088 } 00089 tp = explain_parse_bits_find_by_value(errnum, table, SIZEOF(table)); 00090 if (tp) 00091 { 00092 if (first) 00093 explain_string_buffer_puts(sb, " ("); 00094 else 00095 explain_string_buffer_puts(sb, ", "); 00096 explain_string_buffer_puts(sb, tp->name); 00097 first = 0; 00098 } 00099 if (!first) 00100 explain_string_buffer_putc(sb, ')'); 00101 } 00102 00103 00104 /* vim: set ts=8 sw=4 et : */