Mercurial > hg > toybox
annotate toys/posix/mkdir.c @ 1776:7bf68329eb3b draft default tip
Repository switched to git at https://github.com/landley/toybox
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Apr 2015 02:28:32 -0500 |
parents | fc1bb49e58a9 |
children |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
1 /* mkdir.c - Make directories |
526 | 2 * |
3 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> | |
4 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html |
526 | 6 |
1143
2115856395e2
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
Rob Landley <rob@landley.net>
parents:
1047
diff
changeset
|
7 USE_MKDIR(NEWTOY(mkdir, "<1vpm:", TOYFLAG_BIN|TOYFLAG_UMASK)) |
526 | 8 |
9 config MKDIR | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
10 bool "mkdir" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
11 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
12 help |
1143
2115856395e2
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
Rob Landley <rob@landley.net>
parents:
1047
diff
changeset
|
13 usage: mkdir [-vp] [-m mode] [dirname...] |
1333
fc1bb49e58a9
Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
14 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
15 Create one or more directories. |
526 | 16 |
1143
2115856395e2
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
Rob Landley <rob@landley.net>
parents:
1047
diff
changeset
|
17 -m set permissions of directory to mode. |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
18 -p make parent directories as needed. |
1143
2115856395e2
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
Rob Landley <rob@landley.net>
parents:
1047
diff
changeset
|
19 -v verbose |
526 | 20 */ |
21 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
22 #define FOR_mkdir |
526 | 23 #include "toys.h" |
24 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
25 GLOBALS( |
763 | 26 char *arg_mode; |
527
a3116cb7ba1e
mkdir cleanups: Let umask do its thing at the syscall level, have mode be a global to prepare for -m, use do_blah name loopfiles() usually calls, one less redundant mkdir() call, go ahead and modify writeable args instead of strdup(), return before restoring / so error message is better, use perror_msg().
Rob Landley <rob@landley.net>
parents:
526
diff
changeset
|
27 ) |
526 | 28 |
29 void mkdir_main(void) | |
30 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
31 char **s; |
1217 | 32 mode_t mode = (0777&~toys.old_umask); |
527
a3116cb7ba1e
mkdir cleanups: Let umask do its thing at the syscall level, have mode be a global to prepare for -m, use do_blah name loopfiles() usually calls, one less redundant mkdir() call, go ahead and modify writeable args instead of strdup(), return before restoring / so error message is better, use perror_msg().
Rob Landley <rob@landley.net>
parents:
526
diff
changeset
|
33 |
1217 | 34 |
35 if (TT.arg_mode) mode = string_to_mode(TT.arg_mode, 0777); | |
526 | 36 |
1217 | 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); | |
526 | 42 } |