mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
add -m flag
This commit is contained in:
parent
53db2d0f6b
commit
24c8d8491f
2 changed files with 20 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue