1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1992-2009 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Common Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.opensource.org/licenses/cpl1.0.txt * 11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * * 20 ***********************************************************************/ 21 #pragma prototyped 22 /* 23 * David Korn 24 * AT&T Bell Laboratories 25 * 26 * mkfifo 27 */ 28 29 static const char usage[] = 30 "[-?\n@(#)$Id: mkfifo (AT&T Research) 2009-01-02 $\n]" 31 USAGE_LICENSE 32 "[+NAME?mkfifo - make FIFOs (named pipes)]" 33 "[+DESCRIPTION?\bmkfifo\b creates one or more FIFO's. By " 34 "default, the mode of created FIFO is \ba=rw\b minus the " 35 "bits set in the \bumask\b(1).]" 36 "[m:mode]:[mode?Set the mode of created FIFO to \amode\a. " 37 "\amode\a is symbolic or octal mode as in \bchmod\b(1). Relative " 38 "modes assume an initial mode of \ba=rw\b.]" 39 "\n" 40 "\nfile ...\n" 41 "\n" 42 "[+EXIT STATUS?]{" 43 "[+0?All FIFO's created successfully.]" 44 "[+>0?One or more FIFO's could not be created.]" 45 "}" 46 "[+SEE ALSO?\bchmod\b(1), \bumask\b(1)]" 47 ; 48 49 #include <cmd.h> 50 #include <ls.h> 51 52 int 53 b_mkfifo(int argc, char *argv[], void* context) 54 { 55 register char* arg; 56 register mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; 57 register mode_t mask = 0; 58 register int mflag = 0; 59 60 cmdinit(argc, argv, context, ERROR_CATALOG, 0); 61 for (;;) 62 { 63 switch (optget(argv, usage)) 64 { 65 case 0: 66 break; 67 case 'm': 68 mflag = 1; 69 mode = strperm(arg = opt_info.arg, &opt_info.arg, mode); 70 if (*opt_info.arg) 71 error(ERROR_exit(0), "%s: invalid mode", arg); 72 continue; 73 case ':': 74 error(2, "%s", opt_info.arg); 75 continue; 76 case '?': 77 error(ERROR_usage(2), "%s", opt_info.arg); 78 continue; 79 } 80 break; 81 } 82 argv += opt_info.index; 83 if (error_info.errors || !*argv) 84 error(ERROR_usage(2), "%s", optusage(NiL)); 85 mask = umask(0); 86 if (!mflag) 87 { 88 mode &= ~mask; 89 umask(mask); 90 mask = 0; 91 } 92 while (arg = *argv++) 93 if (mkfifo(arg, mode) < 0) 94 error(ERROR_system(0), "%s:", arg); 95 if (mask) 96 umask(mask); 97 return error_info.errors != 0; 98 } 99