annotate toys/mkfifo.c @ 234:163498bf547b

Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:43:27 -0600
parents d4176f3f3835
children 7cb15eae1664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
7 USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN))
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
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 168
diff changeset
24 void mkfifo_main(void)
157
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
25 {
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
26 char *arg;
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
27 int i;
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
28 mode_t mode;
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
29
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
30 if (toys.optflags) {
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
31 char *end;
168
14fa82969ea3 Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents: 157
diff changeset
32 mode = (mode_t)strtol(toy.mkfifo.mode, &end, 8);
14fa82969ea3 Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents: 157
diff changeset
33 if (end<=toy.mkfifo.mode || *end || mode<0 || mode>0777)
157
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
34 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
35 } else mode = 0644;
157
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
36
168
14fa82969ea3 Tighten up error handling, add a umask() call so -m 123 actually works.
Rob Landley <rob@landley.net>
parents: 157
diff changeset
37 umask(0);
157
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
38 for (i = 0; (arg = toys.optargs[i]); i++)
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
39 if (mkfifo(arg, mode))
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
40 perror_exit(arg);
714f4c051594 Add initial mkfifo implementation
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
diff changeset
41 }