libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 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 00008 * published by the Free Software Foundation; either version 3 of the 00009 * License, or (at 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/ebadf.h> 00024 #include <libexplain/buffer/enotdir.h> 00025 #include <libexplain/buffer/errno/fchdir.h> 00026 #include <libexplain/buffer/errno/generic.h> 00027 #include <libexplain/buffer/fildes_to_pathname.h> 00028 #include <libexplain/buffer/file_type.h> 00029 #include <libexplain/explanation.h> 00030 #include <libexplain/string_buffer.h> 00031 00032 00033 static void 00034 explain_buffer_errno_fchdir_system_call(explain_string_buffer_t *sb, 00035 int errnum, int fildes) 00036 { 00037 (void)errnum; 00038 explain_string_buffer_printf(sb, "fchdir(fildes = %d", fildes); 00039 explain_buffer_fildes_to_pathname(sb, fildes); 00040 explain_string_buffer_putc(sb, ')'); 00041 } 00042 00043 00044 static void 00045 explain_buffer_errno_fchdir_explanation(explain_string_buffer_t *sb, 00046 int errnum, int fildes) 00047 { 00048 switch (errnum) 00049 { 00050 case EBADF: 00051 explain_buffer_ebadf(sb, fildes, "fildes"); 00052 break; 00053 00054 case ENOTDIR: 00055 explain_buffer_enotdir_fd(sb, fildes, "fildes"); 00056 break; 00057 00058 case EACCES: 00059 explain_string_buffer_puts 00060 ( 00061 sb, 00062 "search permission was denied on the directory" 00063 ); 00064 break; 00065 00066 default: 00067 explain_buffer_errno_generic(sb, errnum, "fchdir"); 00068 break; 00069 } 00070 } 00071 00072 00073 void 00074 explain_buffer_errno_fchdir(explain_string_buffer_t *sb, int errnum, 00075 int fildes) 00076 { 00077 explain_explanation_t exp; 00078 00079 explain_explanation_init(&exp, errnum); 00080 explain_buffer_errno_fchdir_system_call 00081 ( 00082 &exp.system_call_sb, 00083 errnum, 00084 fildes 00085 ); 00086 explain_buffer_errno_fchdir_explanation 00087 ( 00088 &exp.explanation_sb, 00089 errnum, 00090 fildes 00091 ); 00092 explain_explanation_assemble(&exp, sb); 00093 } 00094 00095 00096 /* vim: set ts=8 sw=4 et : */