libexplain  1.4.D001
libexplain/buffer/errno/fchmod.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 
00021 #include <libexplain/buffer/does_not_have_inode_modify_permission.h>
00022 #include <libexplain/buffer/eacces.h>
00023 #include <libexplain/buffer/ebadf.h>
00024 #include <libexplain/buffer/eio.h>
00025 #include <libexplain/buffer/enomem.h>
00026 #include <libexplain/buffer/eperm.h>
00027 #include <libexplain/buffer/erofs.h>
00028 #include <libexplain/buffer/errno/fchmod.h>
00029 #include <libexplain/buffer/errno/generic.h>
00030 #include <libexplain/buffer/fildes.h>
00031 #include <libexplain/buffer/permission_mode.h>
00032 #include <libexplain/explanation.h>
00033 
00034 
00035 static void
00036 explain_buffer_errno_fchmod_system_call(explain_string_buffer_t *sb, int errnum,
00037     int fildes, mode_t mode)
00038 {
00039     (void)errnum;
00040     explain_string_buffer_puts(sb, "fchmod(fildes = ");
00041     explain_buffer_fildes(sb, fildes);
00042     explain_string_buffer_puts(sb, ", mode = ");
00043     explain_buffer_permission_mode(sb, mode);
00044     explain_string_buffer_putc(sb, ')');
00045 }
00046 
00047 
00048 void
00049 explain_buffer_errno_fchmod_explanation(explain_string_buffer_t *sb, int errnum,
00050     const char *syscall_name, int fildes, mode_t mode)
00051 {
00052     (void)mode;
00053     switch (errnum)
00054     {
00055     case EIO:
00056         explain_buffer_eio(sb);
00057         break;
00058 
00059     case ENOMEM:
00060         explain_buffer_enomem_kernel(sb);
00061         break;
00062 
00063     case EPERM:
00064         /*
00065          * The effective UID does not match the owner of the file, and
00066          * the process is not privileged (Linux: it does not have the
00067          * CAP_FOWNER capability).
00068          */
00069         explain_buffer_does_not_have_inode_modify_permission_fd
00070         (
00071             sb,
00072             fildes,
00073             "fildes"
00074         );
00075         break;
00076 
00077     case EROFS:
00078         explain_buffer_erofs_fildes(sb, fildes, "fildes");
00079         break;
00080 
00081     case EBADF:
00082         explain_buffer_ebadf(sb, fildes, "fildes");
00083         break;
00084 
00085     default:
00086         explain_buffer_errno_generic(sb, errnum, syscall_name);
00087         break;
00088     }
00089 }
00090 
00091 
00092 void
00093 explain_buffer_errno_fchmod(explain_string_buffer_t *sb, int errnum, int fildes,
00094     mode_t mode)
00095 {
00096     explain_explanation_t exp;
00097 
00098     explain_explanation_init(&exp, errnum);
00099     explain_buffer_errno_fchmod_system_call(&exp.system_call_sb, errnum, fildes,
00100         mode);
00101     explain_buffer_errno_fchmod_explanation(&exp.explanation_sb, errnum,
00102         "fchmod", fildes, mode);
00103     explain_explanation_assemble(&exp, sb);
00104 }
00105 
00106 
00107 /* vim: set ts=8 sw=4 et : */