xref: /titanic_50/usr/src/lib/libcmd/common/mkfifo.c (revision b02e9a2d4d2071d770e5aa9ae8f83f2bbe1f2ced)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1992-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
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 
30 static const char usage[] =
31 "[-?\n@(#)$Id: mkfifo (AT&T Research) 1999-04-20 $\n]"
32 USAGE_LICENSE
33 "[+NAME?mkfifo - make FIFOs (named pipes)]"
34 "[+DESCRIPTION?\bmkfifo\b creates one or more FIFO's.  By "
35 	"default, the mode of created FIFO is \ba=rw\b minus the "
36 	"bits set in the \bumask\b(1).]"
37 "[m:mode]:[mode?Set the mode of created FIFO to \amode\a.  "
38 	"\amode\a is symbolic or octal mode as in \bchmod\b(1).  Relative "
39 	"modes assume an initial mode of \ba=rw\b.]"
40 "\n"
41 "\nfile ...\n"
42 "\n"
43 "[+EXIT STATUS?]{"
44         "[+0?All FIFO's created successfully.]"
45         "[+>0?One or more FIFO's could not be created.]"
46 "}"
47 "[+SEE ALSO?\bchmod\b(1), \bumask\b(1)]"
48 ;
49 
50 #include <cmd.h>
51 #include <ls.h>
52 
53 #define RWALL	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
54 
55 int
56 b_mkfifo(int argc, char *argv[], void* context)
57 {
58 	register char *arg;
59 	register mode_t mode=RWALL, mask=0;
60 	register int n;
61 
62 	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
63 	while (n = optget(argv, usage)) switch (n)
64 	{
65 	  case 'm':
66 		mode = strperm(arg=opt_info.arg,&opt_info.arg,mode);
67 		if(*opt_info.arg)
68 			error(ERROR_exit(0),"%s: invalid mode",arg);
69 		break;
70 	  case ':':
71 		error(2, "%s",opt_info.arg);
72 		break;
73 	  case '?':
74 		error(ERROR_usage(2), "%s",opt_info.arg);
75 		break;
76 	}
77 	argv += opt_info.index;
78 	if(error_info.errors || !*argv)
79 		error(ERROR_usage(2),"%s",optusage(NiL));
80 	while(arg = *argv++)
81 	{
82 		if(mkfifo(arg,mode) < 0)
83 			error(ERROR_system(0),"%s:",arg);
84 	}
85 	if(mask)
86 		umask(mask);
87 	return(error_info.errors!=0);
88 }
89 
90