Mercurial > hg > toybox
annotate toys/mkfifo.c @ 322:fa0a95ae4303
Second attempt at making netcat -l work properly.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 16 Nov 2008 01:57:06 -0600 |
parents | 951110c37fee |
children |
rev | line source |
---|---|
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
2 * |
157
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
3 * mkfifo.c: Create a named pipe. |
168
14fa82969ea3
Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents:
157
diff
changeset
|
4 * |
14fa82969ea3
Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents:
157
diff
changeset
|
5 * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
6 |
257 | 7 USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN|TOYFLAG_UMASK)) |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
8 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
9 config MKFIFO |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
10 bool "mkfifo" |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
11 default y |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
12 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
13 usage: mkfifo [-m mode] name... |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
14 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
15 Makes a named pipe at name. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
16 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
17 -m mode The mode of the pipe(s) created by mkfifo. It defaults |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
18 to 0644. This number is in octal, optionally preceded |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
19 by a leading zero. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
20 */ |
157
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
21 |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
22 #include "toys.h" |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
23 |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
24 DEFINE_GLOBALS( |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
25 char *mode; |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
26 ) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
27 |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
28 #define TT this.mkfifo |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
29 |
186
25447caf1b4b
Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents:
168
diff
changeset
|
30 void mkfifo_main(void) |
157
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
31 { |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
32 char *arg; |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
33 int i; |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
34 mode_t mode; |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
35 |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
36 if (toys.optflags) { |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
37 char *end; |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
38 mode = (mode_t)strtol(TT.mode, &end, 8); |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
39 if (end<=TT.mode || *end || mode<0 || mode>0777) |
157
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
40 error_exit("Invalid mode"); |
168
14fa82969ea3
Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents:
157
diff
changeset
|
41 } else mode = 0644; |
157
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
42 |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
43 for (i = 0; (arg = toys.optargs[i]); i++) |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
44 if (mkfifo(arg, mode)) |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
45 perror_exit(arg); |
714f4c051594
Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff
changeset
|
46 } |