mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
New Unix utility function to make a directory path.
Essentially 'mkdir -p' - we try to make each prefix of the pathname, terminating on any error other than EEXIST. Semantics are similar to make_dir_and_check_ours(): we return NULL on success or a dynamically allocated error message string on failure.
This commit is contained in:
parent
9398d23033
commit
23a02f429c
@ -11,6 +11,7 @@
|
||||
#include <dlfcn.h> /* Dynamic library loading */
|
||||
#endif /* NO_LIBDL */
|
||||
#include "charset.h"
|
||||
#include <sys/types.h> /* for mode_t */
|
||||
|
||||
#ifdef OSX_GTK
|
||||
/*
|
||||
@ -197,6 +198,7 @@ void noncloexec(int);
|
||||
int nonblock(int);
|
||||
int no_nonblock(int);
|
||||
char *make_dir_and_check_ours(const char *dirname);
|
||||
char *make_dir_path(const char *path, mode_t mode);
|
||||
|
||||
/*
|
||||
* Exports from unicode.c.
|
||||
|
@ -322,3 +322,28 @@ char *make_dir_and_check_ours(const char *dirname)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *make_dir_path(const char *path, mode_t mode)
|
||||
{
|
||||
int pos = 0;
|
||||
char *prefix;
|
||||
|
||||
while (1) {
|
||||
pos += strcspn(path + pos, "/");
|
||||
|
||||
if (pos > 0) {
|
||||
prefix = dupprintf("%.*s", pos, path);
|
||||
|
||||
if (mkdir(prefix, mode) < 0 && errno != EEXIST) {
|
||||
char *ret = dupprintf("%s: mkdir: %s",
|
||||
prefix, strerror(errno));
|
||||
sfree(prefix);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (!path[pos])
|
||||
return NULL;
|
||||
pos += strspn(path + pos, "/");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user