libexplain  1.4.D001
libexplain/buffer/errno/futimes.c
Go to the documentation of this file.
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/fcntl.h>
00021 
00022 #include <libexplain/buffer/does_not_have_inode_modify_permission.h>
00023 #include <libexplain/buffer/ebadf.h>
00024 #include <libexplain/buffer/efault.h>
00025 #include <libexplain/buffer/erofs.h>
00026 #include <libexplain/buffer/errno/futimes.h>
00027 #include <libexplain/buffer/errno/generic.h>
00028 #include <libexplain/buffer/fildes_not_open_for_writing.h>
00029 #include <libexplain/buffer/fildes.h>
00030 #include <libexplain/buffer/gettext.h>
00031 #include <libexplain/buffer/pointer.h>
00032 #include <libexplain/buffer/timeval.h>
00033 #include <libexplain/explanation.h>
00034 #include <libexplain/is_efault.h>
00035 
00036 
00037 static void
00038 explain_buffer_errno_futimes_system_call(explain_string_buffer_t *sb,
00039     int errnum, int fildes, const struct timeval *tv)
00040 {
00041     (void)errnum;
00042     explain_string_buffer_puts(sb, "futimes(fildes = ");
00043     explain_buffer_fildes(sb, fildes);
00044     explain_string_buffer_puts(sb, ", tv = ");
00045     if (explain_is_efault_pointer(tv, sizeof(*tv)))
00046     {
00047         explain_buffer_pointer(sb, tv);
00048     }
00049     else
00050     {
00051         explain_string_buffer_putc(sb, '{');
00052         explain_buffer_timeval(sb, &tv[0]);
00053         explain_string_buffer_puts(sb, ", ");
00054         explain_buffer_timeval(sb, &tv[1]);
00055         explain_string_buffer_putc(sb, '}');
00056     }
00057     explain_string_buffer_putc(sb, ')');
00058 }
00059 
00060 
00061 static void
00062 explain_buffer_errno_futimes_explanation(explain_string_buffer_t *sb,
00063     int errnum, int fildes, const struct timeval *tv)
00064 {
00065     (void)tv;
00066     switch (errnum)
00067     {
00068     case EBADF:
00069         if (explain_buffer_fildes_not_open_for_writing(sb, fildes, "fildes"))
00070             explain_buffer_ebadf(sb, fildes, "fildes");
00071         break;
00072 
00073     case EFAULT:
00074         explain_buffer_efault(sb, "tv");
00075         break;
00076 
00077     case EACCES:
00078     case EPERM:
00079         /*
00080          * If tv is not NULL, times are changed as given,
00081          * but you need inode modify permission
00082          */
00083         explain_buffer_does_not_have_inode_modify_permission_fd
00084         (
00085             sb,
00086             fildes,
00087             "fildes"
00088         );
00089         break;
00090 
00091     case EROFS:
00092         explain_buffer_erofs_fildes(sb, fildes, "fildes");
00093         break;
00094 
00095     default:
00096         explain_buffer_errno_generic(sb, errnum, "futimes");
00097         break;
00098     }
00099 }
00100 
00101 
00102 void
00103 explain_buffer_errno_futimes(explain_string_buffer_t *sb, int errnum,
00104     int fildes, const struct timeval *tv)
00105 {
00106     explain_explanation_t exp;
00107 
00108     explain_explanation_init(&exp, errnum);
00109     explain_buffer_errno_futimes_system_call
00110     (
00111         &exp.system_call_sb,
00112         errnum,
00113         fildes,
00114         tv
00115     );
00116     explain_buffer_errno_futimes_explanation
00117     (
00118         &exp.explanation_sb,
00119         errnum,
00120         fildes,
00121         tv
00122     );
00123     explain_explanation_assemble(&exp, sb);
00124 }
00125 
00126 /* vim: set ts=8 sw=4 et : */