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/fcntl.h> 00021 00022 #include <libexplain/buffer/ebadf.h> 00023 #include <libexplain/buffer/enotdir.h> 00024 #include <libexplain/buffer/fildes.h> 00025 #include <libexplain/buffer/errno/futimesat.h> 00026 #include <libexplain/buffer/errno/utimes.h> 00027 #include <libexplain/buffer/errno/generic.h> 00028 #include <libexplain/buffer/pathname.h> 00029 #include <libexplain/buffer/timeval.h> 00030 #include <libexplain/explanation.h> 00031 #include <libexplain/fileinfo.h> 00032 00033 00034 static void 00035 explain_buffer_errno_futimesat_system_call(explain_string_buffer_t *sb, int 00036 errnum, int fildes, const char *pathname, const struct timeval *data) 00037 { 00038 (void)errnum; 00039 explain_string_buffer_puts(sb, "futimesat(fildes = "); 00040 explain_buffer_fildes(sb, fildes); 00041 explain_string_buffer_puts(sb, ", pathname = "); 00042 explain_buffer_pathname(sb, pathname); 00043 explain_string_buffer_puts(sb, ", data = "); 00044 explain_buffer_timeval_array(sb, data, 2); 00045 explain_string_buffer_putc(sb, ')'); 00046 } 00047 00048 00049 void 00050 explain_buffer_errno_futimesat_explanation(explain_string_buffer_t *sb, int 00051 errnum, const char *syscall_name, int fildes, const char *pathname, const 00052 struct timeval *data) 00053 { 00054 switch (errnum) 00055 { 00056 case EBADF: 00057 explain_buffer_ebadf(sb, fildes, "fildes"); 00058 break; 00059 00060 case ENOTDIR: 00061 if (pathname[0] == '/') 00062 { 00063 explain_buffer_errno_utimes_explanation(sb, errnum, syscall_name, 00064 pathname, data); 00065 break; 00066 } 00067 if (fildes == AT_FDCWD) 00068 { 00069 explain_buffer_errno_utimes_explanation(sb, errnum, syscall_name, 00070 pathname, data); 00071 break; 00072 } 00073 if (!explain_fildes_is_a_directory(fildes)) 00074 { 00075 explain_buffer_enotdir_fd(sb, fildes, "fildes"); 00076 break; 00077 } 00078 00079 /* 00080 * form an absolute path by ombining the fd's dir with the pathname 00081 */ 00082 { 00083 char dir2[PATH_MAX + 1]; 00084 char pathname2[PATH_MAX + 1]; 00085 explain_string_buffer_t sb2; 00086 explain_string_buffer_init(&sb2, pathname2, sizeof(pathname2)); 00087 explain_fileinfo_self_fd_n(fildes, dir2, sizeof(dir2)); 00088 explain_string_buffer_puts(&sb2, dir2); 00089 explain_string_buffer_path_join(&sb2, pathname); 00090 00091 explain_buffer_errno_utimes_explanation(sb, errnum, syscall_name, 00092 pathname2, data); 00093 } 00094 break; 00095 00096 default: 00097 explain_buffer_errno_generic(sb, errnum, syscall_name); 00098 break; 00099 } 00100 } 00101 00102 00103 void 00104 explain_buffer_errno_futimesat(explain_string_buffer_t *sb, int errnum, int 00105 fildes, const char *pathname, const struct timeval *data) 00106 { 00107 explain_explanation_t exp; 00108 00109 explain_explanation_init(&exp, errnum); 00110 explain_buffer_errno_futimesat_system_call(&exp.system_call_sb, errnum, 00111 fildes, pathname, data); 00112 explain_buffer_errno_futimesat_explanation(&exp.explanation_sb, errnum, 00113 "futimesat", fildes, pathname, data); 00114 explain_explanation_assemble(&exp, sb); 00115 } 00116 00117 00118 /* vim: set ts=8 sw=4 et : */