1 /* vi: set sw=4 ts=4: */
3 * Mini mkdir implementation for busybox
5 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
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/mkdir.html */
13 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
15 * Fixed broken permission setting when -p was used; especially in
16 * conjunction with -m.
19 /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
24 /* This is a NOFORK applet. Be very careful! */
26 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
27 static const char mkdir_longopts[] ALIGN1 =
28 "mode\0" Required_argument "m"
29 "parents\0" No_argument "p"
31 "context\0" Required_argument "Z"
36 int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37 int mkdir_main(int argc, char **argv)
39 mode_t mode = (mode_t)(-1);
40 int status = EXIT_SUCCESS;
45 security_context_t scontext;
48 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
49 applet_long_options = mkdir_longopts;
51 opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
54 if (!bb_parse_mode(smode, &mode)) {
55 bb_error_msg_and_die("invalid mode '%s'", smode);
59 flags |= FILEUTILS_RECUR;
63 setfscreatecon_or_die(scontext);
74 if (bb_make_directory(*argv, mode, flags)) {
75 status = EXIT_FAILURE;