libexplain  1.4.D001
libexplain/buffer/errno/tcsetattr.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/einval.h>
00023 #include <libexplain/buffer/enosys.h>
00024 #include <libexplain/buffer/errno/generic.h>
00025 #include <libexplain/buffer/errno/tcsetattr.h>
00026 #include <libexplain/buffer/fildes.h>
00027 #include <libexplain/buffer/is_the_null_pointer.h>
00028 #include <libexplain/buffer/tcsetattr_options.h>
00029 #include <libexplain/buffer/termios.h>
00030 #include <libexplain/explanation.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_tcsetattr_system_call(explain_string_buffer_t *sb, int
00035     errnum, int fildes, int options, const struct termios *data)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "tcsetattr(fildes = ");
00039     explain_buffer_fildes(sb, fildes);
00040     explain_string_buffer_puts(sb, ", options = ");
00041     explain_buffer_tcsetattr_options(sb, options);
00042     explain_string_buffer_puts(sb, ", data = ");
00043     explain_buffer_termios(sb, data);
00044     explain_string_buffer_putc(sb, ')');
00045 }
00046 
00047 
00048 void
00049 explain_buffer_errno_tcsetattr_explanation(explain_string_buffer_t *sb, int
00050     errnum, const char *syscall_name, int fildes, int options, const struct
00051     termios *data)
00052 {
00053     /*
00054      * http://www.opengroup.org/onlinepubs/009695399/functions/tcsetattr.html
00055      */
00056     (void)options;
00057     switch (errnum)
00058     {
00059     case EBADF:
00060         explain_buffer_ebadf(sb, fildes, "fildes");
00061         break;
00062 
00063     case EINVAL:
00064         if (!data)
00065         {
00066             explain_buffer_is_the_null_pointer(sb, "data");
00067             break;
00068         }
00069         explain_buffer_einval_vague(sb, "options");
00070         break;
00071 
00072     case ENOTTY:
00073     case ENOSYS:
00074 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS
00075     case EOPNOTSUPP:
00076 #endif
00077 #ifdef ENOIOCTLCMD
00078     case ENOIOCTLCMD:
00079 #endif
00080 #ifdef ENOIOCTL
00081     case ENONOIOCTL:
00082 #endif
00083         explain_buffer_enosys_fildes(sb, fildes, "fildes", syscall_name);
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_tcsetattr(explain_string_buffer_t *sb, int errnum, int
00095     fildes, int options, const struct termios *data)
00096 {
00097     explain_explanation_t exp;
00098 
00099     explain_explanation_init(&exp, errnum);
00100     explain_buffer_errno_tcsetattr_system_call(&exp.system_call_sb, errnum,
00101         fildes, options, data);
00102     explain_buffer_errno_tcsetattr_explanation(&exp.explanation_sb, errnum,
00103         "tcsetattr", fildes, options, data);
00104     explain_explanation_assemble(&exp, sb);
00105 }
00106 
00107 
00108 /* vim: set ts=8 sw=4 et : */