libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 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/errno/lseek.h> 00022 #include <libexplain/buffer/errno/pread.h> 00023 #include <libexplain/buffer/errno/read.h> 00024 #include <libexplain/buffer/fildes.h> 00025 #include <libexplain/buffer/off_t.h> 00026 #include <libexplain/buffer/pointer.h> 00027 #include <libexplain/buffer/size_t.h> 00028 #include <libexplain/explanation.h> 00029 00030 00031 static void 00032 explain_buffer_errno_pread_system_call(explain_string_buffer_t *sb, int errnum, 00033 int fildes, void *data, size_t data_size, off_t offset) 00034 { 00035 (void)errnum; 00036 explain_string_buffer_puts(sb, "pread(fildes = "); 00037 explain_buffer_fildes(sb, fildes); 00038 explain_string_buffer_puts(sb, ", data = "); 00039 explain_buffer_pointer(sb, data); 00040 explain_string_buffer_puts(sb, ", data_size = "); 00041 explain_buffer_size_t(sb, data_size); 00042 explain_string_buffer_puts(sb, ", offset = "); 00043 explain_buffer_off_t(sb, offset); 00044 explain_string_buffer_putc(sb, ')'); 00045 } 00046 00047 00048 static void 00049 explain_buffer_errno_pread_explanation(explain_string_buffer_t *sb, int errnum, 00050 const char *syscall_name, int fildes, void *data, size_t data_size, 00051 off_t offset) 00052 { 00053 /* 00054 * http://www.opengroup.org/onlinepubs/009695399/functions/pread.html 00055 */ 00056 switch (errnum) 00057 { 00058 default: 00059 caused_by_read: 00060 explain_buffer_errno_read_explanation 00061 ( 00062 sb, 00063 errnum, 00064 syscall_name, 00065 fildes, 00066 data, 00067 data_size 00068 ); 00069 break; 00070 00071 case EBADF: 00072 case ESPIPE: 00073 case ENOSYS: 00074 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS 00075 case EOPNOTSUPP: 00076 #endif 00077 caused_by_lseek: 00078 explain_buffer_errno_lseek_explanation 00079 ( 00080 sb, 00081 errnum, 00082 syscall_name, 00083 fildes, 00084 offset, 00085 SEEK_SET 00086 ); 00087 break; 00088 00089 case EINVAL: 00090 if (offset < 0) 00091 goto caused_by_lseek; 00092 goto caused_by_read; 00093 } 00094 } 00095 00096 00097 void 00098 explain_buffer_errno_pread(explain_string_buffer_t *sb, int errnum, int fildes, 00099 void *data, size_t data_size, off_t offset) 00100 { 00101 explain_explanation_t exp; 00102 00103 explain_explanation_init(&exp, errnum); 00104 explain_buffer_errno_pread_system_call 00105 ( 00106 &exp.system_call_sb, 00107 errnum, 00108 fildes, 00109 data, 00110 data_size, 00111 offset 00112 ); 00113 explain_buffer_errno_pread_explanation 00114 ( 00115 &exp.explanation_sb, 00116 errnum, 00117 "pread", 00118 fildes, 00119 data, 00120 data_size, 00121 offset 00122 ); 00123 explain_explanation_assemble(&exp, sb); 00124 } 00125 00126 00127 /* vim: set ts=8 sw=4 et : */