libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or (at 00009 * your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/sys/stat.h> 00022 00023 #include <libexplain/buffer/eacces.h> 00024 #include <libexplain/buffer/efault.h> 00025 #include <libexplain/buffer/eio.h> 00026 #include <libexplain/buffer/eloop.h> 00027 #include <libexplain/buffer/enametoolong.h> 00028 #include <libexplain/buffer/enoent.h> 00029 #include <libexplain/buffer/enomem.h> 00030 #include <libexplain/buffer/enotdir.h> 00031 #include <libexplain/buffer/errno/chdir.h> 00032 #include <libexplain/buffer/errno/generic.h> 00033 #include <libexplain/buffer/errno/path_resolution.h> 00034 #include <libexplain/buffer/pointer.h> 00035 #include <libexplain/explanation.h> 00036 #include <libexplain/string_buffer.h> 00037 00038 00039 static void 00040 explain_buffer_errno_chdir_system_call(explain_string_buffer_t *sb, 00041 int errnum, const char *pathname) 00042 { 00043 explain_string_buffer_printf(sb, "chdir(pathname = "); 00044 if (errnum == EFAULT) 00045 explain_buffer_pointer(sb, pathname); 00046 else 00047 explain_string_buffer_puts_quoted(sb, pathname); 00048 explain_string_buffer_putc(sb, ')'); 00049 } 00050 00051 00052 static void 00053 explain_buffer_errno_chdir_explanation(explain_string_buffer_t *sb, 00054 int errnum, const char *pathname) 00055 { 00056 explain_final_t final_component; 00057 00058 explain_final_init(&final_component); 00059 final_component.want_to_search = 1; 00060 final_component.must_be_a_st_mode = 1; 00061 final_component.st_mode = S_IFDIR; 00062 00063 switch (errnum) 00064 { 00065 case EACCES: 00066 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00067 break; 00068 00069 case EFAULT: 00070 explain_buffer_efault(sb, "pathname"); 00071 break; 00072 00073 case EIO: 00074 explain_buffer_eio_path(sb, pathname); 00075 break; 00076 00077 case ELOOP: 00078 case EMLINK: /* BSD */ 00079 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00080 break; 00081 00082 case ENAMETOOLONG: 00083 explain_buffer_enametoolong 00084 ( 00085 sb, 00086 pathname, 00087 "pathname", 00088 &final_component 00089 ); 00090 break; 00091 00092 case ENOENT: 00093 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00094 break; 00095 00096 case ENOMEM: 00097 explain_buffer_enomem_kernel(sb); 00098 break; 00099 00100 case ENOTDIR: 00101 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00102 break; 00103 00104 default: 00105 explain_buffer_errno_generic(sb, errnum, "chdir"); 00106 break; 00107 } 00108 } 00109 00110 00111 void 00112 explain_buffer_errno_chdir(explain_string_buffer_t *sb, int errnum, 00113 const char *pathname) 00114 { 00115 explain_explanation_t exp; 00116 00117 explain_explanation_init(&exp, errnum); 00118 explain_buffer_errno_chdir_system_call 00119 ( 00120 &exp.system_call_sb, 00121 errnum, 00122 pathname 00123 ); 00124 explain_buffer_errno_chdir_explanation 00125 ( 00126 &exp.explanation_sb, 00127 errnum, 00128 pathname 00129 ); 00130 explain_explanation_assemble(&exp, sb); 00131 } 00132 00133 00134 /* vim: set ts=8 sw=4 et : */