source: MondoRescue/branches/2.2.9/mindi-busybox/coreutils/rmdir.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.6 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * rmdir implementation for busybox
4 *
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9
10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
12
13#include "libbb.h"
14
15/* This is a NOFORK applet. Be very careful! */
16
17
18#define PARENTS 0x01
19#define IGNORE_NON_EMPTY 0x02
20
21int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
22int rmdir_main(int argc UNUSED_PARAM, char **argv)
23{
24 int status = EXIT_SUCCESS;
25 int flags;
26 char *path;
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
37 flags = getopt32(argv, "p");
38 argv += optind;
39
40 if (!*argv) {
41 bb_show_usage();
42 }
43
44 do {
45 path = *argv;
46
47 while (1) {
48 if (rmdir(path) < 0) {
49#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
50 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
51 break;
52#endif
53 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */
54 status = EXIT_FAILURE;
55 } else if (flags & PARENTS) {
56 /* Note: path was not "" since rmdir succeeded. */
57 path = dirname(path);
58 /* Path is now just the parent component. Dirname
59 * returns "." if there are no parents.
60 */
61 if (NOT_LONE_CHAR(path, '.')) {
62 continue;
63 }
64 }
65 break;
66 }
67 } while (*++argv);
68
69 return status;
70}
Note: See TracBrowser for help on using the repository browser.