1*4e46e593Sjoerg /* $NetBSD: mkfifo.c,v 1.13 2011/09/04 20:30:34 joerg Exp $ */
27280395fSjtc
361f28255Scgd /*
47280395fSjtc * Copyright (c) 1990, 1993
57280395fSjtc * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
1589aaa1bbSagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32f027bde2Slukem #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
3498e5374cSlukem __COPYRIGHT("@(#) Copyright (c) 1990, 1993\
3598e5374cSlukem The Regents of the University of California. All rights reserved.");
3661f28255Scgd #endif /* not lint */
3761f28255Scgd
3861f28255Scgd #ifndef lint
397280395fSjtc #if 0
407280395fSjtc static char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94";
417280395fSjtc #endif
42*4e46e593Sjoerg __RCSID("$NetBSD: mkfifo.c,v 1.13 2011/09/04 20:30:34 joerg Exp $");
4361f28255Scgd #endif /* not lint */
4461f28255Scgd
4561f28255Scgd #include <stdio.h>
466b020f1eSjtc #include <stdlib.h>
4761f28255Scgd #include <string.h>
48b148ed66Sjtc #include <locale.h>
492ddbb97fSjtc #include <errno.h>
502ddbb97fSjtc #include <sys/types.h>
512ddbb97fSjtc #include <sys/stat.h>
522ddbb97fSjtc #include <unistd.h>
53b148ed66Sjtc #include <err.h>
5461f28255Scgd
55*4e46e593Sjoerg __dead static void usage(void);
566b020f1eSjtc
57f7c6bf57Sjtc int
main(int argc,char * argv[])58*4e46e593Sjoerg main(int argc, char *argv[])
5961f28255Scgd {
606b020f1eSjtc int ch, exitval;
616b020f1eSjtc void *set;
626b020f1eSjtc mode_t mode;
6361f28255Scgd
64b148ed66Sjtc setlocale (LC_ALL, "");
65b148ed66Sjtc
666b020f1eSjtc /* The default mode is the value of the bitwise inclusive or of
676b020f1eSjtc S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH
686b020f1eSjtc modified by the file creation mask */
696b020f1eSjtc mode = 0666 & ~umask(0);
706b020f1eSjtc
71b148ed66Sjtc while ((ch = getopt(argc, argv, "m:")) != -1)
7261f28255Scgd switch(ch) {
736b020f1eSjtc case 'm':
746b020f1eSjtc if (!(set = setmode(optarg))) {
75c05266afSchristos err(1, "Cannot set file mode `%s'", optarg);
76b148ed66Sjtc /* NOTREACHED */
776b020f1eSjtc }
786b020f1eSjtc /* In symbolic mode strings, the + and - operators are
796b020f1eSjtc interpreted relative to an assumed initial mode of
806b020f1eSjtc a=rw. */
816b020f1eSjtc mode = getmode(set, 0666);
82e92c3f28Senami free(set);
8361f28255Scgd break;
8461f28255Scgd case '?':
8561f28255Scgd default:
8661f28255Scgd usage();
8761f28255Scgd }
887280395fSjtc argc -= optind;
897280395fSjtc argv += optind;
907280395fSjtc if (argv[0] == NULL)
9161f28255Scgd usage();
9261f28255Scgd
9361f28255Scgd for (exitval = 0; *argv; ++argv) {
946b020f1eSjtc if (mkfifo(*argv, mode) < 0) {
95b148ed66Sjtc warn("%s", *argv);
966b020f1eSjtc exitval = 1;
9761f28255Scgd }
9861f28255Scgd }
9961f28255Scgd exit(exitval);
10061f28255Scgd }
10161f28255Scgd
102*4e46e593Sjoerg static void
usage(void)103*4e46e593Sjoerg usage(void)
10461f28255Scgd {
1056b020f1eSjtc (void)fprintf(stderr, "usage: mkfifo [-m mode] fifoname ...\n");
10661f28255Scgd exit(1);
10761f28255Scgd }
108