libexplain  1.4.D001
libexplain/buffer/ebadf.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2013, 2014 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 3 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/fcntl.h>
00021 
00022 #include <libexplain/buffer/check_fildes_range.h>
00023 #include <libexplain/buffer/ebadf.h>
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/software_error.h>
00026 #include <libexplain/gettext.h>
00027 
00028 
00029 void
00030 explain_buffer_ebadf(explain_string_buffer_t *sb, int fildes,
00031     const char *caption)
00032 {
00033     if (explain_buffer_check_fildes_range(sb, fildes, caption) >= 0)
00034     {
00035         /* all done */
00036     }
00037     else if (fcntl(fildes, F_GETFL, 0) < 0)
00038     {
00039         explain_string_buffer_printf_gettext
00040         (
00041             sb,
00042             /*
00043              * xgettext: This message is used when a file descriptor is not
00044              * valid and does not refer to an open file.
00045              *
00046              * %1$s => the name of the offending system call argument.
00047              */
00048             i18n("the %s argument does not refer to an open file"),
00049             caption
00050         );
00051     }
00052     else
00053     {
00054         explain_buffer_einval_vague(sb, caption);
00055     }
00056     explain_buffer_software_error(sb);
00057 }
00058 
00059 
00060 void
00061 explain_buffer_ebadf_stream(explain_string_buffer_t *sb, const char *caption)
00062 {
00063     /*
00064      * Linux man fileno says:
00065      * "This function should not fail and thus not set errno.
00066      * However, in case fileno() detects that its argument is not a
00067      * valid stream, it must return -1 and set errno to EBADF."
00068      */
00069     explain_string_buffer_printf_gettext
00070     (
00071         sb,
00072         /*
00073          * xgettext: This error message is issued when a FILE* pointer
00074          * does not refer to a valid file stream.
00075          *
00076          * %1$s => the name of the offending system call argument
00077          */
00078         i18n("the %s argument does not refer a valid file stream"),
00079         caption
00080     );
00081 }
00082 
00083 
00084 void
00085 explain_buffer_ebadf_dir(explain_string_buffer_t *sb, const char *caption)
00086 {
00087     explain_string_buffer_printf_gettext
00088     (
00089         sb,
00090         /*
00091          * xgettext: This error message is issued when a DIR* pointer
00092          * does not refer to a valid directory stream.
00093          *
00094          * %1$s => the name of the offending system call argument
00095          */
00096         i18n("the %s argument does not refer a valid directory stream"),
00097         caption
00098     );
00099 }
00100 
00101 
00102 /* vim: set ts=8 sw=4 et : */