1 /* mkdir.c - Make directories
2  *
3  * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
4  *
5  * See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html
6 
7 USE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vpm:", TOYFLAG_BIN|TOYFLAG_UMASK))
8 
9 config MKDIR
10   bool "mkdir"
11   default y
12   help
13     usage: mkdir [-vp] [-m mode] [dirname...]
14 
15     Create one or more directories.
16 
17     -m	set permissions of directory to mode.
18     -p	make parent directories as needed.
19     -v	verbose
20 
21 config MKDIR_Z
22   bool
23   default y
24   depends on MKDIR && !TOYBOX_LSM_NONE
25   help
26     usage: [-Z context]
27 
28     -Z	set security context
29 */
30 
31 #define FOR_mkdir
32 #include "toys.h"
33 
GLOBALS(char * arg_mode;char * arg_context;)34 GLOBALS(
35   char *arg_mode;
36   char *arg_context;
37 )
38 
39 void mkdir_main(void)
40 {
41   char **s;
42   mode_t mode = (0777&~toys.old_umask);
43 
44   if (CFG_MKDIR_Z && (toys.optflags&FLAG_Z))
45     if (0>lsm_set_create(TT.arg_context))
46       perror_exit("-Z '%s' failed", TT.arg_context);
47 
48   if (TT.arg_mode) mode = string_to_mode(TT.arg_mode, 0777);
49 
50   // Note, -p and -v flags line up with mkpathat() flags
51   for (s=toys.optargs; *s; s++) {
52     if (mkpathat(AT_FDCWD, *s, mode, toys.optflags|1))
53       perror_msg("'%s'", *s);
54   }
55 }
56