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, "<1vpm:", 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 
22 #define FOR_mkdir
23 #include "toys.h"
24 
GLOBALS(char * arg_mode;)25 GLOBALS(
26   char *arg_mode;
27 )
28 
29 void mkdir_main(void)
30 {
31   char **s;
32   mode_t mode = (0777&~toys.old_umask);
33 
34 
35   if (TT.arg_mode) mode = string_to_mode(TT.arg_mode, 0777);
36 
37   // Note, -p and -v flags line up with mkpathat() flags
38 
39   for (s=toys.optargs; *s; s++)
40     if (mkpathat(AT_FDCWD, *s, mode, toys.optflags|1))
41       perror_msg("'%s'", *s);
42 }
43