source: MondoRescue/branches/3.3/mindi-busybox/coreutils/mkdir.c@ 3667

Last change on this file since 3667 was 3621, checked in by Bruno Cornec, 7 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 2.5 KB
RevLine 
[821]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 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]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
[1765]19/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
20 */
21
[3232]22//usage:#define mkdir_trivial_usage
23//usage: "[OPTIONS] DIRECTORY..."
24//usage:#define mkdir_full_usage "\n\n"
25//usage: "Create DIRECTORY\n"
26//usage: "\n -m MODE Mode"
27//usage: "\n -p No error if exists; make parent directories as needed"
28//usage: IF_SELINUX(
29//usage: "\n -Z Set security context"
30//usage: )
31//usage:
32//usage:#define mkdir_example_usage
33//usage: "$ mkdir /tmp/foo\n"
34//usage: "$ mkdir /tmp/foo\n"
35//usage: "/tmp/foo: File exists\n"
36//usage: "$ mkdir /tmp/foo/bar/baz\n"
37//usage: "/tmp/foo/bar/baz: No such file or directory\n"
38//usage: "$ mkdir -p /tmp/foo/bar/baz\n"
39
[1765]40#include "libbb.h"
[821]41
[1765]42/* This is a NOFORK applet. Be very careful! */
43
[821]44#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
[1765]45static const char mkdir_longopts[] ALIGN1 =
46 "mode\0" Required_argument "m"
47 "parents\0" No_argument "p"
48#if ENABLE_SELINUX
49 "context\0" Required_argument "Z"
[821]50#endif
[3621]51#if ENABLE_FEATURE_VERBOSE
[3232]52 "verbose\0" No_argument "v"
[3621]53#endif
[1765]54 ;
55#endif
[821]56
[2725]57int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
58int mkdir_main(int argc UNUSED_PARAM, char **argv)
[821]59{
[3232]60 long mode = -1;
[821]61 int status = EXIT_SUCCESS;
62 int flags = 0;
[1765]63 unsigned opt;
[821]64 char *smode;
[1765]65#if ENABLE_SELINUX
66 security_context_t scontext;
67#endif
[821]68
69#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
[1765]70 applet_long_options = mkdir_longopts;
[821]71#endif
[3621]72 opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
[1765]73 if (opt & 1) {
[3621]74 mode_t mmode = bb_parse_mode(smode, 0777);
75 if (mmode == (mode_t)-1) {
[1765]76 bb_error_msg_and_die("invalid mode '%s'", smode);
[821]77 }
[3232]78 mode = mmode;
[821]79 }
[1765]80 if (opt & 2)
[821]81 flags |= FILEUTILS_RECUR;
[3621]82 if ((opt & 4) && FILEUTILS_VERBOSE)
83 flags |= FILEUTILS_VERBOSE;
[1765]84#if ENABLE_SELINUX
[3621]85 if (opt & 8) {
[1765]86 selinux_or_die();
87 setfscreatecon_or_die(scontext);
88 }
89#endif
[821]90
[2725]91 argv += optind;
92 if (!argv[0])
[821]93 bb_show_usage();
94
95 do {
96 if (bb_make_directory(*argv, mode, flags)) {
97 status = EXIT_FAILURE;
98 }
99 } while (*++argv);
100
101 return status;
102}
Note: See TracBrowser for help on using the repository browser.