From: David Lawrence Ramsey Date: Wed, 18 Apr 2007 18:22:13 +0000 (+0000) Subject: fix various file- and rcfile-opening bugs X-Git-Tag: v2.0.5~16 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=529a98a8bbaa1d24351c182a8793dd67a5bed6c7;p=nano.git fix various file- and rcfile-opening bugs git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4080 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 0186f6fb..80240087 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ CVS code - - files.c: + open_file() + - Open files using their full paths whenever possible, so that + ~user/file.txt and "~user/file.txt" are treated the same way + if ~user is a user's home directory. (DLR) real_dir_from_tilde() - Fix segfault when dealing with directory names that begin with "~", but that aren't users' home directories. (DLR, found by @@ -13,6 +17,15 @@ CVS code - input_tab() - Don't bother checking if num_matches is less than zero, as it's a size_t and hence unsigned. (DLR) +- rcfile.c: + parse_include() + - Open files using their full paths whenever possible, so that + ~user/file.txt and "~user/file.txt" are treated the same way + if ~user is a user's home directory. (DLR) + - Properly check for the included file's being a directory, a + character file, or a block file. (DLR) + - For consistency, display the filename as the user entered it + if we can't read the specified file. (DLR) - winio.c: parse_kbinput() - Interpret Cancel and Shift-Cancel. (DLR) diff --git a/src/files.c b/src/files.c index 68a1288e..2cd54d2f 100644 --- a/src/files.c +++ b/src/files.c @@ -586,10 +586,17 @@ int open_file(const char *filename, bool newfie, FILE **f) { struct stat fileinfo; int fd; + char *full_filename; assert(filename != NULL && f != NULL); - if (stat(filename, &fileinfo) == -1) { + /* Get the specified file's full path. */ + full_filename = get_full_path(filename); + + if (full_filename == NULL) + full_filename = mallocstrcpy(NULL, filename); + + if (stat(full_filename, &fileinfo) == -1) { if (newfie) { statusbar(_("New File")); return -2; @@ -606,8 +613,9 @@ int open_file(const char *filename, bool newfie, FILE **f) _("\"%s\" is a device file"), filename); beep(); return -1; - } else if ((fd = open(filename, O_RDONLY)) == -1) { - statusbar(_("Error reading %s: %s"), filename, strerror(errno)); + } else if ((fd = open(full_filename, O_RDONLY)) == -1) { + statusbar(_("Error reading %s: %s"), filename, + strerror(errno)); beep(); return -1; } else { @@ -623,6 +631,8 @@ int open_file(const char *filename, bool newfie, FILE **f) statusbar(_("Reading File")); } + free(full_filename); + return 0; } diff --git a/src/rcfile.c b/src/rcfile.c index 7aa75d0c..d2e20edc 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -363,25 +363,23 @@ void parse_include(char *ptr) /* Get the specified file's full path. */ full_option = get_full_path(option); - if (full_option == NULL) { - rcfile_error(_("Error reading %s: %s"), option, strerror(errno)); - goto cleanup_include; - } + if (full_option == NULL) + full_option = mallocstrcpy(NULL, option); /* Don't open directories, character files, or block files. */ - if (stat(nanorc, &rcinfo) != -1) { + if (stat(full_option, &rcinfo) != -1) { if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || S_ISBLK(rcinfo.st_mode)) { rcfile_error(S_ISDIR(rcinfo.st_mode) ? _("\"%s\" is a directory") : - _("\"%s\" is a device file"), nanorc); + _("\"%s\" is a device file"), option); goto cleanup_include; } } /* Open the new syntax file. */ if ((rcstream = fopen(full_option, "rb")) == NULL) { - rcfile_error(_("Error reading %s: %s"), full_option, + rcfile_error(_("Error reading %s: %s"), option, strerror(errno)); goto cleanup_include; }