libexplain  1.4.D001
libexplain/buffer/errno/tcgetattr.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 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/efault.h>
00023 #include <libexplain/buffer/enosys.h>
00024 #include <libexplain/buffer/errno/generic.h>
00025 #include <libexplain/buffer/errno/tcgetattr.h>
00026 #include <libexplain/buffer/fildes.h>
00027 #include <libexplain/buffer/is_the_null_pointer.h>
00028 #include <libexplain/buffer/pointer.h>
00029 #include <libexplain/explanation.h>
00030 
00031 
00032 static void
00033 explain_buffer_errno_tcgetattr_system_call(explain_string_buffer_t *sb, int
00034     errnum, int fildes, struct termios *data)
00035 {
00036     (void)errnum;
00037     explain_string_buffer_puts(sb, "tcgetattr(fildes = ");
00038     explain_buffer_fildes(sb, fildes);
00039     explain_string_buffer_puts(sb, ", data = ");
00040     explain_buffer_pointer(sb, data);
00041     explain_string_buffer_putc(sb, ')');
00042 }
00043 
00044 
00045 void
00046 explain_buffer_errno_tcgetattr_explanation(explain_string_buffer_t *sb, int
00047     errnum, const char *syscall_name, int fildes, struct termios *data)
00048 {
00049     /*
00050      * http://www.opengroup.org/onlinepubs/009695399/functions/tcgetattr.html
00051      */
00052     switch (errnum)
00053     {
00054     case EBADF:
00055         explain_buffer_ebadf(sb, fildes, "fildes");
00056         break;
00057 
00058     case EINVAL:
00059         if (!data)
00060         {
00061             explain_buffer_is_the_null_pointer(sb, "data");
00062             break;
00063         }
00064         goto generic;
00065 
00066     case EFAULT:
00067         explain_buffer_efault(sb, "data");
00068         break;
00069 
00070     case ENOTTY:
00071     case ENOSYS:
00072 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS
00073     case EOPNOTSUPP:
00074 #endif
00075 #ifdef ENOIOCTLCMD
00076     case ENOIOCTLCMD:
00077 #endif
00078 #ifdef ENOIOCTL
00079     case ENONOIOCTL:
00080 #endif
00081         explain_buffer_enosys_fildes(sb, fildes, "fildes", syscall_name);
00082         break;
00083 
00084     default:
00085         generic:
00086         explain_buffer_errno_generic(sb, errnum, syscall_name);
00087         break;
00088     }
00089 }
00090 
00091 
00092 void
00093 explain_buffer_errno_tcgetattr(explain_string_buffer_t *sb, int errnum, int
00094     fildes, struct termios *data)
00095 {
00096     explain_explanation_t exp;
00097 
00098     explain_explanation_init(&exp, errnum);
00099     explain_buffer_errno_tcgetattr_system_call(&exp.system_call_sb, errnum,
00100         fildes, data);
00101     explain_buffer_errno_tcgetattr_explanation(&exp.explanation_sb, errnum,
00102         "tcgetattr", fildes, data);
00103     explain_explanation_assemble(&exp, sb);
00104 }
00105 
00106 
00107 /* vim: set ts=8 sw=4 et : */