X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxmisc.c;h=daa61a0193665909755938231c0d10a84ce703ba;hb=095072fa46b2d7b8beafaddb2f873d2f500a1e10;hp=a7a2fcb93576bf7248a409757458a41fdbe0b827;hpb=009ab4a20cfd685ff20b8f922068ffa6900b92c7;p=PuTTY.git diff --git a/unix/uxmisc.c b/unix/uxmisc.c index a7a2fcb9..daa61a01 100644 --- a/unix/uxmisc.c +++ b/unix/uxmisc.c @@ -322,3 +322,30 @@ 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; + } + + sfree(prefix); + } + + if (!path[pos]) + return NULL; + pos += strspn(path + pos, "/"); + } +}