mkfifo.c revision 331722
1237981Smav/* 2237981Smav * Copyright (c) 1990, 1993 3237981Smav * The Regents of the University of California. All rights reserved. 4237981Smav * 5237981Smav * Redistribution and use in source and binary forms, with or without 6237981Smav * modification, are permitted provided that the following conditions 7237981Smav * are met: 8237981Smav * 1. Redistributions of source code must retain the above copyright 9237981Smav * notice, this list of conditions and the following disclaimer. 10237981Smav * 2. Redistributions in binary form must reproduce the above copyright 11237981Smav * notice, this list of conditions and the following disclaimer in the 12237981Smav * documentation and/or other materials provided with the distribution. 13237981Smav * 4. Neither the name of the University nor the names of its contributors 14237981Smav * may be used to endorse or promote products derived from this software 15237981Smav * without specific prior written permission. 16237981Smav * 17237981Smav * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18237981Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19237981Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20237981Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21237981Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22237981Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23237981Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24237981Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25237981Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26237981Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27237981Smav * SUCH DAMAGE. 28237981Smav */ 29237981Smav 30237981Smav#ifndef lint 31237981Smavstatic const char copyright[] = 32237981Smav"@(#) Copyright (c) 1990, 1993\n\ 33237981Smav The Regents of the University of California. All rights reserved.\n"; 34237981Smav#endif /* not lint */ 35237981Smav 36237981Smav#ifndef lint 37237981Smav#if 0 38237981Smavstatic char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; 39237981Smav#endif 40237981Smav#endif /* not lint */ 41237981Smav#include <sys/cdefs.h> 42237981Smav__FBSDID("$FreeBSD: stable/11/usr.bin/mkfifo/mkfifo.c 331722 2018-03-29 02:50:57Z eadler $"); 43237981Smav 44237981Smav#include <sys/types.h> 45237981Smav#include <sys/stat.h> 46237981Smav 47237981Smav#include <err.h> 48237981Smav#include <errno.h> 49237981Smav#include <stdio.h> 50237981Smav#include <stdlib.h> 51237981Smav#include <string.h> 52237981Smav#include <unistd.h> 53237981Smav 54237981Smav#define BASEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ 55237981Smav S_IROTH | S_IWOTH 56237981Smav 57237981Smavstatic void usage(void); 58237981Smav 59237981Smavstatic int f_mode; 60237981Smav 61237981Smavint 62237981Smavmain(int argc, char *argv[]) 63237981Smav{ 64237981Smav const char *modestr = NULL; 65237981Smav const void *modep; 66237981Smav mode_t fifomode; 67237981Smav int ch, exitval; 68237981Smav 69237981Smav while ((ch = getopt(argc, argv, "m:")) != -1) 70237981Smav switch(ch) { 71237981Smav case 'm': 72237981Smav f_mode = 1; 73237981Smav modestr = optarg; 74237981Smav break; 75237981Smav case '?': 76237981Smav default: 77237981Smav usage(); 78237981Smav } 79237981Smav argc -= optind; 80237981Smav argv += optind; 81237981Smav if (argv[0] == NULL) 82237981Smav usage(); 83237981Smav 84237981Smav if (f_mode) { 85237981Smav umask(0); 86237981Smav errno = 0; 87237981Smav if ((modep = setmode(modestr)) == NULL) { 88237981Smav if (errno) 89237981Smav err(1, "setmode"); 90237981Smav errx(1, "invalid file mode: %s", modestr); 91237981Smav } 92237981Smav fifomode = getmode(modep, BASEMODE); 93237981Smav } else { 94237981Smav fifomode = BASEMODE; 95237981Smav } 96237981Smav 97237981Smav for (exitval = 0; *argv != NULL; ++argv) 98237981Smav if (mkfifo(*argv, fifomode) < 0) { 99237981Smav warn("%s", *argv); 100237981Smav exitval = 1; 101237981Smav } 102237981Smav exit(exitval); 103237981Smav} 104237981Smav 105237981Smavstatic void 106237981Smavusage(void) 107237981Smav{ 108237981Smav (void)fprintf(stderr, "usage: mkfifo [-m mode] fifo_name ...\n"); 109237981Smav exit(1); 110237981Smav} 111237981Smav