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,but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty 00012 * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser 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/buffer/dac.h> 00022 #include <libexplain/buffer/efault.h> 00023 #include <libexplain/buffer/einval.h> 00024 #include <libexplain/buffer/errno/generic.h> 00025 #include <libexplain/buffer/errno/setdomainname.h> 00026 #include <libexplain/buffer/gettext.h> 00027 #include <libexplain/buffer/size_t.h> 00028 #include <libexplain/buffer/string_n.h> 00029 #include <libexplain/explanation.h> 00030 00031 00032 static void 00033 explain_buffer_errno_setdomainname_system_call(explain_string_buffer_t *sb, int 00034 errnum, const char *data, size_t data_size) 00035 { 00036 (void)errnum; 00037 explain_string_buffer_puts(sb, "setdomainname(data = "); 00038 explain_buffer_string_n(sb, data, data_size); 00039 explain_string_buffer_puts(sb, ", data_size = "); 00040 explain_buffer_size_t(sb, data_size); 00041 explain_string_buffer_putc(sb, ')'); 00042 } 00043 00044 00045 static void 00046 explain_buffer_errno_setdomainname_explanation(explain_string_buffer_t *sb, 00047 int errnum, const char *data, size_t data_size) 00048 { 00049 (void)data; 00050 switch (errnum) 00051 { 00052 case EFAULT: 00053 explain_buffer_efault(sb, "data"); 00054 break; 00055 00056 case EINVAL: 00057 if ((int)data_size < 0) 00058 explain_buffer_einval_too_small(sb, "data_size", data_size); 00059 else 00060 explain_buffer_einval_too_large(sb, "data_size"); 00061 break; 00062 00063 case EPERM: 00064 explain_buffer_gettext 00065 ( 00066 sb, 00067 /* 00068 * xgettext: this error message is issued when a process 00069 * attempts to set the domain name without sufficient privilege. 00070 */ 00071 i18n("the process does not have permission to set the domain name") 00072 ); 00073 explain_buffer_dac_sys_admin(sb); 00074 break; 00075 00076 default: 00077 explain_buffer_errno_generic(sb, errnum, "setdomainname"); 00078 break; 00079 } 00080 } 00081 00082 00083 void 00084 explain_buffer_errno_setdomainname(explain_string_buffer_t *sb, int errnum, 00085 const char *data, size_t data_size) 00086 { 00087 explain_explanation_t exp; 00088 00089 explain_explanation_init(&exp, errnum); 00090 explain_buffer_errno_setdomainname_system_call(&exp.system_call_sb, errnum, 00091 data, data_size); 00092 explain_buffer_errno_setdomainname_explanation(&exp.explanation_sb, errnum, 00093 data, data_size); 00094 explain_explanation_assemble(&exp, sb); 00095 } 00096 00097 00098 /* vim: set ts=8 sw=4 et : */