libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009-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/time.h> 00021 #include <libexplain/ac/sys/timeb.h> 00022 00023 #include <libexplain/ftime.h> 00024 #include <libexplain/output.h> 00025 #include <libexplain/is_efault.h> 00026 00027 00028 void 00029 explain_ftime_or_die(struct timeb *tp) 00030 { 00031 if (explain_ftime_on_error(tp) < 0) 00032 { 00033 explain_output_exit_failure(); 00034 } 00035 } 00036 00037 00038 #ifndef HAVE_FTIME 00039 00040 int 00041 ftime(timebuf) 00042 struct timeb *timebuf; 00043 { 00044 struct timeval tv; 00045 struct timezone tz; 00046 00047 if (explain_is_efault_pointer(timebuf, sizeof(*timebuf))) 00048 { 00049 errno = EFAULT; 00050 return -1; 00051 } 00052 if (gettimeofday(&tv, &tz) < 0) 00053 return -1; 00054 timebuf->time = tv.tv_sec; 00055 timebuf->millitm = tv.tv_usec / 1000; 00056 timebuf->timezone = tz.tz_minuteswest; 00057 timebuf->dstflag = tz.tz_dsttime; 00058 return 0; 00059 } 00060 00061 #endif 00062 00063 00064 int 00065 explain_ftime_on_error(struct timeb *tp) 00066 { 00067 int result; 00068 00069 result = ftime(tp); 00070 if (result < 0) 00071 { 00072 int hold_errno; 00073 00074 hold_errno = errno; 00075 explain_output_error("%s", explain_errno_ftime(hold_errno, tp)); 00076 errno = hold_errno; 00077 } 00078 return result; 00079 } 00080 00081 00082 /* vim: set ts=8 sw=4 et : */