mirror of
git://git.suckless.org/sbase
synced 2024-12-22 23:13:44 +00:00
Implement -m option for mkdir
This commit is contained in:
parent
36afa1e169
commit
4d014e66fd
4
mkdir.1
4
mkdir.1
@ -3,7 +3,7 @@
|
|||||||
mkdir \- make directory
|
mkdir \- make directory
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B mkdir
|
.B mkdir
|
||||||
.RB [ \-p ]
|
.RB [ \-pm ]
|
||||||
.RI [ name ...]
|
.RI [ name ...]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B mkdir
|
.B mkdir
|
||||||
@ -13,5 +13,7 @@ creates the specified directories.
|
|||||||
.B \-p
|
.B \-p
|
||||||
creates any necessary parent directories, and does not fail if the target
|
creates any necessary parent directories, and does not fail if the target
|
||||||
already exists.
|
already exists.
|
||||||
|
.B \-m
|
||||||
|
set the file permission bits of the newly created directory.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.IR mkdir (2)
|
.IR mkdir (2)
|
||||||
|
12
mkdir.c
12
mkdir.c
@ -1,4 +1,5 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -13,18 +14,24 @@ static void mkdirp(char *);
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-p] directory...\n", argv0);
|
eprintf("usage: %s [-pm] directory...\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
bool pflag = false;
|
bool pflag = false;
|
||||||
|
bool mflag = false;
|
||||||
|
int mode;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'p':
|
case 'p':
|
||||||
pflag = true;
|
pflag = true;
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
mflag = true;
|
||||||
|
mode = estrtol(EARGF(usage()), 10);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
@ -38,6 +45,9 @@ main(int argc, char *argv[])
|
|||||||
} else if(mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
|
} else if(mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
|
||||||
eprintf("mkdir %s:", argv[0]);
|
eprintf("mkdir %s:", argv[0]);
|
||||||
}
|
}
|
||||||
|
if (mflag)
|
||||||
|
if (chmod(argv[0], mode) < 0)
|
||||||
|
eprintf("chmod %s:", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user