libexplain  1.4.D001
libexplain/buffer/errno/pathconf.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2012, 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/eacces.h>
00022 #include <libexplain/buffer/eloop.h>
00023 #include <libexplain/buffer/enametoolong.h>
00024 #include <libexplain/buffer/enoent.h>
00025 #include <libexplain/buffer/enotdir.h>
00026 #include <libexplain/buffer/errno/generic.h>
00027 #include <libexplain/buffer/errno/path_resolution.h>
00028 #include <libexplain/buffer/errno/pathconf.h>
00029 #include <libexplain/buffer/pathconf_name.h>
00030 #include <libexplain/buffer/pathname.h>
00031 #include <libexplain/explanation.h>
00032 
00033 
00034 static void
00035 explain_buffer_errno_pathconf_system_call(explain_string_buffer_t *sb,
00036     int errnum, const char *pathname, int name)
00037 {
00038     (void)errnum;
00039     explain_string_buffer_puts(sb, "pathconf(pathname = ");
00040     explain_buffer_pathname(sb, pathname);
00041     explain_string_buffer_puts(sb, ", name = ");
00042     explain_buffer_pathconf_name(sb, name);
00043     explain_string_buffer_putc(sb, ')');
00044 }
00045 
00046 
00047 void
00048 explain_buffer_pathconf_einval(explain_string_buffer_t *sb,
00049     const char *arg1_caption, int name, const char *name_caption)
00050 {
00051     if (!explain_valid_pathconf_name(name))
00052     {
00053         explain_string_buffer_printf_gettext
00054         (
00055             sb,
00056             /*
00057              * xgettext: This message is used to explain an EINVAL error
00058              * reported by the pathconf system call.
00059              *
00060              * %1$s => the name of the offending system call argument.
00061              */
00062             i18n("%s does not refer to a known file configuration value"),
00063             name_caption
00064         );
00065     }
00066     else
00067     {
00068         explain_string_buffer_printf_gettext
00069         (
00070             sb,
00071             /*
00072              * xgettext: This message is used to explain an EINVAL error
00073              * reported by the pathconf system call.
00074              *
00075              * %1$s => the name of the system call argument containing
00076              *         the 'name' selector, e.g. _PC_NAME_MAX
00077              * %2$s => the name of the first argument, "pathname" or "fildes"
00078              */
00079             i18n("the implementation does not support an association of "
00080                 "%s with %s"),
00081             name_caption,
00082             arg1_caption
00083         );
00084     }
00085 }
00086 
00087 
00088 static void
00089 explain_buffer_errno_pathconf_explanation(explain_string_buffer_t *sb,
00090     int errnum, const char *pathname, int name)
00091 {
00092     explain_final_t final_component;
00093 
00094     /*
00095      * http://www.opengroup.org/onlinepubs/009695399/functions/pathconf.html
00096      */
00097     (void)name;
00098     explain_final_init(&final_component);
00099     switch (errnum)
00100     {
00101     case ELOOP:
00102         explain_buffer_eloop(sb, pathname, "pathname", &final_component);
00103         break;
00104 
00105     case EACCES:
00106         explain_buffer_eacces(sb, pathname, "pathname", &final_component);
00107         break;
00108 
00109     case EINVAL:
00110     case ENOSYS: /* many systems say this for EINVAL */
00111 #ifdef EOPNOTSUPP
00112     case EOPNOTSUPP: /* HPUX says this for EINVAL */
00113 #endif
00114         explain_buffer_pathconf_einval(sb, "pathname", name, "name");
00115         break;
00116 
00117     case ENAMETOOLONG:
00118         explain_buffer_enametoolong
00119         (
00120             sb,
00121             pathname,
00122             "pathname",
00123             &final_component
00124         );
00125         break;
00126 
00127     case ENOENT:
00128         explain_buffer_enoent(sb, pathname, "pathname", &final_component);
00129         break;
00130 
00131     case ENOTDIR:
00132         explain_buffer_enotdir(sb, pathname, "pathname", &final_component);
00133         break;
00134 
00135     default:
00136         explain_buffer_errno_generic(sb, errnum, "pathconf");
00137         break;
00138     }
00139 }
00140 
00141 
00142 void
00143 explain_buffer_errno_pathconf(explain_string_buffer_t *sb, int errnum,
00144     const char *pathname, int name)
00145 {
00146     explain_explanation_t exp;
00147 
00148     explain_explanation_init(&exp, errnum);
00149     explain_buffer_errno_pathconf_system_call
00150     (
00151         &exp.system_call_sb,
00152         errnum,
00153         pathname,
00154         name
00155     );
00156     explain_buffer_errno_pathconf_explanation
00157     (
00158         &exp.explanation_sb,
00159         errnum,
00160         pathname,
00161         name
00162     );
00163     explain_explanation_assemble(&exp, sb);
00164 }
00165 
00166 
00167 /* vim: set ts=8 sw=4 et : */