diff options
author | Scott James Remnant <scott@ubuntu.com> | 2005-11-22 15:44:02 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-11-22 15:44:02 +0100 |
commit | 0da0efb2b622435209d183b49e2d16d426142b2c (patch) | |
tree | 189196a8ece9de51fd6589ad4c54db4d86bb5205 /udev_utils_file.c | |
parent | cfd0fc66054cb7eab4989d214e4f8552dc2bf0b8 (diff) |
move delete_path() to utils
Diffstat (limited to 'udev_utils_file.c')
-rw-r--r-- | udev_utils_file.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/udev_utils_file.c b/udev_utils_file.c index a3dab58b36..cd9c244f0f 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -63,6 +63,37 @@ int create_path(const char *path) return mkdir(p, 0755); } +int delete_path(const char *path) +{ + char p[PATH_SIZE]; + char *pos; + int retval; + + strcpy (p, path); + pos = strrchr(p, '/'); + while (1) { + *pos = '\0'; + pos = strrchr(p, '/'); + + /* don't remove the last one */ + if ((pos == p) || (pos == NULL)) + break; + + /* remove if empty */ + retval = rmdir(p); + if (errno == ENOENT) + retval = 0; + if (retval) { + if (errno == ENOTEMPTY) + return 0; + err("rmdir(%s) failed: %s", p, strerror(errno)); + break; + } + dbg("removed '%s'", p); + } + return 0; +} + /* Reset permissions on the device node, before unlinking it to make sure, * that permisions of possible hard links will be removed too. */ |