sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 7808f4161d65a45c7e8d7c81bf4683b925c6564d
parent 651dbdd700baa85354aaa7265c0e8850ff405c48
Author: sin <sin@2f30.org>
Date:   Sat, 30 Nov 2013 20:56:34 +0000

Implement -m for mkfifo(1)

Diffstat:
Mmkfifo.1 | 10+++++++++-
Mmkfifo.c | 15+++++++++------
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/mkfifo.1 b/mkfifo.1 @@ -3,9 +3,17 @@ mkfifo \- make named pipe .SH SYNOPSIS .B mkfifo -.RI [ name ...] +.RB [ \-m +.IR mode ] +.I name ... .SH DESCRIPTION .B mkfifo 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 .IR mkfifo (3) diff --git a/mkfifo.c b/mkfifo.c @@ -8,13 +8,19 @@ static void usage(void) { - eprintf("usage: %s name...\n", argv0); + eprintf("usage: %s [-m mode] name...\n", argv0); } int main(int argc, char *argv[]) { + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | + S_IWGRP | S_IROTH | S_IWOTH; + ARGBEGIN { + case 'm': + mode = estrtol(EARGF(usage()), 8); + break; default: usage(); } ARGEND; @@ -22,12 +28,9 @@ main(int argc, char *argv[]) if (argc < 1) usage(); - for(; argc > 0; argc--, argv++) { - if(mkfifo(argv[0], S_IRUSR|S_IWUSR|S_IRGRP|\ - S_IWGRP|S_IROTH|S_IWOTH) == -1) { + for(; argc > 0; argc--, argv++) + if(mkfifo(argv[0], mode) == -1) eprintf("mkfifo %s:", argv[0]); - } - } return EXIT_SUCCESS; }