mkfifo.c revision 200420
1150524Sphk/* 2150524Sphk * Copyright (c) 1990, 1993 3150524Sphk * The Regents of the University of California. All rights reserved. 4150524Sphk * 5150524Sphk * Redistribution and use in source and binary forms, with or without 6150524Sphk * modification, are permitted provided that the following conditions 7150524Sphk * are met: 8150524Sphk * 1. Redistributions of source code must retain the above copyright 9150524Sphk * notice, this list of conditions and the following disclaimer. 10150524Sphk * 2. Redistributions in binary form must reproduce the above copyright 11150524Sphk * notice, this list of conditions and the following disclaimer in the 12150524Sphk * documentation and/or other materials provided with the distribution. 13150524Sphk * 3. All advertising materials mentioning features or use of this software 14150524Sphk * must display the following acknowledgement: 15150524Sphk * This product includes software developed by the University of 16150524Sphk * California, Berkeley and its contributors. 17150524Sphk * 4. Neither the name of the University nor the names of its contributors 18150524Sphk * may be used to endorse or promote products derived from this software 19150524Sphk * without specific prior written permission. 20150524Sphk * 21150524Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22150524Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23150524Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24150524Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25150524Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26150524Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27150524Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28150524Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29150524Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30150524Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31150524Sphk * SUCH DAMAGE. 32150524Sphk */ 33150524Sphk 34150524Sphk#ifndef lint 35150524Sphkstatic const char copyright[] = 36150524Sphk"@(#) Copyright (c) 1990, 1993\n\ 37150524Sphk The Regents of the University of California. All rights reserved.\n"; 38150524Sphk#endif /* not lint */ 39150524Sphk 40150524Sphk#ifndef lint 41150524Sphk#if 0 42150524Sphkstatic char sccsid[] = "@(#)mkfifo.c 8.2 (Berkeley) 1/5/94"; 43150524Sphk#endif 44150524Sphk#endif /* not lint */ 45150524Sphk#include <sys/cdefs.h> 46150524Sphk__FBSDID("$FreeBSD: head/usr.bin/mkfifo/mkfifo.c 200420 2009-12-11 23:35:38Z delphij $"); 47150524Sphk 48150524Sphk#include <sys/types.h> 49150524Sphk#include <sys/stat.h> 50150524Sphk 51150524Sphk#include <err.h> 52150524Sphk#include <errno.h> 53150524Sphk#include <stdio.h> 54150524Sphk#include <stdlib.h> 55150524Sphk#include <unistd.h> 56150524Sphk 57150524Sphk#define BASEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ 58150524Sphk S_IROTH | S_IWOTH 59150524Sphk 60150524Sphkstatic void usage(void); 61150524Sphk 62150524Sphkstatic int f_mode; 63150524Sphk 64150524Sphkint 65150524Sphkmain(int argc, char *argv[]) 66150524Sphk{ 67150524Sphk const char *modestr = NULL; 68150524Sphk const void *modep; 69 mode_t fifomode; 70 int ch, exitval; 71 72 while ((ch = getopt(argc, argv, "m:")) != -1) 73 switch(ch) { 74 case 'm': 75 f_mode = 1; 76 modestr = optarg; 77 break; 78 case '?': 79 default: 80 usage(); 81 } 82 argc -= optind; 83 argv += optind; 84 if (argv[0] == NULL) 85 usage(); 86 87 if (f_mode) { 88 umask(0); 89 errno = 0; 90 if ((modep = setmode(modestr)) == NULL) { 91 if (errno) 92 err(1, "setmode"); 93 errx(1, "invalid file mode: %s", modestr); 94 } 95 fifomode = getmode(modep, BASEMODE); 96 } else { 97 fifomode = BASEMODE; 98 } 99 100 for (exitval = 0; *argv != NULL; ++argv) 101 if (mkfifo(*argv, fifomode) < 0) { 102 warn("%s", *argv); 103 exitval = 1; 104 } 105 exit(exitval); 106} 107 108static void 109usage(void) 110{ 111 (void)fprintf(stderr, "usage: mkfifo [-m mode] fifo_name ...\n"); 112 exit(1); 113} 114