libexplain  1.4.D001
libexplain/buffer/errno/tmpfile.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/stdio.h>
00021 #include <libexplain/ac/string.h>
00022 #include <libexplain/ac/sys/param.h>
00023 
00024 #include <libexplain/buffer/errno/mkstemp.h>
00025 #include <libexplain/buffer/errno/tmpfile.h>
00026 #include <libexplain/explanation.h>
00027 #include <libexplain/path_search.h>
00028 
00029 
00030 static void
00031 explain_buffer_errno_tmpfile_system_call(explain_string_buffer_t *sb,
00032     int errnum)
00033 {
00034     (void)errnum;
00035     explain_string_buffer_puts(sb, "tmpfile()");
00036 }
00037 
00038 
00039 void
00040 explain_buffer_errno_tmpfile_explanation(explain_string_buffer_t *sb,
00041     int errnum, const char *syscall_name)
00042 {
00043     /*
00044      * We use the same array size that [e]glibc uses.
00045      */
00046     char            pathname[FILENAME_MAX];
00047 
00048     /*
00049      * Do what [e]glibc would do (probably did).
00050      */
00051     const char *dir = NULL;
00052     int try_tmpdir = 0;
00053     if
00054     (
00055         errnum != EFAULT
00056     &&
00057         explain_path_search(pathname, sizeof(pathname), dir, "tmpf", try_tmpdir)
00058     &&
00059         errno == errnum
00060     &&
00061         explain_path_search_explanation(sb, errnum, dir, try_tmpdir) >= 0
00062     )
00063     {
00064         return;
00065     }
00066 
00067     /*
00068      * http://www.opengroup.org/onlinepubs/009695399/functions/tmpfile.html
00069      */
00070     explain_buffer_errno_mkstemp_explanation
00071     (
00072         sb,
00073         errnum,
00074         syscall_name,
00075         pathname
00076     );
00077 }
00078 
00079 
00080 void
00081 explain_buffer_errno_tmpfile(explain_string_buffer_t *sb, int errnum)
00082 {
00083     explain_explanation_t exp;
00084 
00085     explain_explanation_init(&exp, errnum);
00086     explain_buffer_errno_tmpfile_system_call(&exp.system_call_sb, errnum);
00087     explain_buffer_errno_tmpfile_explanation
00088     (
00089         &exp.explanation_sb,
00090         errnum,
00091         "tmpfile"
00092     );
00093     explain_explanation_assemble(&exp, sb);
00094 }
00095 
00096 
00097 /* vim: set ts=8 sw=4 et : */