libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 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 00012 * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser 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/enomem.h> 00024 #include <libexplain/buffer/enotdir.h> 00025 #include <libexplain/buffer/errno/generic.h> 00026 #include <libexplain/buffer/errno/fdopendir.h> 00027 #include <libexplain/buffer/fildes.h> 00028 #include <libexplain/explanation.h> 00029 00030 00031 static void 00032 explain_buffer_errno_fdopendir_system_call(explain_string_buffer_t *sb, 00033 int errnum, int fildes) 00034 { 00035 (void)errnum; 00036 explain_string_buffer_puts(sb, "fdopendir(fildes = "); 00037 explain_buffer_fildes(sb, fildes); 00038 explain_string_buffer_putc(sb, ')'); 00039 } 00040 00041 00042 void 00043 explain_buffer_errno_fdopendir_explanation(explain_string_buffer_t *sb, 00044 int errnum, const char *syscall_name, int fildes) 00045 { 00046 switch (errnum) 00047 { 00048 case EBADF: 00049 explain_buffer_ebadf(sb, fildes, "fildes"); 00050 break; 00051 00052 case ENOMEM: 00053 explain_buffer_enomem_user(sb, 0); 00054 break; 00055 00056 case ENOTDIR: 00057 explain_buffer_enotdir_fd(sb, fildes, "fildes"); 00058 break; 00059 00060 case EINVAL: 00061 { 00062 /* recapitulate some eglibc logic */ 00063 int flags = fcntl(fildes, F_GETFL); 00064 if (flags >= 0) 00065 { 00066 /* FIXME: O_DIRECTORY */ 00067 if ((flags & O_ACCMODE) == O_WRONLY) 00068 { 00069 explain_buffer_ebadf_not_open_for_reading 00070 ( 00071 sb, 00072 "fildes", 00073 flags 00074 ); 00075 break; 00076 } 00077 } 00078 } 00079 /* fall through... */ 00080 00081 case ENOSYS: 00082 default: 00083 explain_buffer_errno_generic(sb, errnum, syscall_name); 00084 break; 00085 } 00086 } 00087 00088 00089 void 00090 explain_buffer_errno_fdopendir(explain_string_buffer_t *sb, int errnum, 00091 int fildes) 00092 { 00093 explain_explanation_t exp; 00094 00095 explain_explanation_init(&exp, errnum); 00096 explain_buffer_errno_fdopendir_system_call(&exp.system_call_sb, errnum, 00097 fildes); 00098 explain_buffer_errno_fdopendir_explanation(&exp.explanation_sb, errnum, 00099 "fdopendir", fildes); 00100 explain_explanation_assemble(&exp, sb); 00101 } 00102 00103 00104 /* vim: set ts=8 sw=4 et : */