libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 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/sys/stat.h> 00021 00022 #include <libexplain/buffer/errno/remove.h> 00023 #include <libexplain/buffer/errno/rmdir.h> 00024 #include <libexplain/buffer/errno/unlink.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/explanation.h> 00027 #include <libexplain/pathname_is_a_directory.h> 00028 00029 00030 static void 00031 explain_buffer_errno_remove_system_call(explain_string_buffer_t *sb, 00032 int errnum, const char *pathname) 00033 { 00034 explain_string_buffer_puts(sb, "remove(pathname = "); 00035 if (errnum == EFAULT) 00036 explain_buffer_pointer(sb, pathname); 00037 else 00038 explain_string_buffer_puts_quoted(sb, pathname); 00039 explain_string_buffer_putc(sb, ')'); 00040 } 00041 00042 00043 static void 00044 explain_buffer_errno_remove_explanation(explain_string_buffer_t *sb, 00045 int errnum, const char *syscall_name, const char *pathname) 00046 { 00047 if (explain_pathname_is_a_directory(pathname)) 00048 { 00049 explain_buffer_errno_rmdir_explanation 00050 ( 00051 sb, 00052 errnum, 00053 syscall_name, 00054 pathname 00055 ); 00056 } 00057 else 00058 { 00059 explain_buffer_errno_unlink_explanation 00060 ( 00061 sb, 00062 errnum, 00063 syscall_name, 00064 pathname 00065 ); 00066 } 00067 } 00068 00069 00070 void 00071 explain_buffer_errno_remove(explain_string_buffer_t *sb, int errnum, 00072 const char *pathname) 00073 { 00074 explain_explanation_t exp; 00075 00076 explain_explanation_init(&exp, errnum); 00077 explain_buffer_errno_remove_system_call 00078 ( 00079 &exp.system_call_sb, 00080 errnum, 00081 pathname 00082 ); 00083 explain_buffer_errno_remove_explanation 00084 ( 00085 &exp.explanation_sb, 00086 errnum, 00087 "remove", 00088 pathname 00089 ); 00090 explain_explanation_assemble(&exp, sb); 00091 } 00092 00093 00094 /* vim: set ts=8 sw=4 et : */