libexplain  1.4.D001
libexplain/buffer/errno/eventfd.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2013, 2014 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/einval.h>
00022 #include <libexplain/buffer/emfile.h>
00023 #include <libexplain/buffer/enfile.h>
00024 #include <libexplain/buffer/enodev.h>
00025 #include <libexplain/buffer/enomem.h>
00026 #include <libexplain/buffer/enosys.h>
00027 #include <libexplain/buffer/errno/eventfd.h>
00028 #include <libexplain/buffer/errno/generic.h>
00029 #include <libexplain/buffer/eventfd_flags.h>
00030 #include <libexplain/explanation.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_eventfd_system_call(explain_string_buffer_t *sb, int
00035     errnum, unsigned initval, int flags)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "eventfd(initval = ");
00039     explain_string_buffer_printf(sb, "%u", initval);
00040     explain_string_buffer_puts(sb, ", flags = ");
00041     explain_buffer_eventfd_flags(sb, flags);
00042     explain_string_buffer_putc(sb, ')');
00043 }
00044 
00045 
00046 static void
00047 explain_buffer_errno_eventfd_explanation(explain_string_buffer_t *sb,
00048     int errnum, unsigned int initval, int flags)
00049 {
00050     /*
00051      * http://www.opengroup.org/onlinepubs/009695399/functions/eventfd.html
00052      */
00053     (void)initval;
00054     (void)flags;
00055     switch (errnum)
00056     {
00057     case EINVAL:
00058         /*
00059          * Flags is invalid; or,
00060          * in Linux 2.6.26 or earlier, flags is non-zero.
00061          */
00062         explain_buffer_einval_bits(sb, "flags");
00063         break;
00064 
00065     case EMFILE:
00066         explain_buffer_emfile(sb);
00067         break;
00068 
00069     case ENFILE:
00070         explain_buffer_enfile(sb);
00071         break;
00072 
00073     case ENODEV:
00074         explain_buffer_enodev_anon_inodes(sb, "eventfd");
00075         break;
00076 
00077     case ENOMEM:
00078         explain_buffer_enomem_kernel(sb);
00079         break;
00080 
00081     case ENOSYS:
00082         explain_buffer_enosys_vague(sb, "eventfd");
00083         break;
00084 
00085     default:
00086         explain_buffer_errno_generic(sb, errnum, "eventfd");
00087         break;
00088     }
00089 }
00090 
00091 
00092 void
00093 explain_buffer_errno_eventfd(explain_string_buffer_t *sb, int errnum,
00094     unsigned int initval, int flags)
00095 {
00096     explain_explanation_t exp;
00097 
00098     explain_explanation_init(&exp, errnum);
00099     explain_buffer_errno_eventfd_system_call(&exp.system_call_sb, errnum,
00100         initval, flags);
00101     explain_buffer_errno_eventfd_explanation(&exp.explanation_sb, errnum,
00102         initval, flags);
00103     explain_explanation_assemble(&exp, sb);
00104 }
00105 
00106 
00107 /* vim: set ts=8 sw=4 et : */