diff options
Diffstat (limited to 'libq/xmkdir.c')
-rw-r--r-- | libq/xmkdir.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libq/xmkdir.c b/libq/xmkdir.c index 9cb1227..a82edd0 100644 --- a/libq/xmkdir.c +++ b/libq/xmkdir.c @@ -3,17 +3,25 @@ static int mkdir_p(const char *path, mode_t mode) { char *_p, *p, *s; + /* Assume that most of the time, only the last element + * is missing. So if we can mkdir it right away, bail. */ + if (mkdir(path, mode) == 0 || errno == EEXIST) + return 0; + + /* Build up the whole tree */ _p = p = xstrdup(path); - while (1) { + while (*p) { /* Skip duplicate slashes */ while (*p == '/') ++p; /* Find the next path element */ s = strchr(p, '/'); - if (!s) + if (!s) { + mkdir(_p, mode); break; + } /* Make it */ *s = '\0'; |