libexplain  1.4.D001
libexplain/buffer/errno/fgetpos.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 #include <libexplain/ac/stdio.h>
00021 
00022 #include <libexplain/buffer/ebadf.h>
00023 #include <libexplain/buffer/einval.h>
00024 #include <libexplain/buffer/errno/fgetpos.h>
00025 #include <libexplain/buffer/errno/lseek.h>
00026 #include <libexplain/buffer/fpos_t.h>
00027 #include <libexplain/buffer/stream.h>
00028 #include <libexplain/explanation.h>
00029 #include <libexplain/stream_to_fildes.h>
00030 
00031 
00032 static void
00033 explain_buffer_errno_fgetpos_system_call(explain_string_buffer_t *sb,
00034     int errnum, FILE *fp, fpos_t *pos)
00035 {
00036     (void)errnum;
00037     explain_string_buffer_puts(sb, "fgetpos(fp = ");
00038     explain_buffer_stream(sb, fp);
00039     explain_string_buffer_puts(sb, ", pos = ");
00040     explain_buffer_fpos_t(sb, pos, 0);
00041     explain_string_buffer_putc(sb, ')');
00042 }
00043 
00044 
00045 void
00046 explain_buffer_errno_fgetpos_explanation(explain_string_buffer_t *sb,
00047     int errnum, const char *syscall_name, FILE *fp, fpos_t *pos)
00048 {
00049     int             fildes;
00050 
00051     /*
00052      * http://www.opengroup.org/onlinepubs/009695399/functions/fgetpos.html
00053      */
00054     (void)fp;
00055     (void)pos;
00056     switch (errnum)
00057     {
00058     case EBADF:
00059     case EINVAL:
00060         explain_buffer_ebadf_stream(sb, "fp");
00061         break;
00062 
00063     default:
00064         fildes = explain_stream_to_fildes(fp);
00065         explain_buffer_errno_lseek_explanation
00066         (
00067             sb,
00068             errnum,
00069             syscall_name,
00070             fildes,
00071             0L,
00072             SEEK_CUR
00073         );
00074         break;
00075     }
00076 }
00077 
00078 
00079 void
00080 explain_buffer_errno_fgetpos(explain_string_buffer_t *sb, int errnum, FILE *fp,
00081     fpos_t *pos)
00082 {
00083     explain_explanation_t exp;
00084 
00085     explain_explanation_init(&exp, errnum);
00086     explain_buffer_errno_fgetpos_system_call(&exp.system_call_sb, errnum, fp,
00087         pos);
00088     explain_buffer_errno_fgetpos_explanation(&exp.explanation_sb, errnum,
00089         "fgetpos", fp, pos);
00090     explain_explanation_assemble(&exp, sb);
00091 }
00092 
00093 
00094 /* vim: set ts=8 sw=4 et : */