1 /* vi: set sw=4 ts=4: */
3 * rmdir implementation for busybox
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 /* BB_AUDIT SUSv3 compliant */
11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
15 /* This is a NOFORK applet. Be very careful! */
19 #define IGNORE_NON_EMPTY 0x02
21 int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
22 int rmdir_main(int argc UNUSED_PARAM, char **argv)
24 int status = EXIT_SUCCESS;
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"
35 applet_long_options = rmdir_longopts;
37 flags = getopt32(argv, "p");
48 if (rmdir(path) < 0) {
49 #if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
50 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
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. */
58 /* Path is now just the parent component. Dirname
59 * returns "." if there are no parents.
61 if (NOT_LONE_CHAR(path, '.')) {