libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008-2011, 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/eloop.h> 00026 #include <libexplain/buffer/enametoolong.h> 00027 #include <libexplain/buffer/enoent.h> 00028 #include <libexplain/buffer/enomem.h> 00029 #include <libexplain/buffer/enotdir.h> 00030 #include <libexplain/buffer/errno/generic.h> 00031 #include <libexplain/buffer/errno/path_resolution.h> 00032 #include <libexplain/buffer/errno/stat.h> 00033 #include <libexplain/buffer/pathname.h> 00034 #include <libexplain/buffer/pointer.h> 00035 #include <libexplain/explanation.h> 00036 #include <libexplain/is_efault.h> 00037 #include <libexplain/string_buffer.h> 00038 00039 00040 static void 00041 explain_buffer_errno_stat_system_call(explain_string_buffer_t *sb, 00042 int errnum, const char *pathname, const struct stat *data) 00043 { 00044 (void)errnum; 00045 explain_string_buffer_printf(sb, "stat(pathname = "); 00046 explain_buffer_pathname(sb, pathname); 00047 explain_string_buffer_puts(sb, ", data = "); 00048 explain_buffer_pointer(sb, data); 00049 explain_string_buffer_putc(sb, ')'); 00050 } 00051 00052 00053 void 00054 explain_buffer_errno_stat_explanation(explain_string_buffer_t *sb, 00055 int errnum, const char *syscall_name, const char *pathname, 00056 const struct stat *data) 00057 { 00058 explain_final_t final_component; 00059 00060 (void)data; 00061 explain_final_init(&final_component); 00062 00063 switch (errnum) 00064 { 00065 case EACCES: 00066 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00067 break; 00068 00069 case EFAULT: 00070 if (explain_is_efault_path(pathname)) 00071 { 00072 explain_buffer_efault(sb, "pathname"); 00073 break; 00074 } 00075 if (explain_is_efault_pointer(data, sizeof(*data))) 00076 { 00077 explain_buffer_efault(sb, "data"); 00078 break; 00079 } 00080 break; 00081 00082 case ELOOP: 00083 case EMLINK: /* BSD */ 00084 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00085 break; 00086 00087 case ENAMETOOLONG: 00088 explain_buffer_enametoolong 00089 ( 00090 sb, 00091 pathname, 00092 "pathname", 00093 &final_component 00094 ); 00095 break; 00096 00097 case ENOENT: 00098 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00099 break; 00100 00101 case ENOMEM: 00102 explain_buffer_enomem_kernel(sb); 00103 break; 00104 00105 case ENOTDIR: 00106 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00107 break; 00108 00109 default: 00110 explain_buffer_errno_generic(sb, errnum, syscall_name); 00111 break; 00112 } 00113 } 00114 00115 00116 void 00117 explain_buffer_errno_stat(explain_string_buffer_t *sb, int errnum, 00118 const char *pathname, const struct stat *data) 00119 { 00120 explain_explanation_t exp; 00121 00122 explain_explanation_init(&exp, errnum); 00123 explain_buffer_errno_stat_system_call 00124 ( 00125 &exp.system_call_sb, 00126 errnum, 00127 pathname, 00128 data 00129 ); 00130 explain_buffer_errno_stat_explanation 00131 ( 00132 &exp.explanation_sb, 00133 errnum, 00134 "stat", 00135 pathname, 00136 data 00137 ); 00138 explain_explanation_assemble(&exp, sb); 00139 } 00140 00141 00142 /* vim: set ts=8 sw=4 et : */