aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/mkdir.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-12-18 10:20:16 -0600
committerRob Landley <rob@landley.net>2013-12-18 10:20:16 -0600
commited9eac3967ed88262293aa395744194f8be294b0 (patch)
tree3d5e4ab9ce2cca36218bd8482785fab38188aebc /toys/posix/mkdir.c
parent4f20b9628bff272c504b6bf2c7c71619f7337022 (diff)
downloadtoybox-ed9eac3967ed88262293aa395744194f8be294b0.tar.gz
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
Diffstat (limited to 'toys/posix/mkdir.c')
-rw-r--r--toys/posix/mkdir.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/toys/posix/mkdir.c b/toys/posix/mkdir.c
index 202eaa79..00946389 100644
--- a/toys/posix/mkdir.c
+++ b/toys/posix/mkdir.c
@@ -4,17 +4,18 @@
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html
-USE_MKDIR(NEWTOY(mkdir, "<1pm:", TOYFLAG_BIN|TOYFLAG_UMASK))
+USE_MKDIR(NEWTOY(mkdir, "<1vpm:", TOYFLAG_BIN|TOYFLAG_UMASK))
config MKDIR
bool "mkdir"
default y
help
- usage: mkdir [-p] [-m mode] [dirname...]
+ usage: mkdir [-vp] [-m mode] [dirname...]
Create one or more directories.
+ -m set permissions of directory to mode.
-p make parent directories as needed.
- -m set permissions of directory to mode.
+ -v verbose
*/
#define FOR_mkdir
@@ -55,9 +56,11 @@ static int do_mkdir(char *dir)
if (save == '/') mode |= 0300;
else if (toys.optflags&FLAG_m) mode = TT.mode;
- if (mkdir(dir, mode)<0 && (!(toys.optflags&FLAG_p) || errno != EEXIST))
- return 1;
-
+ if (mkdir(dir, mode)) {
+ if (!(toys.optflags&FLAG_p) || errno != EEXIST) return 1;
+ } else if (toys.optflags&FLAG_v)
+ fprintf(stderr, "%s: created directory '%s'\n", toys.which->name, dir);
+
if (!(*s = save)) break;
}