libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as 00008 * published by the Free Software Foundation; either version 3 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/stdio.h> 00022 00023 #include <libexplain/buffer/enoent.h> 00024 #include <libexplain/buffer/errno/path_resolution.h> 00025 #include <libexplain/buffer/gettext.h> 00026 00027 00028 static void 00029 report_error(explain_string_buffer_t *sb, const char *caption) 00030 { 00031 explain_buffer_gettext_printf 00032 ( 00033 sb, 00034 /* 00035 * xgettext: This explanation is used in response to an ENOENT 00036 * error. This explanation is only used if a more specific 00037 * cause cannot be determined. 00038 * 00039 * %1$s => the name of the offending system call argument. 00040 * %2$s => always identical to the above. 00041 */ 00042 i18n("%s, or a directory component of %s, does not exist or is a " 00043 "dangling symbolic link"), 00044 caption, 00045 caption 00046 ); 00047 } 00048 00049 00050 static void 00051 report_error_dirname(explain_string_buffer_t *sb, const char *caption) 00052 { 00053 explain_buffer_gettext_printf 00054 ( 00055 sb, 00056 /* 00057 * xgettext: This explanation is used in response to an ENOENT 00058 * error. This explanation is only used if a more specific 00059 * cause cannot be determined. 00060 * 00061 * %1$s => the name of the offending system call argument. 00062 */ 00063 i18n("a directory component of %s does not exist or is a dangling " 00064 "symbolic link"), 00065 caption 00066 ); 00067 } 00068 00069 00070 void 00071 explain_buffer_enoent(explain_string_buffer_t *sb, const char *pathname, 00072 const char *pathname_caption, const explain_final_t *final_component) 00073 { 00074 if 00075 ( 00076 explain_buffer_errno_path_resolution 00077 ( 00078 sb, 00079 ENOENT, 00080 pathname, 00081 pathname_caption, 00082 final_component 00083 ) 00084 ) 00085 { 00086 /* 00087 * Unable to find a specific cause, 00088 * emit the generic explanation. 00089 */ 00090 if (final_component->must_exist) 00091 report_error(sb, pathname_caption); 00092 else 00093 report_error_dirname(sb, pathname_caption); 00094 } 00095 } 00096 00097 00098 void 00099 explain_buffer_enoent2(explain_string_buffer_t *sb, 00100 const char *oldpath, const char *oldpath_caption, 00101 const explain_final_t *oldpath_final_component, 00102 const char *newpath, const char *newpath_caption, 00103 const explain_final_t *newpath_final_component) 00104 { 00105 if 00106 ( 00107 explain_buffer_errno_path_resolution 00108 ( 00109 sb, 00110 ENOENT, 00111 oldpath, 00112 oldpath_caption, 00113 oldpath_final_component 00114 ) 00115 && 00116 explain_buffer_errno_path_resolution 00117 ( 00118 sb, 00119 ENOENT, 00120 newpath, 00121 newpath_caption, 00122 newpath_final_component 00123 ) 00124 ) 00125 { 00126 char oldpath_or_newpath[100]; 00127 00128 snprintf 00129 ( 00130 oldpath_or_newpath, 00131 sizeof(oldpath_or_newpath), 00132 "%s or %s", 00133 oldpath_caption, 00134 newpath_caption 00135 ); 00136 00137 /* 00138 * Unable to find a specific cause, 00139 * emit the generic explanation. 00140 */ 00141 if 00142 ( 00143 oldpath_final_component->must_exist 00144 || 00145 newpath_final_component->must_exist 00146 ) 00147 { 00148 report_error(sb, oldpath_or_newpath); 00149 } 00150 else 00151 { 00152 report_error_dirname(sb, oldpath_or_newpath); 00153 } 00154 } 00155 } 00156 00157 00158 /* vim: set ts=8 sw=4 et : */