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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
530
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
2 *
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
3 * mkfifo.c - Create FIFOs (named pipes)
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
4 *
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
8 *
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
9 * TODO: Add -m
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
12
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
13 config MKFIFO
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
14 bool "mkfifo"
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
15 default y
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
16 help
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
19 Create FIFOs (named pipes).
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
20 */
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
23 #include "toys.h"
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
30 void mkfifo_main(void)
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
31 {
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
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
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
42 toys.exitval = 1;
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
43 }
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
44 }
6afff0596646 Add mkfifo.
Georgi Chorbadzhiyski <gf@unixsol.org>
parents:
diff changeset
45 }