1331722Seadler/* 21590Srgrimes * Copyright (c) 1990, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 301590Srgrimes#ifndef lint 3127647Scharnierstatic const char copyright[] = 321590Srgrimes"@(#) Copyright (c) 1990, 1993\n\ 331590Srgrimes The Regents of the University of California. All rights reserved.\n"; 341590Srgrimes#endif /* not lint */ 351590Srgrimes 361590Srgrimes#ifndef lint 3727647Scharnier#if 0 381590Srgrimesstatic char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; 3927647Scharnier#endif 401590Srgrimes#endif /* not lint */ 4199112Sobrien#include <sys/cdefs.h> 4299112Sobrien__FBSDID("$FreeBSD$"); 431590Srgrimes 441590Srgrimes#include <sys/types.h> 451590Srgrimes#include <sys/stat.h> 461590Srgrimes 4727647Scharnier#include <err.h> 4850452Ssheldonh#include <errno.h> 491590Srgrimes#include <stdio.h> 5078717Sdd#include <stdlib.h> 51200462Sdelphij#include <string.h> 5227647Scharnier#include <unistd.h> 531590Srgrimes 5450452Ssheldonh#define BASEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ 5550452Ssheldonh S_IROTH | S_IWOTH 5650452Ssheldonh 5792921Simpstatic void usage(void); 5827647Scharnier 5950452Ssheldonhstatic int f_mode; 6050452Ssheldonh 611590Srgrimesint 62102944Sdwmalonemain(int argc, char *argv[]) 631590Srgrimes{ 64140382Sdelphij const char *modestr = NULL; 65140382Sdelphij const void *modep; 6650452Ssheldonh mode_t fifomode; 671590Srgrimes int ch, exitval; 681590Srgrimes 6950452Ssheldonh while ((ch = getopt(argc, argv, "m:")) != -1) 701590Srgrimes switch(ch) { 7150452Ssheldonh case 'm': 7250452Ssheldonh f_mode = 1; 7350452Ssheldonh modestr = optarg; 7450452Ssheldonh break; 751590Srgrimes case '?': 761590Srgrimes default: 771590Srgrimes usage(); 781590Srgrimes } 791590Srgrimes argc -= optind; 801590Srgrimes argv += optind; 811590Srgrimes if (argv[0] == NULL) 821590Srgrimes usage(); 831590Srgrimes 8450452Ssheldonh if (f_mode) { 8550452Ssheldonh umask(0); 8650452Ssheldonh errno = 0; 8750452Ssheldonh if ((modep = setmode(modestr)) == NULL) { 8850452Ssheldonh if (errno) 8950452Ssheldonh err(1, "setmode"); 9050452Ssheldonh errx(1, "invalid file mode: %s", modestr); 9150452Ssheldonh } 9250452Ssheldonh fifomode = getmode(modep, BASEMODE); 9350452Ssheldonh } else { 9450452Ssheldonh fifomode = BASEMODE; 9550452Ssheldonh } 9650452Ssheldonh 971590Srgrimes for (exitval = 0; *argv != NULL; ++argv) 9850452Ssheldonh if (mkfifo(*argv, fifomode) < 0) { 991590Srgrimes warn("%s", *argv); 1001590Srgrimes exitval = 1; 1011590Srgrimes } 1021590Srgrimes exit(exitval); 1031590Srgrimes} 1041590Srgrimes 10527647Scharnierstatic void 106102944Sdwmaloneusage(void) 1071590Srgrimes{ 10850452Ssheldonh (void)fprintf(stderr, "usage: mkfifo [-m mode] fifo_name ...\n"); 1091590Srgrimes exit(1); 1101590Srgrimes} 111