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 00021 #include <libexplain/acl_grammar.h> 00022 #include <libexplain/buffer/enomem.h> 00023 #include <libexplain/buffer/errno/acl_from_text.h> 00024 #include <libexplain/buffer/errno/generic.h> 00025 #include <libexplain/buffer/is_the_null_pointer.h> 00026 #include <libexplain/explanation.h> 00027 00028 00029 static void 00030 explain_buffer_errno_acl_from_text_system_call(explain_string_buffer_t *sb, int 00031 errnum, const char *text) 00032 { 00033 (void)errnum; 00034 explain_string_buffer_puts(sb, "acl_from_text(text = "); 00035 explain_string_buffer_puts_quoted(sb, text); 00036 explain_string_buffer_putc(sb, ')'); 00037 } 00038 00039 00040 void 00041 explain_buffer_errno_acl_from_text_explanation(explain_string_buffer_t *sb, 00042 int errnum, const char *syscall_name, const char *text) 00043 { 00044 switch (errnum) 00045 { 00046 case EINVAL: 00047 /* 00048 * The argument text cannot be translated into an ACL. 00049 */ 00050 if (!text) 00051 { 00052 explain_buffer_is_the_null_pointer(sb, text); 00053 break; 00054 } 00055 explain_string_buffer_puts(sb, explain_acl_parse(text)); 00056 break; 00057 00058 case ENOMEM: 00059 /* 00060 * The acl_t to be returned requires more memory than is 00061 * allowed by the hardware or system-imposed memory management 00062 * constraints. 00063 */ 00064 explain_buffer_enomem_user(sb, 0); 00065 break; 00066 00067 default: 00068 explain_buffer_errno_generic(sb, errnum, syscall_name); 00069 break; 00070 } 00071 } 00072 00073 00074 void 00075 explain_buffer_errno_acl_from_text(explain_string_buffer_t *sb, int errnum, 00076 const char *text) 00077 { 00078 explain_explanation_t exp; 00079 00080 explain_explanation_init(&exp, errnum); 00081 explain_buffer_errno_acl_from_text_system_call 00082 ( 00083 &exp.system_call_sb, 00084 errnum, 00085 text 00086 ); 00087 explain_buffer_errno_acl_from_text_explanation 00088 ( 00089 &exp.explanation_sb, 00090 errnum, 00091 "acl_from_text", 00092 text 00093 ); 00094 explain_explanation_assemble(&exp, sb); 00095 } 00096 00097 00098 /* vim: set ts=8 sw=4 et : */