libexplain  1.4.D001
libexplain/iocontrol/vidiocgchan.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - a library of system-call-specific strerror replacements
00003  * Copyright (C) 2011, 2013 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 it
00007  * under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014  * 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/errno.h>
00021 #include <libexplain/ac/linux/videodev.h>
00022 #include <libexplain/ac/sys/ioctl.h>
00023 
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/is_the_null_pointer.h>
00026 #include <libexplain/buffer/video_channel.h>
00027 #include <libexplain/iocontrol/generic.h>
00028 #include <libexplain/iocontrol/vidiocgchan.h>
00029 #include <libexplain/is_efault.h>
00030 
00031 #ifdef VIDIOCGCHAN
00032 
00033 
00034 static void
00035 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00036     int errnum, int fildes, int request, const void *data)
00037 {
00038     (void)p;
00039     (void)errnum;
00040     (void)fildes;
00041     (void)request;
00042     explain_buffer_video_channel(sb, data, 0);
00043 }
00044 
00045 
00046 static void
00047 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00048     int errnum, int fildes, int request, const void *data)
00049 {
00050     switch (errnum)
00051     {
00052     case EINVAL:
00053         if (!data)
00054         {
00055             explain_buffer_is_the_null_pointer(sb, "data");
00056             return;
00057         }
00058 
00059         {
00060             const struct video_channel *arg;
00061 
00062             arg = data;
00063             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00064             {
00065                 int             nchannels;
00066 
00067                 nchannels = explain_video_channel_get_n(fildes);
00068 
00069                 /* pre-3.1: the ioctl may not be supported */
00070                 if (nchannels == 0)
00071                 {
00072                     explain_iocontrol_generic_print_explanation
00073                     (
00074                         p,
00075                         sb,
00076                         ENOTTY,
00077                         fildes,
00078                         request,
00079                         data
00080                     );
00081                     return;
00082                 }
00083 
00084                 /* the channel number may be out of range */
00085                 if
00086                 (
00087                     nchannels > 0
00088                 &&
00089                     (unsigned)arg->channel >= (unsigned)nchannels
00090                 )
00091                 {
00092                     explain_buffer_einval_out_of_range
00093                     (
00094                         sb,
00095                         "data->channel",
00096                         0,
00097                         nchannels - 1
00098                     );
00099                     return;
00100                 }
00101             }
00102         }
00103 
00104         /* no idea */
00105         explain_buffer_einval_vague(sb, "data");
00106         break;
00107 
00108     default:
00109         explain_iocontrol_generic_print_explanation
00110         (
00111             p,
00112             sb,
00113             errnum,
00114             fildes,
00115             request,
00116             data
00117         );
00118         break;
00119     }
00120 }
00121 
00122 
00123 static void
00124 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00125     int errnum, int fildes, int request, const void *data)
00126 {
00127     (void)p;
00128     (void)errnum;
00129     (void)fildes;
00130     (void)request;
00131     explain_buffer_video_channel(sb, data, 1);
00132 }
00133 
00134 
00135 const explain_iocontrol_t explain_iocontrol_vidiocgchan =
00136 {
00137     "VIDIOCGCHAN", /* name */
00138     VIDIOCGCHAN, /* value */
00139     0, /* disambiguate */
00140     0, /* print_name */
00141     print_data,
00142     print_explanation,
00143     print_data_returned,
00144     sizeof(struct video_channel), /* data_size */
00145     "struct video_channel *", /* data_type */
00146     0, /* flags */
00147     __FILE__,
00148     __LINE__,
00149 };
00150 
00151 #else /* ndef VIDIOCGCHAN */
00152 
00153 const explain_iocontrol_t explain_iocontrol_vidiocgchan =
00154 {
00155     0, /* name */
00156     0, /* value */
00157     0, /* disambiguate */
00158     0, /* print_name */
00159     0, /* print_data */
00160     0, /* print_explanation */
00161     0, /* print_data_returned */
00162     0, /* data_size */
00163     0, /* data_type */
00164     0, /* flags */
00165     __FILE__,
00166     __LINE__,
00167 };
00168 
00169 #endif /* VIDIOCGCHAN */
00170 
00171 /* vim: set ts=8 sw=4 et : */