10f66f451Sopenharmony_ci/* mkdir.c - Make directories
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
40f66f451Sopenharmony_ci *
50f66f451Sopenharmony_ci * See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ciUSE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vp(parent)(parents)m:", TOYFLAG_BIN|TOYFLAG_UMASK))
80f66f451Sopenharmony_ci
90f66f451Sopenharmony_ciconfig MKDIR
100f66f451Sopenharmony_ci  bool "mkdir"
110f66f451Sopenharmony_ci  default y
120f66f451Sopenharmony_ci  help
130f66f451Sopenharmony_ci    usage: mkdir [-vp] [-m mode] [dirname...]
140f66f451Sopenharmony_ci
150f66f451Sopenharmony_ci    Create one or more directories.
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_ci    -m	Set permissions of directory to mode
180f66f451Sopenharmony_ci    -p	Make parent directories as needed
190f66f451Sopenharmony_ci    -v	Verbose
200f66f451Sopenharmony_ci
210f66f451Sopenharmony_ciconfig MKDIR_Z
220f66f451Sopenharmony_ci  bool
230f66f451Sopenharmony_ci  default y
240f66f451Sopenharmony_ci  depends on MKDIR && !TOYBOX_LSM_NONE
250f66f451Sopenharmony_ci  help
260f66f451Sopenharmony_ci    usage: [-Z context]
270f66f451Sopenharmony_ci
280f66f451Sopenharmony_ci    -Z	Set security context
290f66f451Sopenharmony_ci*/
300f66f451Sopenharmony_ci
310f66f451Sopenharmony_ci#define FOR_mkdir
320f66f451Sopenharmony_ci#include "toys.h"
330f66f451Sopenharmony_ci
340f66f451Sopenharmony_ciGLOBALS(
350f66f451Sopenharmony_ci  char *m, *Z;
360f66f451Sopenharmony_ci)
370f66f451Sopenharmony_ci
380f66f451Sopenharmony_civoid mkdir_main(void)
390f66f451Sopenharmony_ci{
400f66f451Sopenharmony_ci  char **s;
410f66f451Sopenharmony_ci  mode_t mode = (0777&~toys.old_umask);
420f66f451Sopenharmony_ci
430f66f451Sopenharmony_ci  if (CFG_MKDIR_Z && (toys.optflags&FLAG_Z))
440f66f451Sopenharmony_ci    if (0>lsm_set_create(TT.Z))
450f66f451Sopenharmony_ci      perror_exit("-Z '%s' failed", TT.Z);
460f66f451Sopenharmony_ci
470f66f451Sopenharmony_ci  if (TT.m) mode = string_to_mode(TT.m, 0777);
480f66f451Sopenharmony_ci
490f66f451Sopenharmony_ci  // Note, -p and -v flags line up with mkpathat() flags
500f66f451Sopenharmony_ci  for (s=toys.optargs; *s; s++) {
510f66f451Sopenharmony_ci    if (mkpathat(AT_FDCWD, *s, mode, toys.optflags|MKPATHAT_MKLAST))
520f66f451Sopenharmony_ci      perror_msg("'%s'", *s);
530f66f451Sopenharmony_ci  }
540f66f451Sopenharmony_ci}
55