[hackers] [sbase] Add p-flag to rmdir(1) || FRIGN

From: <git_AT_suckless.org>
Date: Fri, 30 Jan 2015 12:50:58 +0100 (CET)

commit 8cafdd9cb9315caca1030f41e0457b884df24646
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 Fri Jan 30 2015 - 12:50:58 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 30 2015 - 13:00:11 CET