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/is_the_null_pointer.h> 00026 #include <libexplain/buffer/long.h> 00027 #include <libexplain/buffer/pointer.h> 00028 #include <libexplain/iocontrol/generic.h> 00029 #include <libexplain/iocontrol/vidiocgfreq.h> 00030 #include <libexplain/is_efault.h> 00031 00032 #ifdef VIDIOCGFREQ 00033 00034 00035 static void 00036 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00037 int errnum, int fildes, int request, const void *data) 00038 { 00039 switch (errnum) 00040 { 00041 case EINVAL: 00042 if (!data) 00043 { 00044 explain_buffer_is_the_null_pointer(sb, "data"); 00045 return; 00046 } 00047 00048 errnum = ENOTTY; 00049 /* Fall through... */ 00050 00051 default: 00052 explain_iocontrol_generic_print_explanation 00053 ( 00054 p, 00055 sb, 00056 errnum, 00057 fildes, 00058 request, 00059 data 00060 ); 00061 break; 00062 } 00063 } 00064 00065 00066 static void 00067 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00068 int errnum, int fildes, int request, const void *data) 00069 { 00070 struct video_tuner qry; 00071 const unsigned long *arg; 00072 00073 (void)p; 00074 (void)errnum; 00075 (void)request; 00076 arg = data; 00077 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00078 { 00079 explain_buffer_pointer(sb, arg); 00080 } 00081 else 00082 { 00083 explain_buffer_ulong(sb, *arg); 00084 memset(&qry, 0, sizeof(qry)); 00085 qry.tuner = *arg; 00086 if (ioctl(fildes, VIDIOCGTUNER, &qry) >= 0 && qry.name[0]) 00087 { 00088 explain_string_buffer_putc(sb, ' '); 00089 explain_string_buffer_puts_quoted_n(sb, qry.name, sizeof(qry.name)); 00090 } 00091 } 00092 } 00093 00094 00095 const explain_iocontrol_t explain_iocontrol_vidiocgfreq = 00096 { 00097 "VIDIOCGFREQ", /* name */ 00098 VIDIOCGFREQ, /* value */ 00099 0, /* disambiguate */ 00100 0, /* print_name */ 00101 explain_iocontrol_generic_print_data_pointer, /* print_data */ 00102 print_explanation, 00103 print_data_returned, 00104 sizeof(unsigned long), /* data_size */ 00105 "unsigned long *", /* data_type */ 00106 0, /* flags */ 00107 __FILE__, 00108 __LINE__, 00109 }; 00110 00111 #else /* ndef VIDIOCGFREQ */ 00112 00113 const explain_iocontrol_t explain_iocontrol_vidiocgfreq = 00114 { 00115 0, /* name */ 00116 0, /* value */ 00117 0, /* disambiguate */ 00118 0, /* print_name */ 00119 0, /* print_data */ 00120 0, /* print_explanation */ 00121 0, /* print_data_returned */ 00122 0, /* data_size */ 00123 0, /* data_type */ 00124 0, /* flags */ 00125 __FILE__, 00126 __LINE__, 00127 }; 00128 00129 #endif /* VIDIOCGFREQ */ 00130 00131 /* vim: set ts=8 sw=4 et : */