libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008-2010, 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, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser 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 00021 #include <libexplain/buffer/ebadf.h> 00022 #include <libexplain/buffer/enomem.h> 00023 #include <libexplain/buffer/errno/fstat.h> 00024 #include <libexplain/buffer/errno/generic.h> 00025 #include <libexplain/buffer/fildes_to_pathname.h> 00026 #include <libexplain/buffer/pointer.h> 00027 #include <libexplain/explanation.h> 00028 00029 00030 static void 00031 explain_buffer_errno_fstat_system_call(explain_string_buffer_t *sb, 00032 int errnum, int fildes, const struct stat *data) 00033 { 00034 (void)errnum; 00035 explain_string_buffer_printf(sb, "fstat(fildes = %d", fildes); 00036 explain_buffer_fildes_to_pathname(sb, fildes); 00037 explain_string_buffer_puts(sb, ", data = "); 00038 explain_buffer_pointer(sb, data); 00039 explain_string_buffer_putc(sb, ')'); 00040 } 00041 00042 00043 void 00044 explain_buffer_errno_fstat_explanation(explain_string_buffer_t *sb, 00045 int errnum, const char *syscall_name, int fildes, const struct stat *data) 00046 { 00047 (void)data; 00048 switch (errnum) 00049 { 00050 case EBADF: 00051 explain_buffer_ebadf(sb, fildes, "fildes"); 00052 break; 00053 00054 case ENOMEM: 00055 explain_buffer_enomem_kernel(sb); 00056 break; 00057 00058 default: 00059 explain_buffer_errno_generic(sb, errnum, syscall_name); 00060 break; 00061 } 00062 } 00063 00064 00065 void 00066 explain_buffer_errno_fstat(explain_string_buffer_t *sb, int errnum, 00067 int fildes, const struct stat *data) 00068 { 00069 explain_explanation_t exp; 00070 00071 explain_explanation_init(&exp, errnum); 00072 explain_buffer_errno_fstat_system_call 00073 ( 00074 &exp.system_call_sb, 00075 errnum, 00076 fildes, 00077 data 00078 ); 00079 explain_buffer_errno_fstat_explanation 00080 ( 00081 &exp.explanation_sb, 00082 errnum, 00083 "fstat", 00084 fildes, 00085 data 00086 ); 00087 explain_explanation_assemble(&exp, sb); 00088 } 00089 00090 00091 /* vim: set ts=8 sw=4 et : */