• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:")"vp(parent)(parents)m:", 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 
34 GLOBALS(
35   char *m, *Z;
36 )
37 
mkdir_main(void)38 void mkdir_main(void)
39 {
40   char **s;
41   mode_t mode = (0777&~toys.old_umask);
42 
43   if (CFG_MKDIR_Z && (toys.optflags&FLAG_Z))
44     if (0>lsm_set_create(TT.Z))
45       perror_exit("-Z '%s' failed", TT.Z);
46 
47   if (TT.m) mode = string_to_mode(TT.m, 0777);
48 
49   // Note, -p and -v flags line up with mkpathat() flags
50   for (s=toys.optargs; *s; s++) {
51     if (mkpathat(AT_FDCWD, *s, mode, toys.optflags|MKPATHAT_MKLAST))
52       perror_msg("'%s'", *s);
53   }
54 }
55