1 /* 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1990, 1993\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mkfifo.c 8.1 (Berkeley) 06/06/93"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 #include <errno.h> 21 #include <stdio.h> 22 #include <string.h> 23 24 main(argc, argv) 25 int argc; 26 char **argv; 27 { 28 extern int errno, optind; 29 int ch, exitval, pflag; 30 31 pflag = 0; 32 while ((ch = getopt(argc, argv, "p")) != EOF) 33 switch(ch) { 34 case 'p': 35 pflag = 1; 36 break; 37 case '?': 38 default: 39 usage(); 40 } 41 42 if (!*(argv += optind)) 43 usage(); 44 45 for (exitval = 0; *argv; ++argv) { 46 if (pflag && build(*argv)) { 47 exitval |= 1; 48 continue; 49 } 50 if (mkfifo(*argv, 0777) < 0) { 51 (void)fprintf(stderr, "mkfifo: %s: %s\n", 52 *argv, strerror(errno)); 53 exitval |= 1; 54 } 55 } 56 exit(exitval); 57 } 58 59 build(path) 60 char *path; 61 { 62 register char *p; 63 struct stat sb; 64 65 for (p = path; *p; p++) { 66 if (*p != '/') 67 continue; 68 if (stat(path, &sb)) { 69 if (errno != ENOENT || mkdir(path, 0777) < 0) { 70 (void)fprintf(stderr, "mkdir: %s: %s\n", 71 path, strerror(errno)); 72 return(1); 73 } 74 } 75 *p = '/'; 76 } 77 return(0); 78 } 79 80 usage() 81 { 82 (void)fprintf(stderr, "usage: mkfifo [-p] fifoname ...\n"); 83 exit(1); 84 } 85