X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_utils_file.c;h=cd9c244f0f3d1b799f58063032ba2da959c6e3b5;hb=f3aef1a78eeb80f9234eb39d22965ad1f6e94b5d;hp=a3dab58b36ae5c6d7b08b850ce50edf1f8ebc749;hpb=df4e89bfa61b6aaea41619842aa9032dd1af072e;p=elogind.git 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. */