mkfifo.c revision 102944
1234353Sdim/* 2198090Srdivacky * Copyright (c) 1990, 1993 3198090Srdivacky * The Regents of the University of California. All rights reserved. 4198090Srdivacky * 5198090Srdivacky * Redistribution and use in source and binary forms, with or without 6198090Srdivacky * modification, are permitted provided that the following conditions 7198090Srdivacky * are met: 8198090Srdivacky * 1. Redistributions of source code must retain the above copyright 9198090Srdivacky * notice, this list of conditions and the following disclaimer. 10198090Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 11198090Srdivacky * notice, this list of conditions and the following disclaimer in the 12198090Srdivacky * documentation and/or other materials provided with the distribution. 13249423Sdim * 3. All advertising materials mentioning features or use of this software 14249423Sdim * must display the following acknowledgement: 15249423Sdim * This product includes software developed by the University of 16198090Srdivacky * California, Berkeley and its contributors. 17198090Srdivacky * 4. Neither the name of the University nor the names of its contributors 18234353Sdim * may be used to endorse or promote products derived from this software 19198090Srdivacky * without specific prior written permission. 20198090Srdivacky * 21276479Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22276479Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23210299Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24210299Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25198090Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26198090Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27210299Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28210299Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29198090Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30212904Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31198090Srdivacky * SUCH DAMAGE. 32261991Sdim */ 33198090Srdivacky 34210299Sed#ifndef lint 35198090Srdivackystatic const char copyright[] = 36198090Srdivacky"@(#) Copyright (c) 1990, 1993\n\ 37276479Sdim The Regents of the University of California. All rights reserved.\n"; 38198090Srdivacky#endif /* not lint */ 39276479Sdim 40198090Srdivacky#ifndef lint 41198090Srdivacky#if 0 42198090Srdivackystatic char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; 43198090Srdivacky#endif 44210299Sed#endif /* not lint */ 45210299Sed#include <sys/cdefs.h> 46210299Sed__FBSDID("$FreeBSD: head/usr.bin/mkfifo/mkfifo.c 102944 2002-09-04 23:29:10Z dwmalone $"); 47210299Sed 48210299Sed#include <sys/types.h> 49198090Srdivacky#include <sys/stat.h> 50198090Srdivacky 51198090Srdivacky#include <err.h> 52198090Srdivacky#include <errno.h> 53210299Sed#include <stdio.h> 54210299Sed#include <stdlib.h> 55210299Sed#include <string.h> 56210299Sed#include <unistd.h> 57210299Sed 58210299Sed#define BASEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ 59210299Sed S_IROTH | S_IWOTH 60210299Sed 61210299Sedstatic void usage(void); 62210299Sed 63210299Sedstatic int f_mode; 64210299Sed 65210299Sedint 66210299Sedmain(int argc, char *argv[]) 67210299Sed{ 68210299Sed char *modestr; 69210299Sed void *modep; 70210299Sed mode_t fifomode; 71210299Sed int ch, exitval; 72210299Sed 73210299Sed while ((ch = getopt(argc, argv, "m:")) != -1) 74210299Sed switch(ch) { 75210299Sed case 'm': 76210299Sed f_mode = 1; 77210299Sed modestr = optarg; 78261991Sdim break; 79261991Sdim case '?': 80210299Sed default: 81210299Sed usage(); 82210299Sed } 83210299Sed argc -= optind; 84210299Sed argv += optind; 85261991Sdim if (argv[0] == NULL) 86261991Sdim usage(); 87210299Sed 88210299Sed if (f_mode) { 89210299Sed umask(0); 90210299Sed errno = 0; 91198090Srdivacky if ((modep = setmode(modestr)) == NULL) { 92198090Srdivacky if (errno) 93212904Sdim err(1, "setmode"); 94212904Sdim errx(1, "invalid file mode: %s", modestr); 95212904Sdim } 96212904Sdim fifomode = getmode(modep, BASEMODE); 97212904Sdim } else { 98212904Sdim fifomode = BASEMODE; 99212904Sdim } 100212904Sdim 101212904Sdim for (exitval = 0; *argv != NULL; ++argv) 102212904Sdim if (mkfifo(*argv, fifomode) < 0) { 103212904Sdim warn("%s", *argv); 104212904Sdim exitval = 1; 105210299Sed } 106210299Sed exit(exitval); 107210299Sed} 108210299Sed 109210299Sedstatic void 110212904Sdimusage(void) 111212904Sdim{ 112212904Sdim (void)fprintf(stderr, "usage: mkfifo [-m mode] fifo_name ...\n"); 113212904Sdim exit(1); 114212904Sdim} 115212904Sdim