libexplain  1.4.D001
libexplain/iocontrol/vidioc_s_tuner.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/videodev2.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/v4l2_tuner.h>
00027 #include <libexplain/iocontrol/generic.h>
00028 #include <libexplain/iocontrol/vidioc_s_tuner.h>
00029 #include <libexplain/is_efault.h>
00030 
00031 #ifdef VIDIOC_S_TUNER
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_v4l2_tuner(sb, data, 1);
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 v4l2_tuner *arg;
00061 
00062             arg = data;
00063             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00064             {
00065                 int             ntuners;
00066 
00067                 ntuners = explain_v4l2_tuner_get_n(fildes);
00068                 if (ntuners == 0)
00069                 {
00070                     explain_iocontrol_generic_print_explanation
00071                     (
00072                         p,
00073                         sb,
00074                         ENOTTY,
00075                         fildes,
00076                         request,
00077                         data
00078                     );
00079                     return;
00080                 }
00081                 if (ntuners > 0 && arg->index >= (unsigned)ntuners)
00082                 {
00083                     explain_buffer_einval_out_of_range
00084                     (
00085                         sb,
00086                         "data->index",
00087                         0,
00088                         ntuners - 1
00089                     );
00090                     return;
00091                 }
00092             }
00093         }
00094 
00095         /* No idea */
00096         explain_buffer_einval_vague(sb, "data");
00097         break;
00098 
00099     default:
00100         explain_iocontrol_generic_print_explanation
00101         (
00102             p,
00103             sb,
00104             errnum,
00105             fildes,
00106             request,
00107             data
00108         );
00109         break;
00110     }
00111 }
00112 
00113 
00114 const explain_iocontrol_t explain_iocontrol_vidioc_s_tuner =
00115 {
00116     "VIDIOC_S_TUNER", /* name */
00117     VIDIOC_S_TUNER, /* value */
00118     0, /* disambiguate */
00119     0, /* print_name */
00120     print_data,
00121     print_explanation,
00122     0, /* print_data_returned */
00123     sizeof(struct v4l2_tuner), /* data_size */
00124     "struct v4l2_tuner *", /* data_type */
00125     0, /* flags */
00126     __FILE__,
00127     __LINE__,
00128 };
00129 
00130 #else /* ndef VIDIOC_S_TUNER */
00131 
00132 const explain_iocontrol_t explain_iocontrol_vidioc_s_tuner =
00133 {
00134     0, /* name */
00135     0, /* value */
00136     0, /* disambiguate */
00137     0, /* print_name */
00138     0, /* print_data */
00139     0, /* print_explanation */
00140     0, /* print_data_returned */
00141     0, /* data_size */
00142     0, /* data_type */
00143     0, /* flags */
00144     __FILE__,
00145     __LINE__,
00146 };
00147 
00148 #endif /* VIDIOC_S_TUNER */
00149 
00150 /* vim: set ts=8 sw=4 et : */