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 | |
parent | cfd0fc66054cb7eab4989d214e4f8552dc2bf0b8 (diff) |
move delete_path() to utils
-rw-r--r-- | udev_remove.c | 29 | ||||
-rw-r--r-- | udev_utils.h | 1 | ||||
-rw-r--r-- | udev_utils_file.c | 31 |
3 files changed, 32 insertions, 29 deletions
diff --git a/udev_remove.c b/udev_remove.c index 8351860472..6efa17eb7c 100644 --- a/udev_remove.c +++ b/udev_remove.c @@ -34,35 +34,6 @@ #include "udev_version.h" #include "logging.h" -static int delete_path(const char *path) -{ - char *pos; - int retval; - - pos = strrchr(path, '/'); - while (1) { - *pos = '\0'; - pos = strrchr(path, '/'); - - /* don't remove the last one */ - if ((pos == path) || (pos == NULL)) - break; - - /* remove if empty */ - retval = rmdir(path); - if (errno == ENOENT) - retval = 0; - if (retval) { - if (errno == ENOTEMPTY) - return 0; - err("rmdir(%s) failed: %s", path, strerror(errno)); - break; - } - dbg("removed '%s'", path); - } - return 0; -} - static int delete_node(struct udevice *udev) { char filename[PATH_SIZE]; diff --git a/udev_utils.h b/udev_utils.h index ffdaf0469f..a28ba005ca 100644 --- a/udev_utils.h +++ b/udev_utils.h @@ -51,6 +51,7 @@ extern int replace_untrusted_chars(char *str); /* udev_utils_file.c */ extern int create_path(const char *path); +extern int delete_path(const char *path); extern int file_map(const char *filename, char **buf, size_t *bufsize); extern void file_unmap(void *buf, size_t bufsize); extern int unlink_secure(const char *filename); 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. */ |