[hackers] [sbase] Add full mode support to mkdir(1) and fix return values || FRIGN
commit 2904da3cb2ee38864f1f5e07778491c27353fa88
Author: FRIGN <dev_AT_frign.de>
Date: Wed Jan 28 20:57:32 2015 +0100
Add full mode support to mkdir(1) and fix return values
Same as with mkfifo(1). Also, somehow the return-values were
ignored and it would always return 0 no matter how many errors
happened.
diff --git a/mkdir.c b/mkdir.c
index 095643f..e1380a3 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -29,16 +29,17 @@ mkdirp(char *path)
static void
usage(void)
{
- eprintf("usage: %s [-pm] directory...\n", argv0);
+ eprintf("usage: %s [-p] [-m mode] directory ...\n", argv0);
}
int
main(int argc, char *argv[])
{
- int pflag = 0;
- int mflag = 0;
- int mode;
- int r = 0;
+ mode_t mode = 0;
+ mode_t mask;
+ int pflag = 0;
+ int mflag = 0;
+ int ret = 0;
ARGBEGIN {
case 'p':
_AT_@ -46,7 +47,8 @@ main(int argc, char *argv[])
break;
case 'm':
mflag = 1;
- mode = estrtol(EARGF(usage()), 8);
+ mask = getumask();
+ mode = parsemode(EARGF(usage()), mode, mask);
break;
default:
usage();
_AT_@ -58,18 +60,17 @@ main(int argc, char *argv[])
for (; argc > 0; argc--, argv++) {
if (pflag) {
if (mkdirp(argv[0]) < 0)
- r = 1;
+ ret = 1;
} else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
weprintf("mkdir %s:", argv[0]);
- r = 1;
+ ret = 1;
}
if (mflag) {
if (chmod(argv[0], mode) < 0) {
weprintf("chmod %s:", argv[0]);
- r = 1;
+ ret = 1;
}
}
}
-
- return 0;
+ return ret;
}
Received on Wed Jan 28 2015 - 20:59:48 CET
This archive was generated by hypermail 2.3.0
: Wed Jan 28 2015 - 21:00:10 CET