Implement -m for mkfifo(1)

This commit is contained in:
sin 2013-11-30 20:56:34 +00:00
parent 651dbdd700
commit 7808f4161d
2 changed files with 18 additions and 7 deletions

View File

@ -3,9 +3,17 @@
mkfifo \- make named pipe mkfifo \- make named pipe
.SH SYNOPSIS .SH SYNOPSIS
.B mkfifo .B mkfifo
.RI [ name ...] .RB [ \-m
.IR mode ]
.I name ...
.SH DESCRIPTION .SH DESCRIPTION
.B mkfifo .B mkfifo
creates named pipes (FIFOs) with the given names. creates named pipes (FIFOs) with the given names.
.SH OPTIONS
.TP
.B \-m
Set the file permission bits of newly created FIFOs to mode. The mode
is specified in octal as we do not currently support all the formats that
the chmod(1) utility supports.
.SH SEE ALSO .SH SEE ALSO
.IR mkfifo (3) .IR mkfifo (3)

View File

@ -8,13 +8,19 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s name...\n", argv0); eprintf("usage: %s [-m mode] name...\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP |
S_IWGRP | S_IROTH | S_IWOTH;
ARGBEGIN { ARGBEGIN {
case 'm':
mode = estrtol(EARGF(usage()), 8);
break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;
@ -22,12 +28,9 @@ main(int argc, char *argv[])
if (argc < 1) if (argc < 1)
usage(); usage();
for(; argc > 0; argc--, argv++) { for(; argc > 0; argc--, argv++)
if(mkfifo(argv[0], S_IRUSR|S_IWUSR|S_IRGRP|\ if(mkfifo(argv[0], mode) == -1)
S_IWGRP|S_IROTH|S_IWOTH) == -1) {
eprintf("mkfifo %s:", argv[0]); eprintf("mkfifo %s:", argv[0]);
}
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }