libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 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 #include <libexplain/ac/sys/time.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/enosys.h> 00029 #include <libexplain/buffer/enotdir.h> 00030 #include <libexplain/buffer/erofs.h> 00031 #include <libexplain/buffer/errno/generic.h> 00032 #include <libexplain/buffer/errno/lutimes.h> 00033 #include <libexplain/buffer/errno/path_resolution.h> 00034 #include <libexplain/buffer/gettext.h> 00035 #include <libexplain/buffer/is_the_null_pointer.h> 00036 #include <libexplain/buffer/pathname.h> 00037 #include <libexplain/buffer/timeval.h> 00038 #include <libexplain/explanation.h> 00039 #include <libexplain/is_efault.h> 00040 00041 00042 static void 00043 explain_buffer_errno_lutimes_system_call(explain_string_buffer_t *sb, int 00044 errnum, const char *pathname, const struct timeval *data) 00045 { 00046 (void)errnum; 00047 explain_string_buffer_puts(sb, "lutimes(pathname = "); 00048 explain_buffer_pathname(sb, pathname); 00049 explain_string_buffer_puts(sb, ", data = "); 00050 explain_buffer_timeval_array(sb, data, 2); 00051 explain_string_buffer_putc(sb, ')'); 00052 } 00053 00054 00055 void 00056 explain_buffer_errno_lutimes_explanation(explain_string_buffer_t *sb, 00057 int errnum, const char *syscall_name, const char *pathname, 00058 const struct timeval *data) 00059 { 00060 explain_final_t final_component; 00061 00062 explain_final_init(&final_component); 00063 if (data) 00064 final_component.want_to_modify_inode = 1; 00065 else 00066 final_component.want_to_write = 1; 00067 00068 switch (errnum) 00069 { 00070 case EACCES: 00071 /* 00072 * if time is NULL, change to "now", 00073 * but need write permission 00074 */ 00075 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00076 break; 00077 00078 case EFAULT: 00079 if (!pathname) 00080 { 00081 explain_buffer_is_the_null_pointer(sb, "pathname"); 00082 break; 00083 } 00084 if (explain_is_efault_path(pathname)) 00085 { 00086 explain_buffer_efault(sb, "pathname"); 00087 break; 00088 } 00089 if (!data) 00090 { 00091 explain_buffer_is_the_null_pointer(sb, "data"); 00092 break; 00093 } 00094 if (explain_is_efault_pointer(data, sizeof(*data) * 2)) 00095 { 00096 explain_buffer_efault(sb, "data"); 00097 break; 00098 } 00099 goto generic; 00100 00101 case ELOOP: 00102 case EMLINK: 00103 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00104 break; 00105 00106 case ENAMETOOLONG: 00107 explain_buffer_enametoolong(sb, pathname, "pathname", &final_component); 00108 break; 00109 00110 case ENOENT: 00111 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00112 break; 00113 00114 case ENOTDIR: 00115 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00116 break; 00117 00118 case EPERM: 00119 /* 00120 * If times is not NULL, change as given, 00121 * but need inode modify permission 00122 */ 00123 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00124 break; 00125 00126 case EROFS: 00127 explain_buffer_erofs(sb, pathname, "pathname"); 00128 break; 00129 00130 case EINVAL: 00131 if (!pathname) 00132 { 00133 explain_buffer_is_the_null_pointer(sb, "pathname"); 00134 break; 00135 } 00136 if (!data) 00137 { 00138 explain_buffer_is_the_null_pointer(sb, "data"); 00139 break; 00140 } 00141 if (data[0].tv_usec == UTIME_OMIT && data[1].tv_usec == UTIME_OMIT) 00142 { 00143 explain_buffer_gettext 00144 ( 00145 sb, 00146 /* FIXME: i18n */ 00147 "both tv_usec vlues are UTIME_OMIT" 00148 ); 00149 } 00150 goto generic; 00151 00152 case ENOSYS: 00153 #if defined(EOPNOTSUPP) && ENOSYS != EOPNOTSUPP 00154 case EOPNOTSUPP: 00155 #endif 00156 #if defined(ENOTSUP) && (ENOTSUP != EOPNOTSUPP) 00157 case ENOTSUP: 00158 #endif 00159 explain_buffer_enosys_pathname(sb, pathname, "pathname", syscall_name); 00160 break; 00161 00162 default: 00163 generic: 00164 explain_buffer_errno_generic(sb, errnum, syscall_name); 00165 break; 00166 } 00167 } 00168 00169 00170 void 00171 explain_buffer_errno_lutimes(explain_string_buffer_t *sb, int errnum, 00172 const char *pathname, const struct timeval *data) 00173 { 00174 explain_explanation_t exp; 00175 00176 explain_explanation_init(&exp, errnum); 00177 explain_buffer_errno_lutimes_system_call(&exp.system_call_sb, errnum, 00178 pathname, data); 00179 explain_buffer_errno_lutimes_explanation(&exp.explanation_sb, errnum, 00180 "lutimes", pathname, data); 00181 explain_explanation_assemble(&exp, sb); 00182 } 00183 00184 00185 /* vim: set ts=8 sw=4 et : */