[hackers] [sbase] Implement -m for mkfifo(1) || sin
commit 7808f4161d65a45c7e8d7c81bf4683b925c6564d
Author: sin <sin_AT_2f30.org>
Date: Sat Nov 30 20:56:34 2013 +0000
Implement -m for mkfifo(1)
diff --git a/mkfifo.1 b/mkfifo.1
index 8ff8da3..0f60d87 100644
--- a/mkfifo.1
+++ b/mkfifo.1
_AT_@ -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
index 24015fe..3f2d618 100644
--- a/mkfifo.c
+++ b/mkfifo.c
_AT_@ -8,13 +8,19 @@
static void
usage(void)
{
- eprintf("usage: %s name...
", argv0);
+ eprintf("usage: %s [-m mode] name...
", 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;
_AT_@ -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;
}
Received on Sat Nov 30 2013 - 21:58:38 CET
This archive was generated by hypermail 2.3.0
: Sat Nov 30 2013 - 22:00:14 CET