sbase/mkfifo.c

51 lines
818 B
C
Raw Normal View History

2011-05-25 10:00:15 +00:00
/* See LICENSE file for copyright and license details. */
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
2011-05-25 10:00:15 +00:00
#include "util.h"
2013-06-14 18:20:47 +00:00
static void
usage(void)
{
2013-11-30 20:56:34 +00:00
eprintf("usage: %s [-m mode] name...\n", argv0);
2013-06-14 18:20:47 +00:00
}
2011-05-25 10:00:15 +00:00
int
main(int argc, char *argv[])
{
mode_t mode = 0;
mode_t mask;
int mflag = 0;
int ret = 0;
2013-11-30 20:56:34 +00:00
2013-06-14 18:20:47 +00:00
ARGBEGIN {
2013-11-30 20:56:34 +00:00
case 'm':
mflag = 1;
mask = getumask();
mode = parsemode(EARGF(usage()), mode, mask);
2013-11-30 20:56:34 +00:00
break;
2013-06-14 18:20:47 +00:00
default:
usage();
} ARGEND;
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) < 0) {
weprintf("mkfifo %s:", argv[0]);
ret = 1;
}
if (mflag) {
if (chmod(argv[0], mode) < 0) {
weprintf("chmod %s:", argv[0]);
ret = 1;
}
}
}
return ret;
2011-05-25 10:00:15 +00:00
}