Mercurial > hg > toybox
annotate toys/posix/mkfifo.c @ 674:7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 08 Oct 2012 00:02:30 -0500 |
parents | 6df4ccc0acbe |
children | 786841fdb1e0 |
rev | line source |
---|---|
530 | 1 /* vi: set sw=4 ts=4: |
2 * | |
3 * mkfifo.c - Create FIFOs (named pipes) | |
4 * | |
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> | |
6 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/mkfifo.html |
530 | 8 * |
9 * TODO: Add -m | |
10 | |
551
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
11 USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN)) |
530 | 12 |
13 config MKFIFO | |
14 bool "mkfifo" | |
15 default y | |
16 help | |
17 usage: mkfifo [fifo_name...] | |
531
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
18 |
530 | 19 Create FIFOs (named pipes). |
20 */ | |
21 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
22 #define FOR_mkfifo |
530 | 23 #include "toys.h" |
24 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
25 GLOBALS( |
551
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
26 char *m_string; |
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
27 mode_t mode; |
531
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
28 ) |
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
29 |
530 | 30 void mkfifo_main(void) |
31 { | |
32 char **s; | |
531
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
33 |
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
34 TT.mode = 0666; |
551
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
35 if (toys.optflags & FLAG_m) { |
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
36 TT.mode = string_to_mode(TT.m_string, 0); |
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
531
diff
changeset
|
37 } |
531
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
38 |
530 | 39 for (s = toys.optargs; *s; s++) { |
531
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
40 if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) { |
6fedb88874a4
Cleanups: use perror_msg() and make mode a global.
Rob Landley <rob@landley.net>
parents:
530
diff
changeset
|
41 perror_msg("cannot create fifo '%s'", *s); |
530 | 42 toys.exitval = 1; |
43 } | |
44 } | |
45 } |