diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-06-18 21:33:15 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-06-18 21:33:15 +0200 |
commit | c32dd69b46c6311148ed666095a13c5e6173c744 (patch) | |
tree | 1c1c50dc5c6bfb452b4fd54d3cb6193a03d56a49 /src/util.c | |
parent | 4545812fbee75ddbeae7f09cfb461e9b7a93cb84 (diff) |
install: make systemd-install useful for installation of template instances
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 2363ea27b2..78d8d5d9c5 100644 --- a/src/util.c +++ b/src/util.c @@ -893,6 +893,53 @@ int mkdir_p(const char *path, mode_t mode) { return 0; } +int rmdir_parents(const char *path, const char *stop) { + size_t l; + int r = 0; + + assert(path); + assert(stop); + + l = strlen(path); + + /* Skip trailing slashes */ + while (l > 0 && path[l-1] == '/') + l--; + + while (l > 0) { + char *t; + + /* Skip last component */ + while (l > 0 && path[l-1] != '/') + l--; + + /* Skip trailing slashes */ + while (l > 0 && path[l-1] == '/') + l--; + + if (l <= 0) + break; + + if (!(t = strndup(path, l))) + return -ENOMEM; + + if (path_startswith(stop, t)) { + free(t); + return 0; + } + + r = rmdir(t); + free(t); + + if (r < 0) + if (errno != ENOENT) + return -errno; + } + + return 0; +} + + char hexchar(int x) { static const char table[16] = "0123456789abcdef"; |