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