diff options
author | Matt Kraai <kraai@debian.org> | 2001-08-29 21:18:47 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-08-29 21:18:47 +0000 |
commit | 1350666498752664a5e772ed99de3e541c04c477 (patch) | |
tree | 8cd1e8ef9238cef1cf0ba71c9778237b554d02c9 /coreutils | |
parent | 5171bf6d40b6b6c0b31e068aec15d14071e3e176 (diff) | |
download | busybox-w32-1350666498752664a5e772ed99de3e541c04c477.tar.gz busybox-w32-1350666498752664a5e772ed99de3e541c04c477.tar.bz2 busybox-w32-1350666498752664a5e772ed99de3e541c04c477.zip |
Add -p support.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/rmdir.c | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c index 2c280376f..cac27cac9 100644 --- a/coreutils/rmdir.c +++ b/coreutils/rmdir.c | |||
@@ -22,24 +22,76 @@ | |||
22 | * | 22 | * |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <stdio.h> | 25 | #include <getopt.h> |
26 | #include <errno.h> | ||
27 | #include <unistd.h> | 26 | #include <unistd.h> |
28 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | |||
29 | #include "busybox.h" | 29 | #include "busybox.h" |
30 | 30 | ||
31 | extern int rmdir_main(int argc, char **argv) | 31 | |
32 | /* Return true if a path is composed of multiple components. */ | ||
33 | |||
34 | static int | ||
35 | multiple_components_p (const char *path) | ||
36 | { | ||
37 | const char *s = path; | ||
38 | |||
39 | while (s[0] != '\0' && s[0] != '/') | ||
40 | s++; | ||
41 | |||
42 | while (s[0] == '/') | ||
43 | s++; | ||
44 | |||
45 | return (s[0] != '\0'); | ||
46 | } | ||
47 | |||
48 | |||
49 | /* Remove a directory. Returns 0 if successful, -1 on error. */ | ||
50 | |||
51 | static int | ||
52 | remove_directory (char *path, int flags) | ||
53 | { | ||
54 | if (!(flags & FILEUTILS_RECUR)) { | ||
55 | if (rmdir (path) < 0) { | ||
56 | perror_msg ("unable to remove `%s'", path); | ||
57 | return -1; | ||
58 | } | ||
59 | } else { | ||
60 | if (remove_directory (path, 0) < 0) | ||
61 | return -1; | ||
62 | |||
63 | if (multiple_components_p (path)) | ||
64 | if (remove_directory (dirname (path), flags) < 0) | ||
65 | return -1; | ||
66 | } | ||
67 | |||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | |||
72 | extern int | ||
73 | rmdir_main (int argc, char **argv) | ||
32 | { | 74 | { |
33 | int status = EXIT_SUCCESS; | 75 | int status = EXIT_SUCCESS; |
76 | int flags = 0; | ||
77 | int i, opt; | ||
34 | 78 | ||
35 | if (argc == 1 || **(argv + 1) == '-') | 79 | while ((opt = getopt (argc, argv, "p")) != -1) |
80 | switch (opt) { | ||
81 | case 'p': | ||
82 | flags |= FILEUTILS_RECUR; | ||
83 | break; | ||
84 | |||
85 | default: | ||
86 | show_usage (); | ||
87 | } | ||
88 | |||
89 | if (optind == argc) | ||
36 | show_usage(); | 90 | show_usage(); |
37 | 91 | ||
38 | while (--argc > 0) { | 92 | for (i = optind; i < argc; i++) |
39 | if (rmdir(*(++argv)) == -1) { | 93 | if (remove_directory (argv[i], flags) < 0) |
40 | perror_msg("%s", *argv); | ||
41 | status = EXIT_FAILURE; | 94 | status = EXIT_FAILURE; |
42 | } | 95 | |
43 | } | ||
44 | return status; | 96 | return status; |
45 | } | 97 | } |