libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 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, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser 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/time.h> 00021 00022 #include <libexplain/buffer/efault.h> 00023 #include <libexplain/buffer/errno/generic.h> 00024 #include <libexplain/buffer/errno/gettimeofday.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/explanation.h> 00027 #include <libexplain/is_efault.h> 00028 00029 00030 static void 00031 explain_buffer_errno_gettimeofday_system_call( 00032 explain_string_buffer_t *sb, int errnum, struct timeval *tv, 00033 struct timezone *tz) 00034 { 00035 (void)errnum; 00036 explain_string_buffer_puts(sb, "gettimeofday(tv = "); 00037 explain_buffer_pointer(sb, tv); 00038 explain_string_buffer_puts(sb, ", tz = "); 00039 explain_buffer_pointer(sb, tz); 00040 explain_string_buffer_putc(sb, ')'); 00041 } 00042 00043 00044 /* 00045 * http://www.opengroup.org/onlinepubs/009695399/functions/gettimeofday.html 00046 */ 00047 00048 static void 00049 explain_buffer_errno_gettimeofday_explanation( 00050 explain_string_buffer_t *sb, int errnum, struct timeval *tv, 00051 struct timezone *tz) 00052 { 00053 switch (errnum) 00054 { 00055 case EFAULT: 00056 if (tv && explain_is_efault_pointer(tv, sizeof(*tv))) 00057 { 00058 explain_buffer_efault(sb, "tv"); 00059 break; 00060 } 00061 if (tz && explain_is_efault_pointer(tz, sizeof(*tz))) 00062 { 00063 explain_buffer_efault(sb, "tz"); 00064 break; 00065 } 00066 break; 00067 00068 default: 00069 explain_buffer_errno_generic(sb, errnum, "gettimeofday"); 00070 break; 00071 } 00072 } 00073 00074 00075 void 00076 explain_buffer_errno_gettimeofday(explain_string_buffer_t *sb, 00077 int errnum, struct timeval *tv, struct timezone *tz) 00078 { 00079 explain_explanation_t exp; 00080 00081 explain_explanation_init(&exp, errnum); 00082 explain_buffer_errno_gettimeofday_system_call 00083 ( 00084 &exp.system_call_sb, 00085 errnum, 00086 tv, 00087 tz 00088 ); 00089 explain_buffer_errno_gettimeofday_explanation 00090 ( 00091 &exp.explanation_sb, 00092 errnum, 00093 tv, 00094 tz 00095 ); 00096 explain_explanation_assemble(&exp, sb); 00097 } 00098 00099 00100 /* vim: set ts=8 sw=4 et : */