libexplain  1.4.D001
libexplain/iocontrol/lpsettimeout.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009-2011, 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 your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00013  * 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/sys/ioctl.h>
00020 #include <libexplain/ac/errno.h>
00021 #include <libexplain/ac/linux/lp.h>
00022 #include <libexplain/ac/time.h>
00023 
00024 #include <libexplain/buffer/efault.h>
00025 #include <libexplain/buffer/einval.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/buffer/timeval.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/lpsettimeout.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef LPSETTIMEOUT
00033 
00034 
00035 static void
00036 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00037     errnum, int fildes, int request, const void *data)
00038 {
00039     (void)p;
00040     (void)errnum;
00041     (void)fildes;
00042     (void)request;
00043     explain_buffer_timeval(sb, data);
00044 }
00045 
00046 
00047 static void
00048 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00049     errnum, int fildes, int request, const void *data)
00050 {
00051     switch (errnum)
00052     {
00053     case EFAULT:
00054         explain_buffer_efault(sb, "data");
00055         break;
00056 
00057     case EINVAL:
00058         if (!data)
00059         {
00060             explain_buffer_is_the_null_pointer(sb, "data");
00061             break;
00062         }
00063         if (!explain_is_efault_pointer(data, sizeof(struct timeval)))
00064         {
00065             struct timeval tv = *(const struct timeval *)data;
00066             if (tv.tv_sec < 0 || tv.tv_usec < 0)
00067             {
00068                 explain_buffer_einval_too_small
00069                 (
00070                     sb,
00071                     "data",
00072                     (tv.tv_sec < 0 ? tv.tv_sec : tv.tv_usec)
00073                 );
00074                 break;
00075             }
00076         }
00077         /* fall through... */
00078 
00079     default:
00080         explain_iocontrol_generic_print_explanation
00081         (
00082             p,
00083             sb,
00084             errnum,
00085             fildes,
00086             request,
00087             data
00088         );
00089         break;
00090     }
00091 }
00092 
00093 
00094 const explain_iocontrol_t explain_iocontrol_lpsettimeout =
00095 {
00096     "LPSETTIMEOUT", /* name */
00097     LPSETTIMEOUT, /* value */
00098     0, /* disambiguate */
00099     0, /* print_name */
00100     print_data,
00101     print_explanation,
00102     0, /* print_data_returned */
00103     sizeof(struct timeval), /* data_size */
00104     "struct timeval *", /* data_type */
00105     IOCONTROL_FLAG_NON_META, /* flags */
00106     __FILE__,
00107     __LINE__,
00108 };
00109 
00110 #else /* ndef LPSETTIMEOUT */
00111 
00112 const explain_iocontrol_t explain_iocontrol_lpsettimeout =
00113 {
00114     0, /* name */
00115     0, /* value */
00116     0, /* disambiguate */
00117     0, /* print_name */
00118     0, /* print_data */
00119     0, /* print_explanation */
00120     0, /* print_data_returned */
00121     0, /* data_size */
00122     0, /* data_type */
00123     0, /* flags */
00124     __FILE__,
00125     __LINE__,
00126 };
00127 
00128 #endif /* LPSETTIMEOUT */
00129 
00130 
00131 /* vim: set ts=8 sw=4 et : */