libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 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, 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/eacces.h> 00022 #include <libexplain/buffer/einval.h> 00023 #include <libexplain/buffer/eio.h> 00024 #include <libexplain/buffer/eloop.h> 00025 #include <libexplain/buffer/enametoolong.h> 00026 #include <libexplain/buffer/enoent.h> 00027 #include <libexplain/buffer/enotdir.h> 00028 #include <libexplain/buffer/errno/generic.h> 00029 #include <libexplain/buffer/errno/path_resolution.h> 00030 #include <libexplain/buffer/errno/realpath.h> 00031 #include <libexplain/buffer/is_the_null_pointer.h> 00032 #include <libexplain/buffer/pathname.h> 00033 #include <libexplain/buffer/pointer.h> 00034 #include <libexplain/explanation.h> 00035 00036 00037 static void 00038 explain_buffer_errno_realpath_system_call(explain_string_buffer_t *sb, 00039 int errnum, const char *pathname, char *resolved_pathname) 00040 { 00041 (void)errnum; 00042 explain_string_buffer_puts(sb, "realpath(pathname = "); 00043 explain_buffer_pathname(sb, pathname); 00044 explain_string_buffer_puts(sb, ", resolved_pathname = "); 00045 explain_buffer_pointer(sb, resolved_pathname); 00046 explain_string_buffer_putc(sb, ')'); 00047 } 00048 00049 00050 void 00051 explain_buffer_errno_realpath_explanation(explain_string_buffer_t *sb, 00052 int errnum, const char *syscall_name, const char *pathname, 00053 char *resolved_pathname) 00054 { 00055 explain_final_t final_component; 00056 00057 explain_final_init(&final_component); 00058 final_component.follow_symlink = 1; 00059 final_component.must_exist = 1; 00060 00061 /* 00062 * http://www.opengroup.org/onlinepubs/009695399/functions/realpath.html 00063 */ 00064 switch (errnum) 00065 { 00066 case EACCES: 00067 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00068 break; 00069 00070 case EINVAL: 00071 if (!pathname) 00072 { 00073 explain_buffer_is_the_null_pointer(sb, "pathname"); 00074 return; 00075 } 00076 if (!resolved_pathname) 00077 { 00078 explain_buffer_is_the_null_pointer(sb, "resolved_pathname"); 00079 return; 00080 } 00081 explain_buffer_einval_vague(sb, "pathname"); 00082 break; 00083 00084 case EIO: 00085 explain_buffer_eio(sb); 00086 break; 00087 00088 case ELOOP: 00089 case EMLINK: /* BSD */ 00090 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00091 break; 00092 00093 case ENAMETOOLONG: 00094 explain_buffer_enametoolong 00095 ( 00096 sb, 00097 pathname, 00098 "pathname", 00099 &final_component 00100 ); 00101 break; 00102 00103 case ENOENT: 00104 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00105 break; 00106 00107 case ENOTDIR: 00108 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00109 break; 00110 00111 default: 00112 explain_buffer_errno_generic(sb, errnum, syscall_name); 00113 break; 00114 } 00115 } 00116 00117 00118 void 00119 explain_buffer_errno_realpath(explain_string_buffer_t *sb, int errnum, 00120 const char *pathname, char *resolved_pathname) 00121 { 00122 explain_explanation_t exp; 00123 00124 explain_explanation_init(&exp, errnum); 00125 explain_buffer_errno_realpath_system_call(&exp.system_call_sb, errnum, 00126 pathname, resolved_pathname); 00127 explain_buffer_errno_realpath_explanation(&exp.explanation_sb, errnum, 00128 "realpath", pathname, resolved_pathname); 00129 explain_explanation_assemble(&exp, sb); 00130 } 00131 00132 00133 /* vim: set ts=8 sw=4 et : */