libexplain
1.4.D001
|
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/string.h> 00023 #include <libexplain/ac/sys/ioctl.h> 00024 00025 #include <libexplain/buffer/einval.h> 00026 #include <libexplain/buffer/is_the_null_pointer.h> 00027 #include <libexplain/buffer/long.h> 00028 #include <libexplain/buffer/pointer.h> 00029 #include <libexplain/buffer/video_tuner.h> 00030 #include <libexplain/iocontrol/generic.h> 00031 #include <libexplain/iocontrol/vidiocsfreq.h> 00032 #include <libexplain/is_efault.h> 00033 00034 #ifdef VIDIOCSFREQ 00035 00036 00037 static void 00038 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00039 int errnum, int fildes, int request, const void *data) 00040 { 00041 struct video_tuner qry; 00042 const unsigned long *arg; 00043 00044 (void)p; 00045 (void)errnum; 00046 (void)request; 00047 arg = data; 00048 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00049 { 00050 explain_buffer_pointer(sb, arg); 00051 } 00052 else 00053 { 00054 explain_buffer_ulong(sb, *arg); 00055 memset(&qry, 0, sizeof(qry)); 00056 qry.tuner = *arg; 00057 if (ioctl(fildes, VIDIOCGTUNER, &qry) >= 0 && qry.name[0]) 00058 { 00059 explain_string_buffer_putc(sb, ' '); 00060 explain_string_buffer_puts_quoted_n(sb, qry.name, sizeof(qry.name)); 00061 } 00062 } 00063 } 00064 00065 00066 static void 00067 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00068 int errnum, int fildes, int request, const void *data) 00069 { 00070 switch (errnum) 00071 { 00072 case EINVAL: 00073 if (!data) 00074 { 00075 explain_buffer_is_the_null_pointer(sb, "data"); 00076 return; 00077 } 00078 00079 { 00080 const unsigned long *arg; 00081 int ntuners; 00082 00083 arg = data; 00084 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00085 goto generic; 00086 00087 ntuners = explain_video_tuner_get_n(fildes); 00088 if (ntuners == 0) 00089 { 00090 errnum = ENOTTY; 00091 goto generic; 00092 } 00093 if (ntuners > 0 && *arg >= (unsigned)ntuners) 00094 { 00095 explain_buffer_einval_out_of_range 00096 ( 00097 sb, 00098 "data", 00099 0, 00100 ntuners - 1 00101 ); 00102 return; 00103 } 00104 } 00105 00106 explain_buffer_einval_vague(sb, "data"); 00107 break; 00108 00109 default: 00110 generic: 00111 explain_iocontrol_generic_print_explanation 00112 ( 00113 p, 00114 sb, 00115 errnum, 00116 fildes, 00117 request, 00118 data 00119 ); 00120 break; 00121 } 00122 } 00123 00124 00125 const explain_iocontrol_t explain_iocontrol_vidiocsfreq = 00126 { 00127 "VIDIOCSFREQ", /* name */ 00128 VIDIOCSFREQ, /* value */ 00129 0, /* disambiguate */ 00130 0, /* print_name */ 00131 print_data, 00132 print_explanation, 00133 0, /* print_data_returned */ 00134 sizeof(unsigned long), /* data_size */ 00135 "unsigned long *", /* data_type */ 00136 0, /* flags */ 00137 __FILE__, 00138 __LINE__, 00139 }; 00140 00141 #else /* ndef VIDIOCSFREQ */ 00142 00143 const explain_iocontrol_t explain_iocontrol_vidiocsfreq = 00144 { 00145 0, /* name */ 00146 0, /* value */ 00147 0, /* disambiguate */ 00148 0, /* print_name */ 00149 0, /* print_data */ 00150 0, /* print_explanation */ 00151 0, /* print_data_returned */ 00152 0, /* data_size */ 00153 0, /* data_type */ 00154 0, /* flags */ 00155 __FILE__, 00156 __LINE__, 00157 }; 00158 00159 #endif /* VIDIOCSFREQ */ 00160 00161 /* vim: set ts=8 sw=4 et : */