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