libexplain  1.4.D001
libexplain/buffer/errno/mkdtemp.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2010, 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 #include <libexplain/ac/sys/stat.h>
00021 
00022 #include <libexplain/buffer/eexist.h>
00023 #include <libexplain/buffer/efault.h>
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/errno/mkdir.h>
00026 #include <libexplain/buffer/errno/mkdtemp.h>
00027 #include <libexplain/buffer/pathname.h>
00028 #include <libexplain/explanation.h>
00029 
00030 
00031 static void
00032 explain_buffer_errno_mkdtemp_system_call(explain_string_buffer_t *sb, int
00033     errnum, char *pathname)
00034 {
00035     (void)errnum;
00036     /*
00037      * The argument must be called "pathname" so that the explanations
00038      * for mkdir() make sense.
00039      */
00040     explain_string_buffer_puts(sb, "mkdtemp(pathname = ");
00041     explain_buffer_pathname(sb, pathname);
00042     explain_string_buffer_putc(sb, ')');
00043 }
00044 
00045 
00046 void
00047 explain_buffer_errno_mkdtemp_explanation(explain_string_buffer_t *sb, int
00048     errnum, const char *syscall_name, char *pathname)
00049 {
00050     /*
00051      * http://www.opengroup.org/onlinepubs/009695399/functions/mkdtemp.html
00052      */
00053     switch (errnum)
00054     {
00055     case EFAULT:
00056         explain_buffer_efault(sb, "pathname");
00057         break;
00058 
00059     case EINVAL:
00060         explain_buffer_einval_mkstemp(sb, pathname, "pathname");
00061         break;
00062 
00063     case EEXIST:
00064         explain_buffer_eexist_tempname_dirname(sb, pathname);
00065         break;
00066 
00067     default:
00068         explain_buffer_errno_mkdir_explanation
00069         (
00070             sb,
00071             errnum,
00072             syscall_name,
00073             pathname,
00074             S_IRUSR | S_IWUSR | S_IXUSR
00075         );
00076         break;
00077     }
00078 }
00079 
00080 
00081 void
00082 explain_buffer_errno_mkdtemp(explain_string_buffer_t *sb, int errnum, char
00083     *pathname)
00084 {
00085     explain_explanation_t exp;
00086 
00087     explain_explanation_init(&exp, errnum);
00088     explain_buffer_errno_mkdtemp_system_call(&exp.system_call_sb, errnum,
00089         pathname);
00090     explain_buffer_errno_mkdtemp_explanation(&exp.explanation_sb, errnum,
00091         "mkdtemp", pathname);
00092     explain_explanation_assemble(&exp, sb);
00093 }
00094 
00095 
00096 /* vim: set ts=8 sw=4 et : */