source: MondoRescue/branches/2.2.9/mindi-busybox/coreutils/mkdir.c@ 2859

Last change on this file since 2859 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.7 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
22#include "libbb.h"
[821]23
[1765]24/* This is a NOFORK applet. Be very careful! */
25
[821]26#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
[1765]27static const char mkdir_longopts[] ALIGN1 =
28 "mode\0" Required_argument "m"
29 "parents\0" No_argument "p"
30#if ENABLE_SELINUX
31 "context\0" Required_argument "Z"
[821]32#endif
[1765]33 ;
34#endif
[821]35
[2725]36int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int mkdir_main(int argc UNUSED_PARAM, char **argv)
[821]38{
39 mode_t mode = (mode_t)(-1);
40 int status = EXIT_SUCCESS;
41 int flags = 0;
[1765]42 unsigned opt;
[821]43 char *smode;
[1765]44#if ENABLE_SELINUX
45 security_context_t scontext;
46#endif
[821]47
48#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
[1765]49 applet_long_options = mkdir_longopts;
[821]50#endif
[2725]51 opt = getopt32(argv, "m:p" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
[1765]52 if (opt & 1) {
53 mode = 0777;
54 if (!bb_parse_mode(smode, &mode)) {
55 bb_error_msg_and_die("invalid mode '%s'", smode);
[821]56 }
57 }
[1765]58 if (opt & 2)
[821]59 flags |= FILEUTILS_RECUR;
[1765]60#if ENABLE_SELINUX
61 if (opt & 4) {
62 selinux_or_die();
63 setfscreatecon_or_die(scontext);
64 }
65#endif
[821]66
[2725]67 argv += optind;
68 if (!argv[0])
[821]69 bb_show_usage();
70
71 do {
72 if (bb_make_directory(*argv, mode, flags)) {
73 status = EXIT_FAILURE;
74 }
75 } while (*++argv);
76
77 return status;
78}
Note: See TracBrowser for help on using the repository browser.