aboutsummaryrefslogtreecommitdiff
path: root/toys/mkfifo.c
blob: 77cb73eeeca1d559854f81c14f0886408a71e055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* vi: set sw=4 ts=4:
 *
 * mkfifo.c: Create a named pipe.
 *
 * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html

config MKFIFO
	bool "mkfifo"
	default y
	help
	  usage: mkfifo [-m mode] name...

	  Makes a named pipe at name.

	  -m mode	The mode of the pipe(s) created by mkfifo. It defaults
			to 0644.  This number is in octal, optionally preceded
			by a leading zero.
*/

#include "toys.h"

void mkfifo_main(void)
{
	char *arg;
	int i;
	mode_t mode;

	if (toys.optflags) {
		char *end;
		mode = (mode_t)strtol(toy.mkfifo.mode, &end, 8);
		if (end<=toy.mkfifo.mode || *end || mode<0 || mode>0777)
			error_exit("Invalid mode");
	} else mode = 0644;

	umask(0);
	for (i = 0; (arg = toys.optargs[i]); i++)
		if (mkfifo(arg, mode))
			perror_exit(arg);
}