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