libexplain  1.4.D001
libexplain/buffer/errno/lchown.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008-2010, 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 
00021 #include <libexplain/buffer/errno/chown.h>
00022 #include <libexplain/buffer/errno/generic.h>
00023 #include <libexplain/buffer/errno/lchown.h>
00024 #include <libexplain/buffer/errno/path_resolution.h>
00025 #include <libexplain/buffer/gid.h>
00026 #include <libexplain/buffer/pointer.h>
00027 #include <libexplain/buffer/uid.h>
00028 #include <libexplain/explanation.h>
00029 
00030 
00031 static void
00032 explain_buffer_errno_lchown_system_call(explain_string_buffer_t *sb,
00033     int errnum, const char *pathname, int owner, int group)
00034 {
00035     explain_string_buffer_puts(sb, "lchown(pathname = ");
00036     if (errnum == EFAULT)
00037         explain_buffer_pointer(sb, pathname);
00038     else
00039         explain_string_buffer_puts_quoted(sb, pathname);
00040     explain_string_buffer_puts(sb, ", owner = ");
00041     explain_buffer_uid(sb, owner);
00042     explain_string_buffer_puts(sb, ", group = ");
00043     explain_buffer_gid(sb, group);
00044     explain_string_buffer_putc(sb, ')');
00045 }
00046 
00047 
00048 void
00049 explain_buffer_errno_lchown_explanation(explain_string_buffer_t *sb,
00050     int errnum, const char *syscall_name, const char *pathname, int owner,
00051     int group)
00052 {
00053     explain_final_t final_component;
00054 
00055     explain_final_init(&final_component);
00056     final_component.want_to_modify_inode = 1;
00057     final_component.follow_symlink = 0;
00058 
00059     explain_buffer_errno_chown_explanation_fc
00060     (
00061         sb,
00062         errnum,
00063         syscall_name,
00064         pathname,
00065         owner,
00066         group,
00067         "pathname",
00068         &final_component
00069     );
00070 }
00071 
00072 
00073 void
00074 explain_buffer_errno_lchown(explain_string_buffer_t *sb, int errnum,
00075     const char *pathname, int owner, int group)
00076 {
00077     explain_explanation_t exp;
00078 
00079     explain_explanation_init(&exp, errnum);
00080     explain_buffer_errno_lchown_system_call
00081     (
00082         &exp.system_call_sb,
00083         errnum,
00084         pathname,
00085         owner,
00086         group
00087     );
00088     explain_buffer_errno_lchown_explanation
00089     (
00090         &exp.explanation_sb,
00091         errnum,
00092         "lchown",
00093         pathname,
00094         owner,
00095         group
00096     );
00097     explain_explanation_assemble(&exp, sb);
00098 }
00099 
00100 
00101 /* vim: set ts=8 sw=4 et : */