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.
This commit is contained in:
parent
befec8cf67
commit
9119365c91
19
mkdir.c
19
mkdir.c
@ -29,16 +29,17 @@ mkdirp(char *path)
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-pm] directory...\n", argv0);
|
eprintf("usage: %s [-p] [-m mode] directory ...\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
mode_t mode = 0;
|
||||||
|
mode_t mask;
|
||||||
int pflag = 0;
|
int pflag = 0;
|
||||||
int mflag = 0;
|
int mflag = 0;
|
||||||
int mode;
|
int ret = 0;
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'p':
|
case 'p':
|
||||||
@ -46,7 +47,8 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
mflag = 1;
|
mflag = 1;
|
||||||
mode = estrtol(EARGF(usage()), 8);
|
mask = getumask();
|
||||||
|
mode = parsemode(EARGF(usage()), mode, mask);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -58,18 +60,17 @@ main(int argc, char *argv[])
|
|||||||
for (; argc > 0; argc--, argv++) {
|
for (; argc > 0; argc--, argv++) {
|
||||||
if (pflag) {
|
if (pflag) {
|
||||||
if (mkdirp(argv[0]) < 0)
|
if (mkdirp(argv[0]) < 0)
|
||||||
r = 1;
|
ret = 1;
|
||||||
} else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
|
} else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
|
||||||
weprintf("mkdir %s:", argv[0]);
|
weprintf("mkdir %s:", argv[0]);
|
||||||
r = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
if (mflag) {
|
if (mflag) {
|
||||||
if (chmod(argv[0], mode) < 0) {
|
if (chmod(argv[0], mode) < 0) {
|
||||||
weprintf("chmod %s:", argv[0]);
|
weprintf("chmod %s:", argv[0]);
|
||||||
r = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user