tweaks: move a function to before the one that calls it

master
Benno Schulenberg 2020-02-10 09:55:21 +01:00
parent 410dcee0a1
commit 3eeedd7caf
1 changed files with 29 additions and 29 deletions

View File

@ -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. */