mkdir.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. USE_MKDIR(NEWTOY(mkdir, "<1"USE_MKDIR_Z("Z:")"vp(parent)(parents)m:", TOYFLAG_BIN|TOYFLAG_UMASK))
  7. config MKDIR
  8. bool "mkdir"
  9. default y
  10. help
  11. usage: mkdir [-vp] [-m MODE] [DIR...]
  12. Create one or more directories.
  13. -m Set permissions of directory to mode
  14. -p Make parent directories as needed
  15. -v Verbose
  16. config MKDIR_Z
  17. bool
  18. default y
  19. depends on MKDIR && !TOYBOX_LSM_NONE
  20. help
  21. usage: [-Z context]
  22. -Z Set security context
  23. */
  24. #define FOR_mkdir
  25. #include "toys.h"
  26. GLOBALS(
  27. char *m, *Z;
  28. )
  29. void mkdir_main(void)
  30. {
  31. char **s;
  32. mode_t mode = (0777&~toys.old_umask);
  33. if (CFG_MKDIR_Z && (toys.optflags&FLAG_Z))
  34. if (0>lsm_set_create(TT.Z))
  35. perror_exit("-Z '%s' failed", TT.Z);
  36. if (TT.m) mode = string_to_mode(TT.m, 0777);
  37. // Note, -p and -v flags line up with mkpathat() flags
  38. for (s=toys.optargs; *s; s++) {
  39. if (mkpathat(AT_FDCWD, *s, mode, toys.optflags|MKPATHAT_MKLAST))
  40. perror_msg("'%s'", *s);
  41. }
  42. }