X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_utils_file.c;h=cd9c244f0f3d1b799f58063032ba2da959c6e3b5;hp=a3dab58b36ae5c6d7b08b850ce50edf1f8ebc749;hb=0da0efb2b622435209d183b49e2d16d426142b2c;hpb=cfd0fc66054cb7eab4989d214e4f8552dc2bf0b8 diff --git a/udev_utils_file.c b/udev_utils_file.c index a3dab58b3..cd9c244f0 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. */