libexplain  1.4.D001
libexplain/buffer/errno/iconv.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 
00021 #include <libexplain/buffer/errno/generic.h>
00022 #include <libexplain/buffer/errno/iconv.h>
00023 #include <libexplain/buffer/is_the_null_pointer.h>
00024 #include <libexplain/buffer/pointer.h>
00025 #include <libexplain/buffer/size_t.h>
00026 #include <libexplain/explanation.h>
00027 
00028 
00029 static void
00030 explain_buffer_errno_iconv_system_call(explain_string_buffer_t *sb, int errnum,
00031     iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t
00032     *outbytesleft)
00033 {
00034     (void)errnum;
00035     explain_string_buffer_puts(sb, "iconv(cd = ");
00036     explain_string_buffer_printf(sb, "%ld", (long)cd);
00037     explain_string_buffer_puts(sb, ", inbuf = ");
00038     explain_buffer_pointer(sb, inbuf);
00039     explain_string_buffer_puts(sb, ", inbytesleft = ");
00040     explain_buffer_size_t_star(sb, inbytesleft);
00041     explain_string_buffer_puts(sb, ", outbuf = ");
00042     explain_buffer_pointer(sb, outbuf);
00043     explain_string_buffer_puts(sb, ", outbytesleft = ");
00044     explain_buffer_size_t_star(sb, outbytesleft);
00045     explain_string_buffer_putc(sb, ')');
00046 }
00047 
00048 
00049 void
00050 explain_buffer_errno_iconv_explanation(explain_string_buffer_t *sb, int errnum,
00051     const char *syscall_name, iconv_t cd, char **inbuf, size_t *inbytesleft,
00052     char **outbuf, size_t *outbytesleft)
00053 {
00054     (void)inbuf;
00055     (void)inbytesleft;
00056     (void)outbuf;
00057     (void)outbytesleft;
00058     switch (errnum)
00059     {
00060     case EBADF:
00061         if (cd == NULL)
00062         {
00063             explain_buffer_is_the_null_pointer(sb, "cd");
00064             break;
00065         }
00066         explain_string_buffer_printf
00067         (
00068             sb,
00069             /* FIXME: i18n */
00070             "the %s argument does not refer to a valid conversion descriptor",
00071             "cd"
00072         );
00073         break;
00074 
00075     case E2BIG:
00076         explain_string_buffer_puts
00077         (
00078             sb,
00079             /* FIXME: i18n */
00080             "there is not sufficient room at *outbuf"
00081         );
00082         break;
00083 
00084     case EILSEQ:
00085         explain_string_buffer_puts
00086         (
00087             sb,
00088             /* FIXME: i18n */
00089             "An invalid multi-byte sequence has been encountered in the input"
00090         );
00091         break;
00092 
00093     case EINVAL:
00094         explain_string_buffer_puts
00095         (
00096             sb,
00097             /* FIXME: i18n */
00098             "An incomplete multi-byte sequence has been encountered at  "
00099             "the end of input "
00100         );
00101         break;
00102 
00103     default:
00104         explain_buffer_errno_generic(sb, errnum, syscall_name);
00105         break;
00106     }
00107 }
00108 
00109 
00110 void
00111 explain_buffer_errno_iconv(explain_string_buffer_t *sb, int errnum, iconv_t cd,
00112     char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
00113 {
00114     explain_explanation_t exp;
00115 
00116     explain_explanation_init(&exp, errnum);
00117     explain_buffer_errno_iconv_system_call(&exp.system_call_sb, errnum, cd,
00118         inbuf, inbytesleft, outbuf, outbytesleft);
00119     explain_buffer_errno_iconv_explanation(&exp.explanation_sb, errnum, "iconv",
00120         cd, inbuf, inbytesleft, outbuf, outbytesleft);
00121     explain_explanation_assemble(&exp, sb);
00122 }
00123 
00124 
00125 /* vim: set ts=8 sw=4 et : */