summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-24 14:56:10 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-24 14:56:10 +0000
commit52feee9b1fc996acb9c2857596bc5c2440644525 (patch)
tree1345002c66b651ddec2739cddc8138e7a3d2c5c9
parent28b29916cbc532fafa1b195e3917fb49ae53bb8e (diff)
downloadbusybox-w32-52feee9b1fc996acb9c2857596bc5c2440644525.tar.gz
busybox-w32-52feee9b1fc996acb9c2857596bc5c2440644525.tar.bz2
busybox-w32-52feee9b1fc996acb9c2857596bc5c2440644525.zip
rmdir: optional long options support for Debian users. +68 bytes.
By Roberto Gordo Saez <roberto.gordo AT gmail.com>
-rw-r--r--coreutils/rmdir.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index 71d29dd98..96bee231b 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -10,20 +10,30 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
12 12
13#include <libgen.h>
14#include "libbb.h" 13#include "libbb.h"
15 14
16/* This is a NOFORK applet. Be very careful! */ 15/* This is a NOFORK applet. Be very careful! */
17 16
18 17
18#define PARENTS 0x01
19#define IGNORE_NON_EMPTY 0x02
20
19int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 21int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
20int rmdir_main(int argc, char **argv) 22int rmdir_main(int argc, char **argv)
21{ 23{
22 int status = EXIT_SUCCESS; 24 int status = EXIT_SUCCESS;
23 int flags; 25 int flags;
24 int do_dot;
25 char *path; 26 char *path;
26 27
28#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
29 static const char rmdir_longopts[] ALIGN1 =
30 "parents\0" No_argument "p"
31 /* Debian etch: many packages fail to be purged or installed
32 * because they desperately want this option: */
33 "ignore-fail-on-non-empty\0" No_argument "\xff"
34 ;
35 applet_long_options = rmdir_longopts;
36#endif
27 flags = getopt32(argv, "p"); 37 flags = getopt32(argv, "p");
28 argv += optind; 38 argv += optind;
29 39
@@ -34,27 +44,26 @@ int rmdir_main(int argc, char **argv)
34 do { 44 do {
35 path = *argv; 45 path = *argv;
36 46
37 /* Record if the first char was a '.' so we can use dirname later. */
38 do_dot = (*path == '.');
39
40 while (1) { 47 while (1) {
41 if (rmdir(path) < 0) { 48 if (rmdir(path) < 0) {
49#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
50 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
51 break;
52#endif
42 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */ 53 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */
43 status = EXIT_FAILURE; 54 status = EXIT_FAILURE;
44 } else if (flags) { 55 } else if (flags & PARENTS) {
45 /* Note: path was not empty or null since rmdir succeeded. */ 56 /* Note: path was not "" since rmdir succeeded. */
46 path = dirname(path); 57 path = dirname(path);
47 /* Path is now just the parent component. Note that dirname 58 /* Path is now just the parent component. Dirname
48 * returns "." if there are no parents. We must distinguish 59 * returns "." if there are no parents.
49 * this from the case of the original path starting with '.'.
50 */ 60 */
51 if (do_dot || (*path != '.') || path[1]) { 61 if (NOT_LONE_CHAR(path, '.')) {
52 continue; 62 continue;
53 } 63 }
54 } 64 }
55 break; 65 break;
56 } 66 }
57
58 } while (*++argv); 67 } while (*++argv);
59 68
60 return status; 69 return status;