libexplain  1.4.D001
libexplain/buffer/errno/adjtime.c
Go to the documentation of this file.
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/limits.h>
00021 
00022 #include <libexplain/buffer/efault.h>
00023 #include <libexplain/buffer/einval.h>
00024 #include <libexplain/buffer/eperm.h>
00025 #include <libexplain/buffer/errno/generic.h>
00026 #include <libexplain/buffer/errno/adjtime.h>
00027 #include <libexplain/buffer/pointer.h>
00028 #include <libexplain/buffer/timeval.h>
00029 #include <libexplain/explanation.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_adjtime_system_call(explain_string_buffer_t *sb, int
00035     errnum, const struct timeval *delta, struct timeval *olddelta)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "adjtime(delta = ");
00039     explain_buffer_timeval(sb, delta);
00040     explain_string_buffer_puts(sb, ", olddelta = ");
00041     explain_buffer_pointer(sb, olddelta);
00042     explain_string_buffer_putc(sb, ')');
00043 }
00044 
00045 
00046 static void
00047 explain_buffer_errno_adjtime_explanation(explain_string_buffer_t *sb, int
00048     errnum, const struct timeval *delta, struct timeval *olddelta)
00049 {
00050     /*
00051      * http://www.opengroup.org/onlinepubs/009695399/functions/adjtime.html
00052      */
00053     switch (errnum)
00054     {
00055     case EFAULT:
00056         if (explain_is_efault_pointer(delta, sizeof(*delta)))
00057             explain_buffer_efault(sb, "delta");
00058         if (olddelta && explain_is_efault_pointer(olddelta, sizeof(*olddelta)))
00059             explain_buffer_efault(sb, "olddelta");
00060         break;
00061 
00062     case EINVAL:
00063         if (!explain_is_efault_pointer(delta, sizeof(*delta)))
00064         {
00065             long lo = (INT_MIN / 1000000 + 2);
00066             long hi = (INT_MAX / 1000000 - 2);
00067             if (delta->tv_sec < lo || delta->tv_sec > hi)
00068             {
00069                 explain_buffer_einval_out_of_range(sb, "delta->tv_sec", lo, hi);
00070                 break;
00071             }
00072         }
00073         explain_buffer_einval_vague(sb, "delta");
00074         break;
00075 
00076     case EPERM:
00077         explain_buffer_eperm_sys_time(sb, "adjtime");
00078         break;
00079 
00080     default:
00081         explain_buffer_errno_generic(sb, errnum, "adjtime");
00082         break;
00083     }
00084 }
00085 
00086 
00087 void
00088 explain_buffer_errno_adjtime(explain_string_buffer_t *sb, int errnum, const
00089     struct timeval *delta, struct timeval *olddelta)
00090 {
00091     explain_explanation_t exp;
00092 
00093     explain_explanation_init(&exp, errnum);
00094     explain_buffer_errno_adjtime_system_call(&exp.system_call_sb, errnum, delta,
00095         olddelta);
00096     explain_buffer_errno_adjtime_explanation(&exp.explanation_sb, errnum, delta,
00097         olddelta);
00098     explain_explanation_assemble(&exp, sb);
00099 }
00100 
00101 
00102 /* vim: set ts=8 sw=4 et : */