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 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser 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/limits.h> /* for PATH_MAX on Solaris */ 00020 #include <libexplain/ac/sys/param.h> /* for PATH_MAX except Solaris */ 00021 #include <libexplain/ac/sys/stat.h> 00022 00023 #include <libexplain/buffer/caption_name_type.h> 00024 #include <libexplain/buffer/eexist.h> 00025 #include <libexplain/dirname.h> 00026 #include <libexplain/name_max.h> 00027 00028 00029 void 00030 explain_buffer_eexist(explain_string_buffer_t *sb, const char *pathname) 00031 { 00032 struct stat pathname_st; 00033 struct stat dirname_st; 00034 char basename[NAME_MAX + 1]; 00035 char dirname[PATH_MAX]; 00036 00037 if (lstat(pathname, &pathname_st) < 0) 00038 pathname_st.st_mode = -1; 00039 explain_basename(basename, pathname, sizeof(basename)); 00040 00041 explain_dirname(dirname, pathname, sizeof(dirname)); 00042 if (stat(dirname, &dirname_st) < 0) 00043 dirname_st.st_mode = S_IFDIR; 00044 00045 explain_buffer_eexist5 00046 ( 00047 sb, 00048 basename, 00049 pathname_st.st_mode, 00050 dirname, 00051 dirname_st.st_mode 00052 ); 00053 } 00054 00055 00056 void 00057 explain_buffer_eexist5(explain_string_buffer_t *sb, const char *base_name, 00058 int base_mode, const char *dir_name, int dir_mode) 00059 { 00060 explain_string_buffer_t base_cnt_sb; 00061 explain_string_buffer_t dir_cnt_sb; 00062 char base_cnt[NAME_MAX + 50]; 00063 char dir_cnt[PATH_MAX + 50]; 00064 00065 explain_string_buffer_init(&base_cnt_sb, base_cnt, sizeof(base_cnt)); 00066 explain_buffer_caption_name_type(&base_cnt_sb, 0, base_name, base_mode); 00067 00068 explain_string_buffer_init(&dir_cnt_sb, dir_cnt, sizeof(dir_cnt)); 00069 explain_buffer_caption_name_type(&dir_cnt_sb, 0, dir_name, dir_mode); 00070 00071 explain_string_buffer_printf_gettext 00072 ( 00073 sb, 00074 /* 00075 * xgettext: This error message is issued when a system call 00076 * reports an EEXIST error, in the case where the directory 00077 * entry to be created already exists, although possibly not the 00078 * intended type. 00079 * 00080 * %1$s => the name and type of the file, the last path component 00081 * %2$s => the name and type of the containing directory, all but the 00082 * last path component. 00083 */ 00084 i18n("there is already a %s in the %s"), 00085 base_cnt, 00086 dir_cnt 00087 ); 00088 } 00089 00090 00091 /* vim: set ts=8 sw=4 et : */