commit 3eeedd7caf9304fa39ebad128633a7cfdc980c5a
parent 410dcee0a1ca411a0e8a7d0087479e97f68fef3e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 10 Feb 2020 09:55:21 +0100
tweaks: move a function to before the one that calls it
Diffstat:
M | src/files.c | | | 58 | +++++++++++++++++++++++++++++----------------------------- |
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -30,35 +30,6 @@
#include <string.h>
#include <unistd.h>
-/* Verify that the containing directory of the given filename exists. */
-bool has_valid_path(const char *filename)
-{
- char *namecopy = copy_of(filename);
- char *parentdir = dirname(namecopy);
- struct stat parentinfo;
- bool validity = FALSE;
-
- if (stat(parentdir, &parentinfo) == -1) {
- if (errno == ENOENT)
- statusline(ALERT, _("Directory '%s' does not exist"), parentdir);
- else
- statusline(ALERT, _("Path '%s': %s"), parentdir, strerror(errno));
- } else if (!S_ISDIR(parentinfo.st_mode))
- statusline(ALERT, _("Path '%s' is not a directory"), parentdir);
- else if (access(parentdir, X_OK) == -1)
- statusline(ALERT, _("Path '%s' is not accessible"), parentdir);
-#ifndef NANO_TINY
- else if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && access(parentdir, W_OK) < 0)
- statusline(MILD, _("Directory '%s' is not writable"), parentdir);
-#endif
- else
- validity = TRUE;
-
- free(namecopy);
-
- return validity;
-}
-
/* Add an item to the circular list of openfile structs. */
void make_new_buffer(void)
{
@@ -362,6 +333,35 @@ void stat_with_alloc(const char *filename, struct stat **pstat)
}
#endif /* !NANO_TINY */
+/* Verify that the containing directory of the given filename exists. */
+bool has_valid_path(const char *filename)
+{
+ char *namecopy = copy_of(filename);
+ char *parentdir = dirname(namecopy);
+ struct stat parentinfo;
+ bool validity = FALSE;
+
+ if (stat(parentdir, &parentinfo) == -1) {
+ if (errno == ENOENT)
+ statusline(ALERT, _("Directory '%s' does not exist"), parentdir);
+ else
+ statusline(ALERT, _("Path '%s': %s"), parentdir, strerror(errno));
+ } else if (!S_ISDIR(parentinfo.st_mode))
+ statusline(ALERT, _("Path '%s' is not a directory"), parentdir);
+ else if (access(parentdir, X_OK) == -1)
+ statusline(ALERT, _("Path '%s' is not accessible"), parentdir);
+#ifndef NANO_TINY
+ else if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && access(parentdir, W_OK) < 0)
+ statusline(MILD, _("Directory '%s' is not writable"), parentdir);
+#endif
+ else
+ validity = TRUE;
+
+ free(namecopy);
+
+ return validity;
+}
+
/* This does one of three things. If the filename is "", it just creates
* a new empty buffer. When the filename is not empty, it reads that file
* into a new buffer when requested, otherwise into the existing buffer. */