Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/coreutils/rmdir.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1303 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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