1*ef03affbSThomas Cort /* $NetBSD: mkfifo.c,v 1.13 2011/09/04 20:30:34 joerg Exp $ */
2*ef03affbSThomas Cort
3*ef03affbSThomas Cort /*
4*ef03affbSThomas Cort * Copyright (c) 1990, 1993
5*ef03affbSThomas Cort * The Regents of the University of California. All rights reserved.
6*ef03affbSThomas Cort *
7*ef03affbSThomas Cort * Redistribution and use in source and binary forms, with or without
8*ef03affbSThomas Cort * modification, are permitted provided that the following conditions
9*ef03affbSThomas Cort * are met:
10*ef03affbSThomas Cort * 1. Redistributions of source code must retain the above copyright
11*ef03affbSThomas Cort * notice, this list of conditions and the following disclaimer.
12*ef03affbSThomas Cort * 2. Redistributions in binary form must reproduce the above copyright
13*ef03affbSThomas Cort * notice, this list of conditions and the following disclaimer in the
14*ef03affbSThomas Cort * documentation and/or other materials provided with the distribution.
15*ef03affbSThomas Cort * 3. Neither the name of the University nor the names of its contributors
16*ef03affbSThomas Cort * may be used to endorse or promote products derived from this software
17*ef03affbSThomas Cort * without specific prior written permission.
18*ef03affbSThomas Cort *
19*ef03affbSThomas Cort * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*ef03affbSThomas Cort * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*ef03affbSThomas Cort * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*ef03affbSThomas Cort * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*ef03affbSThomas Cort * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*ef03affbSThomas Cort * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*ef03affbSThomas Cort * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*ef03affbSThomas Cort * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*ef03affbSThomas Cort * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*ef03affbSThomas Cort * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*ef03affbSThomas Cort * SUCH DAMAGE.
30*ef03affbSThomas Cort */
31*ef03affbSThomas Cort
32*ef03affbSThomas Cort #include <sys/cdefs.h>
33*ef03affbSThomas Cort #ifndef lint
34*ef03affbSThomas Cort __COPYRIGHT("@(#) Copyright (c) 1990, 1993\
35*ef03affbSThomas Cort The Regents of the University of California. All rights reserved.");
36*ef03affbSThomas Cort #endif /* not lint */
37*ef03affbSThomas Cort
38*ef03affbSThomas Cort #ifndef lint
39*ef03affbSThomas Cort #if 0
40*ef03affbSThomas Cort static char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94";
41*ef03affbSThomas Cort #endif
42*ef03affbSThomas Cort __RCSID("$NetBSD: mkfifo.c,v 1.13 2011/09/04 20:30:34 joerg Exp $");
43*ef03affbSThomas Cort #endif /* not lint */
44*ef03affbSThomas Cort
45*ef03affbSThomas Cort #include <stdio.h>
46*ef03affbSThomas Cort #include <stdlib.h>
47*ef03affbSThomas Cort #include <string.h>
48*ef03affbSThomas Cort #include <locale.h>
49*ef03affbSThomas Cort #include <errno.h>
50*ef03affbSThomas Cort #include <sys/types.h>
51*ef03affbSThomas Cort #include <sys/stat.h>
52*ef03affbSThomas Cort #include <unistd.h>
53*ef03affbSThomas Cort #include <err.h>
54*ef03affbSThomas Cort
55*ef03affbSThomas Cort __dead static void usage(void);
56*ef03affbSThomas Cort
57*ef03affbSThomas Cort int
main(int argc,char * argv[])58*ef03affbSThomas Cort main(int argc, char *argv[])
59*ef03affbSThomas Cort {
60*ef03affbSThomas Cort int ch, exitval;
61*ef03affbSThomas Cort void *set;
62*ef03affbSThomas Cort mode_t mode;
63*ef03affbSThomas Cort
64*ef03affbSThomas Cort setlocale (LC_ALL, "");
65*ef03affbSThomas Cort
66*ef03affbSThomas Cort /* The default mode is the value of the bitwise inclusive or of
67*ef03affbSThomas Cort S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH
68*ef03affbSThomas Cort modified by the file creation mask */
69*ef03affbSThomas Cort mode = 0666 & ~umask(0);
70*ef03affbSThomas Cort
71*ef03affbSThomas Cort while ((ch = getopt(argc, argv, "m:")) != -1)
72*ef03affbSThomas Cort switch(ch) {
73*ef03affbSThomas Cort case 'm':
74*ef03affbSThomas Cort if (!(set = setmode(optarg))) {
75*ef03affbSThomas Cort err(1, "Cannot set file mode `%s'", optarg);
76*ef03affbSThomas Cort /* NOTREACHED */
77*ef03affbSThomas Cort }
78*ef03affbSThomas Cort /* In symbolic mode strings, the + and - operators are
79*ef03affbSThomas Cort interpreted relative to an assumed initial mode of
80*ef03affbSThomas Cort a=rw. */
81*ef03affbSThomas Cort mode = getmode(set, 0666);
82*ef03affbSThomas Cort free(set);
83*ef03affbSThomas Cort break;
84*ef03affbSThomas Cort case '?':
85*ef03affbSThomas Cort default:
86*ef03affbSThomas Cort usage();
87*ef03affbSThomas Cort }
88*ef03affbSThomas Cort argc -= optind;
89*ef03affbSThomas Cort argv += optind;
90*ef03affbSThomas Cort if (argv[0] == NULL)
91*ef03affbSThomas Cort usage();
92*ef03affbSThomas Cort
93*ef03affbSThomas Cort for (exitval = 0; *argv; ++argv) {
94*ef03affbSThomas Cort if (mkfifo(*argv, mode) < 0) {
95*ef03affbSThomas Cort warn("%s", *argv);
96*ef03affbSThomas Cort exitval = 1;
97*ef03affbSThomas Cort }
98*ef03affbSThomas Cort }
99*ef03affbSThomas Cort exit(exitval);
100*ef03affbSThomas Cort }
101*ef03affbSThomas Cort
102*ef03affbSThomas Cort static void
usage(void)103*ef03affbSThomas Cort usage(void)
104*ef03affbSThomas Cort {
105*ef03affbSThomas Cort (void)fprintf(stderr, "usage: mkfifo [-m mode] fifoname ...\n");
106*ef03affbSThomas Cort exit(1);
107*ef03affbSThomas Cort }
108