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/efault.h> 00023 #include <libexplain/buffer/einval.h> 00024 #include <libexplain/buffer/emfile.h> 00025 #include <libexplain/buffer/enfile.h> 00026 #include <libexplain/buffer/errno/generic.h> 00027 #include <libexplain/buffer/errno/pipe2.h> 00028 #include <libexplain/buffer/is_the_null_pointer.h> 00029 #include <libexplain/buffer/open_flags.h> 00030 #include <libexplain/buffer/pointer.h> 00031 #include <libexplain/explanation.h> 00032 00033 00034 static void 00035 explain_buffer_errno_pipe2_system_call(explain_string_buffer_t *sb, int errnum, 00036 int *fildes, int flags) 00037 { 00038 (void)errnum; 00039 explain_string_buffer_puts(sb, "pipe2(fildes = "); 00040 explain_buffer_pointer(sb, fildes); 00041 explain_string_buffer_puts(sb, ", flags = "); 00042 explain_buffer_open_flags(sb, flags); 00043 explain_string_buffer_putc(sb, ')'); 00044 } 00045 00046 00047 void 00048 explain_buffer_errno_pipe2_explanation(explain_string_buffer_t *sb, int errnum, 00049 const char *syscall_name, int *fildes, int flags) 00050 { 00051 switch (errnum) 00052 { 00053 case EFAULT: 00054 if (!fildes) 00055 { 00056 explain_buffer_is_the_null_pointer(sb, "fildes"); 00057 break; 00058 } 00059 explain_buffer_efault(sb, "fildes"); 00060 break; 00061 00062 case EINVAL: 00063 if (flags & ~(O_NONBLOCK | O_CLOEXEC)) 00064 { 00065 explain_buffer_einval_bits(sb, "flags"); 00066 break; 00067 } 00068 goto generic; 00069 00070 case EMFILE: 00071 explain_buffer_emfile(sb); 00072 break; 00073 00074 case ENFILE: 00075 explain_buffer_enfile(sb); 00076 break; 00077 00078 default: 00079 generic: 00080 explain_buffer_errno_generic(sb, errnum, syscall_name); 00081 break; 00082 } 00083 } 00084 00085 00086 void 00087 explain_buffer_errno_pipe2(explain_string_buffer_t *sb, int errnum, int *fildes, 00088 int flags) 00089 { 00090 explain_explanation_t exp; 00091 00092 explain_explanation_init(&exp, errnum); 00093 explain_buffer_errno_pipe2_system_call(&exp.system_call_sb, errnum, fildes, 00094 flags); 00095 explain_buffer_errno_pipe2_explanation(&exp.explanation_sb, errnum, "pipe2", 00096 fildes, flags); 00097 explain_explanation_assemble(&exp, sb); 00098 } 00099 00100 00101 /* vim: set ts=8 sw=4 et : */