libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 2011, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 3 of the License, or (at 00008 * your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful,but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty 00012 * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/errno.h> 00020 #include <libexplain/ac/sys/param.h> 00021 #include <libexplain/ac/sys/timex.h> 00022 00023 #include <libexplain/buffer/efault.h> 00024 #include <libexplain/buffer/einval.h> 00025 #include <libexplain/buffer/enosys.h> 00026 #include <libexplain/buffer/eperm.h> 00027 #include <libexplain/buffer/errno/generic.h> 00028 #include <libexplain/buffer/errno/adjtimex.h> 00029 #include <libexplain/buffer/timex.h> 00030 #include <libexplain/explanation.h> 00031 #include <libexplain/is_efault.h> 00032 00033 00034 static void 00035 explain_buffer_errno_adjtimex_system_call(explain_string_buffer_t *sb, int 00036 errnum, struct timex *data) 00037 { 00038 (void)errnum; 00039 explain_string_buffer_puts(sb, "adjtimex(data = "); 00040 explain_buffer_timex(sb, data); 00041 explain_string_buffer_putc(sb, ')'); 00042 } 00043 00044 00045 static void 00046 explain_buffer_errno_adjtimex_explanation(explain_string_buffer_t *sb, int 00047 errnum, struct timex *data) 00048 { 00049 /* 00050 * http://www.opengroup.org/onlinepubs/009695399/functions/adjtimex.html 00051 */ 00052 switch (errnum) 00053 { 00054 case EFAULT: 00055 explain_buffer_efault(sb, "data"); 00056 break; 00057 00058 case EINVAL: 00059 #ifdef HAVE_SYS_TIMEX_H 00060 if (explain_is_efault_pointer(data, sizeof(*data))) 00061 { 00062 explain_buffer_einval_vague(sb, "data"); 00063 break; 00064 } 00065 #ifdef ADJ_OFFSET 00066 if (data->modes & ADJ_OFFSET) 00067 { 00068 long lo = -131071; 00069 long hi = 131071; 00070 if (data->offset < lo || data->offset > hi) 00071 { 00072 explain_buffer_einval_out_of_range(sb, "data->offset", lo, hi); 00073 break; 00074 } 00075 } 00076 #endif 00077 #ifdef ADJ_STATUS 00078 if (data->modes & ADJ_STATUS) 00079 { 00080 switch (data->status) 00081 { 00082 case TIME_OK: 00083 case TIME_INS: 00084 case TIME_DEL: 00085 case TIME_OOP: 00086 case TIME_WAIT: 00087 #ifdef TIME_BAD 00088 case TIME_BAD: 00089 #endif 00090 break; 00091 00092 default: 00093 explain_buffer_einval_vague(sb, "data->status"); 00094 return; 00095 } 00096 } 00097 #endif 00098 #ifdef ADJ_TICK 00099 if (data->modes & ADJ_TICK) 00100 { 00101 long lo = 900000/HZ; 00102 long hi = 1100000/HZ; 00103 if (data->tick < lo || data->tick > hi) 00104 { 00105 explain_buffer_einval_out_of_range(sb, "data->tick", lo, hi); 00106 break; 00107 } 00108 } 00109 #endif 00110 #endif 00111 explain_buffer_einval_vague(sb, "data"); 00112 break; 00113 00114 case ENOSYS: 00115 explain_buffer_enosys_vague(sb, "adjtimex"); 00116 break; 00117 00118 case EPERM: 00119 explain_buffer_eperm_sys_time(sb, "adjtimex"); 00120 break; 00121 00122 default: 00123 explain_buffer_errno_generic(sb, errnum, "adjtimex"); 00124 break; 00125 } 00126 } 00127 00128 00129 void 00130 explain_buffer_errno_adjtimex(explain_string_buffer_t *sb, int errnum, struct 00131 timex *data) 00132 { 00133 explain_explanation_t exp; 00134 00135 explain_explanation_init(&exp, errnum); 00136 explain_buffer_errno_adjtimex_system_call(&exp.system_call_sb, errnum, 00137 data); 00138 explain_buffer_errno_adjtimex_explanation(&exp.explanation_sb, errnum, 00139 data); 00140 explain_explanation_assemble(&exp, sb); 00141 } 00142 00143 00144 /* vim: set ts=8 sw=4 et : */