blob: ab466fc377165fcc6cbbd8ff85c7b737e3eb8fe9 [file] [log] [blame]
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -06001/* vi: set sw=4 ts=4:
2 *
3 * mkfifo.c - Create FIFOs (named pipes)
4 *
5 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
6 *
7 * See http://pubs.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html
8 *
9 * TODO: Add -m
10
Daniel Walter05744b32012-03-19 19:57:56 -050011USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN))
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060012
13config MKFIFO
14 bool "mkfifo"
15 default y
16 help
17 usage: mkfifo [fifo_name...]
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060018
Rob Landleye430db22012-03-06 21:19:57 -060019 Create FIFOs (named pipes).
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060020*/
21
22#include "toys.h"
23
Rob Landleye430db22012-03-06 21:19:57 -060024DEFINE_GLOBALS(
Daniel Walter05744b32012-03-19 19:57:56 -050025 char *m_string;
26 mode_t mode;
Rob Landleye430db22012-03-06 21:19:57 -060027)
28
29#define TT this.mkfifo
Daniel Walter05744b32012-03-19 19:57:56 -050030#define FLAG_m (1)
Rob Landleye430db22012-03-06 21:19:57 -060031
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060032void mkfifo_main(void)
33{
34 char **s;
Rob Landleye430db22012-03-06 21:19:57 -060035
36 TT.mode = 0666;
Daniel Walter05744b32012-03-19 19:57:56 -050037 if (toys.optflags & FLAG_m) {
38 TT.mode = string_to_mode(TT.m_string, 0);
39 }
Rob Landleye430db22012-03-06 21:19:57 -060040
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060041 for (s = toys.optargs; *s; s++) {
Rob Landleye430db22012-03-06 21:19:57 -060042 if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) {
43 perror_msg("cannot create fifo '%s'", *s);
Georgi Chorbadzhiyskif656fc92012-03-06 20:58:13 -060044 toys.exitval = 1;
45 }
46 }
47}