diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-03-02 01:18:02 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-03-02 01:18:02 +0000 |
commit | e80a7f6447e6b1bf3ec44df83d86eeab6390ea3c (patch) | |
tree | f6b01ed1225a0553226dee2583d58ef80bd8e47c /libq | |
parent | make sure ROOT works properly (diff) | |
download | portage-utils-e80a7f6447e6b1bf3ec44df83d86eeab6390ea3c.tar.gz portage-utils-e80a7f6447e6b1bf3ec44df83d86eeab6390ea3c.tar.bz2 portage-utils-e80a7f6447e6b1bf3ec44df83d86eeab6390ea3c.zip |
optimize a bit, and make sure we dont need a trailing slash for the last dir component
Diffstat (limited to 'libq')
-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 9cb12274..a82edd04 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'; |