source: MondoRescue/branches/2.2.5/mindi-busybox/coreutils/rmdir.c@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 17 years ago

Update to busybox 1.7.2

File size: 1.3 KB
RevLine 
[821]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 *
[1765]7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
[821]8 */
9
10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
12
13#include <libgen.h>
[1765]14#include "libbb.h"
[821]15
[1765]16/* This is a NOFORK applet. Be very careful! */
17
18
19int rmdir_main(int argc, char **argv);
[821]20int rmdir_main(int argc, char **argv)
21{
22 int status = EXIT_SUCCESS;
23 int flags;
24 int do_dot;
25 char *path;
26
[1765]27 flags = getopt32(argv, "p");
[821]28 argv += optind;
29
30 if (!*argv) {
31 bb_show_usage();
32 }
33
34 do {
35 path = *argv;
36
37 /* Record if the first char was a '.' so we can use dirname later. */
38 do_dot = (*path == '.');
39
[1765]40 while (1) {
[821]41 if (rmdir(path) < 0) {
[1765]42 bb_perror_msg("'%s'", path); /* Match gnu rmdir msg. */
[821]43 status = EXIT_FAILURE;
44 } else if (flags) {
45 /* Note: path was not empty or null since rmdir succeeded. */
46 path = dirname(path);
47 /* Path is now just the parent component. Note that dirname
48 * returns "." if there are no parents. We must distinguish
49 * this from the case of the original path starting with '.'.
[1765]50 */
[821]51 if (do_dot || (*path != '.') || path[1]) {
52 continue;
53 }
54 }
55 break;
[1765]56 }
[821]57
58 } while (*++argv);
59
60 return status;
61}
Note: See TracBrowser for help on using the repository browser.