Mercurial > hg > toybox
comparison toys/mkfifo.c @ 157:714f4c051594
Add initial mkfifo implementation
author | Charlie Shepherd <masterdriverz@gentoo.org> |
---|---|
date | Wed, 07 Nov 2007 00:11:20 +0000 |
parents | |
children | 14fa82969ea3 |
comparison
equal
deleted
inserted
replaced
156:1e8f4b05cb65 | 157:714f4c051594 |
---|---|
1 /* vi: set sw=4 ts=4: */ | |
2 /* | |
3 * mkfifo.c: Create a named pipe. | |
4 */ | |
5 | |
6 #include "toys.h" | |
7 | |
8 int mkfifo_main(void) | |
9 { | |
10 char *arg; | |
11 int i; | |
12 mode_t mode; | |
13 | |
14 if (toys.optflags) { | |
15 long temp; | |
16 char *end; | |
17 int len = strlen(toy.mkfifo.mode); | |
18 temp = strtol(toy.mkfifo.mode, &end, 8); | |
19 switch (temp) { | |
20 case LONG_MAX: | |
21 case LONG_MIN: | |
22 case 0: | |
23 if (!errno) | |
24 break; | |
25 error_exit("Invalid mode"); | |
26 } | |
27 if (temp > 0777 || *end || len < 3 || len > 4) | |
28 error_exit("Invalid mode"); | |
29 mode = (mode_t)temp; | |
30 } else { | |
31 mode = 0644; | |
32 } | |
33 | |
34 for (i = 0; (arg = toys.optargs[i]); i++) | |
35 if (mkfifo(arg, mode)) | |
36 perror_exit(arg); | |
37 | |
38 return 0; | |
39 } |