summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rmdir.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/rmdir.c b/rmdir.c
index c4ee227..8ad3f02 100644
--- a/rmdir.c
+++ b/rmdir.c
@@ -32,22 +32,18 @@
static int rm_dir(char *path, int prune)
{
- if (prune) {
- char *working = path;
- while (strcmp(working, ".") && strcmp(working, "/")) {
- if (rmdir(working) != 0) {
- fprintf(stderr, "rmdir: %s: %s\n",
- working, strerror(errno));
- return 1;
- }
- working = dirname(working);
- }
-
- } else if (rmdir(path) != 0) {
+ if (rmdir(path) != 0) {
fprintf(stderr, "rmdir: %s: %s\n", path, strerror(errno));
return 1;
}
+ if (prune) {
+ char *parent = dirname(path);
+ if (strcmp(parent, ".") && strcmp(parent, "/")) {
+ return rm_dir(parent, prune);
+ }
+ }
+
return 0;
}