libexplain  1.4.D001
libexplain/buffer/errno/futimens.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 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 of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
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/stat.h>
00021 
00022 #include <libexplain/buffer/eacces.h>
00023 #include <libexplain/buffer/ebadf.h>
00024 #include <libexplain/buffer/efault.h>
00025 #include <libexplain/buffer/einval.h>
00026 #include <libexplain/buffer/eperm.h>
00027 #include <libexplain/buffer/erofs.h>
00028 #include <libexplain/buffer/dac.h>
00029 #include <libexplain/buffer/errno/futimens.h>
00030 #include <libexplain/buffer/errno/generic.h>
00031 #include <libexplain/buffer/fildes.h>
00032 #include <libexplain/buffer/gettext.h>
00033 #include <libexplain/buffer/is_the_null_pointer.h>
00034 #include <libexplain/buffer/timespec.h>
00035 #include <libexplain/explanation.h>
00036 
00037 
00038 static void
00039 explain_buffer_errno_futimens_system_call(explain_string_buffer_t *sb, int
00040     errnum, int fildes, const struct timespec *data)
00041 {
00042     (void)errnum;
00043     explain_string_buffer_puts(sb, "futimens(fildes = ");
00044     explain_buffer_fildes(sb, fildes);
00045     explain_string_buffer_puts(sb, ", data = ");
00046     explain_buffer_timespec_array(sb, data, 2);
00047     explain_string_buffer_putc(sb, ')');
00048 }
00049 
00050 
00051 static int
00052 ok_tv_nsec(long x)
00053 {
00054     return ((x >= 0 && x < 100000000) || x == UTIME_NOW || x == UTIME_OMIT);
00055 }
00056 
00057 
00058 void
00059 explain_buffer_errno_futimens_explanation(explain_string_buffer_t *sb, int
00060     errnum, const char *syscall_name, int fildes, const struct timespec *data)
00061 {
00062     switch (errnum)
00063     {
00064     case EACCES:
00065         if (!data)
00066         {
00067              explain_buffer_is_the_null_pointer(sb, "data");
00068              break;
00069         }
00070         if (data[0].tv_nsec == UTIME_NOW)
00071         {
00072             explain_buffer_gettext
00073             (
00074                 sb,
00075                 /* FIXME: i18n */
00076                 "both tv_nsec values are UTIME_NOW"
00077             );
00078             break;
00079         }
00080         explain_buffer_eacces_syscall(sb, syscall_name);
00081         break;
00082 
00083     case EBADF:
00084         explain_buffer_ebadf(sb, fildes, "fildes");
00085         break;
00086 
00087     case EFAULT:
00088         explain_buffer_efault(sb, "data");
00089         break;
00090 
00091     case EINVAL:
00092         if (!data)
00093         {
00094              explain_buffer_is_the_null_pointer(sb, "data");
00095              break;
00096         }
00097         if (!ok_tv_nsec(data[0].tv_nsec))
00098         {
00099             explain_buffer_einval_out_of_range(sb, "data[0].tv_nsec",
00100                 0, 999999999);
00101             break;
00102         }
00103         if (!ok_tv_nsec(data[1].tv_nsec))
00104         {
00105             explain_buffer_einval_out_of_range(sb, "data[1].tv_nsec",
00106                 0, 999999999);
00107             break;
00108         }
00109         explain_buffer_einval_vague(sb, "data");
00110         break;
00111 
00112     case EPERM:
00113         explain_buffer_eperm_vague(sb, syscall_name);
00114         explain_buffer_dac_fowner(sb);
00115         break;
00116 
00117     case EROFS:
00118         explain_buffer_erofs_fildes(sb, fildes, "fildes");
00119         break;
00120 
00121     default:
00122         explain_buffer_errno_generic(sb, errnum, syscall_name);
00123         break;
00124     }
00125 }
00126 
00127 
00128 void
00129 explain_buffer_errno_futimens(explain_string_buffer_t *sb, int errnum, int
00130     fildes, const struct timespec *data)
00131 {
00132     explain_explanation_t exp;
00133 
00134     explain_explanation_init(&exp, errnum);
00135     explain_buffer_errno_futimens_system_call(&exp.system_call_sb, errnum,
00136         fildes, data);
00137     explain_buffer_errno_futimens_explanation(&exp.explanation_sb, errnum,
00138         "futimens", fildes, data);
00139     explain_explanation_assemble(&exp, sb);
00140 }
00141 
00142 
00143 /* vim: set ts=8 sw=4 et : */