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/enametoolong.h> 00024 #include <libexplain/buffer/errno/path_resolution.h> 00025 00026 00027 static void 00028 report_error(explain_string_buffer_t *sb, const char *caption) 00029 { 00030 explain_string_buffer_printf 00031 ( 00032 sb, 00033 "%s, or a directory component of %s, is too long", 00034 caption, 00035 caption 00036 ); 00037 } 00038 00039 00040 void 00041 explain_buffer_enametoolong(explain_string_buffer_t *sb, 00042 const char *pathname, const char *pathname_caption, 00043 const explain_final_t *final_component) 00044 { 00045 if 00046 ( 00047 explain_buffer_errno_path_resolution 00048 ( 00049 sb, 00050 ENAMETOOLONG, 00051 pathname, 00052 pathname_caption, 00053 final_component 00054 ) 00055 ) 00056 { 00057 /* 00058 * Unable to find a specific cause, 00059 * emit the generic explanation. 00060 */ 00061 report_error(sb, pathname_caption); 00062 } 00063 } 00064 00065 00066 void 00067 explain_buffer_enametoolong2(explain_string_buffer_t *sb, 00068 const char *oldpath, const char *oldpath_caption, 00069 const explain_final_t *oldpath_final_component, 00070 const char *newpath, const char *newpath_caption, 00071 const explain_final_t *newpath_final_component) 00072 { 00073 if 00074 ( 00075 explain_buffer_errno_path_resolution 00076 ( 00077 sb, 00078 ENAMETOOLONG, 00079 oldpath, 00080 oldpath_caption, 00081 oldpath_final_component 00082 ) 00083 && 00084 explain_buffer_errno_path_resolution 00085 ( 00086 sb, 00087 ENAMETOOLONG, 00088 newpath, 00089 newpath_caption, 00090 newpath_final_component 00091 ) 00092 ) 00093 { 00094 char buffer[40]; 00095 00096 /* 00097 * Unable to pin point a specific cause, 00098 * use the generic explanatiuon. 00099 */ 00100 snprintf 00101 ( 00102 buffer, 00103 sizeof(buffer), 00104 "%s or %s", 00105 oldpath_caption, 00106 newpath_caption 00107 ); 00108 report_error(sb, buffer); 00109 } 00110 } 00111 00112 00113 /* vim: set ts=8 sw=4 et : */