add -m flag

This commit is contained in:
rsc 2004-04-21 22:37:29 +00:00
parent 53db2d0f6b
commit 24c8d8491f
2 changed files with 20 additions and 2 deletions

View file

@ -5,6 +5,9 @@ mkdir \- make a directory
.B mkdir
[
.B -p
] [
.B -m
. I mode
]
.I dirname ...
.SH DESCRIPTION
@ -19,6 +22,11 @@ flag is given,
.I mkdir
creates any necessary parent directories
and does not complain if the target directory already exists.
.PP
The
.B -m
flag sets the permissions to be used when creating the directory.
The default is 0777.
.SH "SEE ALSO"
.IR rm (1)
.br

View file

@ -2,11 +2,12 @@
#include <libc.h>
char *e;
ulong mode = 0777L;
void
usage(void)
{
fprint(2, "usage: mkdir [-p] dir...\n");
fprint(2, "usage: mkdir [-p] [-m mode] dir...\n");
exits("usage");
}
@ -20,7 +21,7 @@ makedir(char *s)
e = "error";
return -1;
}
f = create(s, OREAD, DMDIR | 0777L);
f = create(s, OREAD, DMDIR | mode);
if(f < 0){
fprint(2, "mkdir: can't create %s: %r\n", s);
e = "error";
@ -50,11 +51,20 @@ void
main(int argc, char *argv[])
{
int i, pflag;
char *m;
pflag = 0;
ARGBEGIN{
default:
usage();
case 'm':
m = ARGF();
if(m == nil)
usage();
mode = strtoul(m, &m, 8);
if(mode > 0777)
usage();
break;
case 'p':
pflag = 1;
break;