suppress warnings about easch <applet>_main() having
[oweals/busybox.git] / coreutils / mkdir.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini mkdir implementation for busybox
4  *
5  * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
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/mkdir.html */
12
13 /* Mar 16, 2003      Manuel Novoa III   (mjn3@codepoet.org)
14  *
15  * Fixed broken permission setting when -p was used; especially in
16  * conjunction with -m.
17  */
18
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <getopt.h> /* struct option */
22 #include "busybox.h"
23
24 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
25 static const struct option mkdir_long_options[] = {
26         { "mode", 1, NULL, 'm' },
27         { "parents", 0, NULL, 'p' },
28         { 0, 0, 0, 0 }
29 };
30 #endif
31
32 int mkdir_main(int argc, char **argv);
33 int mkdir_main(int argc, char **argv)
34 {
35         mode_t mode = (mode_t)(-1);
36         int status = EXIT_SUCCESS;
37         int flags = 0;
38         unsigned opt;
39         char *smode;
40
41 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
42         applet_long_options = mkdir_long_options;
43 #endif
44         opt = getopt32(argc, argv, "m:p", &smode);
45         if (opt & 1) {
46                 mode = 0777;
47                 if (!bb_parse_mode(smode, &mode)) {
48                         bb_error_msg_and_die("invalid mode '%s'", smode);
49                 }
50         }
51         if (opt & 2)
52                 flags |= FILEUTILS_RECUR;
53
54         if (optind == argc) {
55                 bb_show_usage();
56         }
57
58         argv += optind;
59
60         do {
61                 if (bb_make_directory(*argv, mode, flags)) {
62                         status = EXIT_FAILURE;
63                 }
64         } while (*++argv);
65
66         return status;
67 }