libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2012, 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/fcntl.h> /* for AT_FDCWD */ 00020 #include <libexplain/ac/limits.h> /* for PATH_MAX on Solaris */ 00021 #include <libexplain/ac/sys/param.h> /* for PATH_MAX except Solaris */ 00022 00023 #include <libexplain/buffer/errno/path_resolution.h> 00024 #include <libexplain/fileinfo.h> 00025 00026 00027 int 00028 explain_buffer_errno_path_resolution_at(explain_string_buffer_t *sb, 00029 int errnum, int fildes, const char *pathname, const char *pathname_caption, 00030 const explain_final_t *final_component) 00031 { 00032 char path2[PATH_MAX + 1]; 00033 explain_string_buffer_t sb2; 00034 00035 /* 00036 * The explain_buffer_erro_path_resolution function doesn't grok 00037 * "relative to fildes" so turn the fildes into a path, and build a 00038 * path that the path_resolution code does understand. 00039 */ 00040 explain_string_buffer_init(&sb2, path2, sizeof(path2)); 00041 if (fildes == AT_FDCWD || pathname[0] == '/') 00042 { 00043 explain_string_buffer_puts(&sb2, pathname); 00044 } 00045 else 00046 { 00047 char path3[PATH_MAX + 1]; 00048 00049 if (!explain_fileinfo_self_fd_n(fildes, path3, sizeof(path3))) 00050 return -1; 00051 explain_string_buffer_puts(&sb2, path3); 00052 explain_string_buffer_path_join(&sb2, pathname); 00053 } 00054 00055 return 00056 explain_buffer_errno_path_resolution 00057 ( 00058 sb, 00059 errnum, 00060 path2, 00061 pathname_caption, 00062 final_component 00063 ); 00064 } 00065 00066 00067 /* vim: set ts=8 sw=4 et : */