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 mkdir
[ [
.B -p .B -p
] [
.B -m
. I mode
] ]
.I dirname ... .I dirname ...
.SH DESCRIPTION .SH DESCRIPTION
@ -19,6 +22,11 @@ flag is given,
.I mkdir .I mkdir
creates any necessary parent directories creates any necessary parent directories
and does not complain if the target directory already exists. 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" .SH "SEE ALSO"
.IR rm (1) .IR rm (1)
.br .br

View file

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