libexplain
1.4.D001
|
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/string.h> 00022 #include <libexplain/ac/sys/stat.h> 00023 00024 #include <libexplain/buffer/eexist.h> 00025 #include <libexplain/buffer/einval.h> 00026 #include <libexplain/buffer/errno/mkostemp.h> 00027 #include <libexplain/buffer/errno/open.h> 00028 #include <libexplain/buffer/open_flags.h> 00029 #include <libexplain/buffer/pathname.h> 00030 #include <libexplain/explanation.h> 00031 00032 00033 static void 00034 explain_buffer_errno_mkostemp_system_call(explain_string_buffer_t *sb, int 00035 errnum, const char *pathname, int flags) 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, "mkostemp(pathname = "); 00043 explain_buffer_pathname(sb, pathname); 00044 explain_string_buffer_puts(sb, ", flags = "); 00045 explain_buffer_open_flags(sb, flags); 00046 explain_string_buffer_putc(sb, ')'); 00047 } 00048 00049 00050 void 00051 explain_buffer_errno_mkostemp_explanation(explain_string_buffer_t *sb, int 00052 errnum, const char *syscall_name, const char *pathname, int flags) 00053 { 00054 size_t len; 00055 00056 /* 00057 * http://www.opengroup.org/onlinepubs/009695399/functions/mkostemp.html 00058 */ 00059 switch (errnum) 00060 { 00061 case EINVAL: 00062 /* 00063 * This case could be ambiguous. The flags combinations could 00064 * be invalid, or the template could be invalid. Since the 00065 * template could have been modified at this point, we can only 00066 * detect the length being wrong. Otherwise, assume the flags 00067 * bits were invalid. 00068 */ 00069 len = strlen(pathname); 00070 if (len < 6) 00071 { 00072 explain_buffer_einval_mkstemp(sb, pathname, "pathname"); 00073 break; 00074 } 00075 /* Fall through... */ 00076 00077 case EEXIST: 00078 explain_buffer_eexist_tempname_dirname(sb, pathname); 00079 break; 00080 00081 default: 00082 explain_buffer_errno_open_explanation 00083 ( 00084 sb, 00085 errnum, 00086 syscall_name, 00087 pathname, 00088 /* this is what [e]glibc does to the flags */ 00089 (flags & ~O_ACCMODE) | O_RDWR | O_CREAT | O_EXCL, 00090 S_IRUSR | S_IWUSR 00091 ); 00092 break; 00093 } 00094 } 00095 00096 00097 void 00098 explain_buffer_errno_mkostemp(explain_string_buffer_t *sb, int errnum, 00099 const char *pathname, int flags) 00100 { 00101 explain_explanation_t exp; 00102 00103 explain_explanation_init(&exp, errnum); 00104 explain_buffer_errno_mkostemp_system_call(&exp.system_call_sb, errnum, 00105 pathname, flags); 00106 explain_buffer_errno_mkostemp_explanation(&exp.explanation_sb, errnum, 00107 "mkostemp", pathname, flags); 00108 explain_explanation_assemble(&exp, sb); 00109 } 00110 00111 00112 /* vim: set ts=8 sw=4 et : */