libexplain  1.4.D001
libexplain/buffer/errno/setvbuf.c
Go to the documentation of this file.
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
00012  * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser
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/ebadf.h>
00022 #include <libexplain/buffer/einval.h>
00023 #include <libexplain/buffer/enomem.h>
00024 #include <libexplain/buffer/errno/generic.h>
00025 #include <libexplain/buffer/errno/setvbuf.h>
00026 #include <libexplain/buffer/setvbuf_mode.h>
00027 #include <libexplain/buffer/stream.h>
00028 #include <libexplain/buffer/pointer.h>
00029 #include <libexplain/buffer/size_t.h>
00030 #include <libexplain/explanation.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_setvbuf_system_call(explain_string_buffer_t *sb,
00035     int errnum, FILE *fp, char *data, int mode, size_t size)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "setvbuf(fp = ");
00039     explain_buffer_stream(sb, fp);
00040     explain_string_buffer_puts(sb, ", data = ");
00041     explain_buffer_pointer(sb, data);
00042     explain_string_buffer_puts(sb, ", mode = ");
00043     explain_buffer_setvbuf_mode(sb, mode);
00044     explain_string_buffer_puts(sb, ", size = ");
00045     explain_buffer_size_t(sb, size);
00046     explain_string_buffer_putc(sb, ')');
00047 }
00048 
00049 
00050 void
00051 explain_buffer_errno_setvbuf_explanation(explain_string_buffer_t *sb,
00052     int errnum, const char *syscall_name, FILE *fp, char *data, int mode,
00053     size_t size)
00054 {
00055     /*
00056      * http://www.opengroup.org/onlinepubs/009695399/functions/setvbuf.html
00057      */
00058     (void)fp;
00059     (void)data;
00060     (void)size;
00061     switch (errnum)
00062     {
00063     case EINVAL:
00064         switch (mode)
00065         {
00066         case _IOFBF:
00067         case _IOLBF:
00068         case _IONBF:
00069             explain_buffer_ebadf_stream(sb, "fp");
00070             break;
00071 
00072         default:
00073             explain_buffer_einval_vague(sb, "mode");
00074             break;
00075         }
00076         break;
00077 
00078     case EBADF:
00079         explain_buffer_ebadf_stream(sb, "fp");
00080         break;
00081 
00082     case ENOMEM:
00083         explain_buffer_enomem_kernel(sb);
00084         break;
00085 
00086     default:
00087         explain_buffer_errno_generic(sb, errnum, syscall_name);
00088         break;
00089     }
00090 }
00091 
00092 
00093 void
00094 explain_buffer_errno_setvbuf(explain_string_buffer_t *sb, int errnum, FILE *fp,
00095     char *data, int mode, size_t size)
00096 {
00097     explain_explanation_t exp;
00098 
00099     if (errnum == 0)
00100         errnum = EINVAL;
00101     explain_explanation_init(&exp, errnum);
00102     explain_buffer_errno_setvbuf_system_call(&exp.system_call_sb, errnum, fp,
00103         data, mode, size);
00104     explain_buffer_errno_setvbuf_explanation(&exp.explanation_sb, errnum,
00105         "setvbuf", fp, data, mode, size);
00106     explain_explanation_assemble(&exp, sb);
00107 }
00108 
00109 
00110 /* vim: set ts=8 sw=4 et : */