[hackers] [sbase] Add p-flag to rmdir(1) || FRIGN
commit ae0df49f243b4103477863dc7e54afab2a521491
Author: FRIGN <dev_AT_frign.de>
Date: Fri Jan 30 12:21:26 2015 +0100
Add p-flag to rmdir(1)
diff --git a/rmdir.c b/rmdir.c
index 4338c0b..743db34 100644
--- a/rmdir.c
+++ b/rmdir.c
_AT_@ -1,6 +1,8 @@
/* See LICENSE file for copyright and license details. */
+#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "util.h"
_AT_@ -8,13 +10,19 @@
static void
usage(void)
{
- eprintf("usage: rmdir dir...\n");
+ eprintf("usage: rmdir [-p] dir ...\n");
}
int
main(int argc, char *argv[])
{
+ int pflag = 0;
+ char *d;
+
ARGBEGIN {
+ case 'p':
+ pflag = 1;
+ break;
default:
usage();
} ARGEND;
_AT_@ -22,8 +30,20 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
- for (; argc > 0; argc--, argv++)
- if (rmdir(argv[0]) < 0)
+ for (; argc > 0; argc--, argv++) {
+ if (rmdir(argv[0]) < 0) {
weprintf("rmdir %s:", argv[0]);
+ if (pflag)
+ return 1;
+ }
+ if (pflag) {
+ d = dirname(argv[0]);
+ for (; strcmp(d, "/") && strcmp(d, ".") ;) {
+ if (rmdir(d) < 0)
+ eprintf("rmdir %s:", d);
+ d = dirname(d);
+ }
+ }
+ }
return 0;
}
Received on Tue Mar 24 2015 - 23:53:21 CET
This archive was generated by hypermail 2.3.0
: Wed Mar 25 2015 - 00:04:25 CET