commit 75a70d98d59a1b30d96617d8c71ce6c2d43d24fa
parent b3374ea1fb595d0486078f8a915b7d4401793081
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 10 Feb 2020 16:56:35 +0100
tweaks: reshuffle two declarations plus a fragment of code
Also, don't bother statting the path that the user provided,
as that case will happen right away in the next 'if'.
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -899,26 +899,25 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
* obtained fd otherwise. *f is set to the opened file. */
int open_file(const char *filename, bool new_one, FILE **f)
{
- struct stat fileinfo, fileinfo2;
- int fd;
char *full_filename = get_full_path(filename);
+ struct stat fileinfo;
+ int fd;
/* If the full path is unusable (due to some component's permissions),
* but the relative path is okay, then just use that one. */
- if (full_filename == NULL || (stat(full_filename, &fileinfo) == -1 &&
- stat(filename, &fileinfo2) != -1))
+ if (full_filename == NULL || stat(full_filename, &fileinfo) == -1)
full_filename = mallocstrcpy(full_filename, filename);
if (stat(full_filename, &fileinfo) == -1) {
+ free(full_filename);
+
if (new_one) {
statusbar(_("New File"));
- free(full_filename);
return 0;
+ } else {
+ statusline(ALERT, _("File \"%s\" not found"), filename);
+ return -1;
}
-
- statusline(ALERT, _("File \"%s\" not found"), filename);
- free(full_filename);
- return -1;
}
#ifndef NANO_TINY