1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin * *
3da2e3ebdSchin * This software is part of the ast package *
4*3e14f97fSRoger A. Faulkner * Copyright (c) 1992-2010 AT&T Intellectual Property *
5da2e3ebdSchin * and is licensed under the *
6da2e3ebdSchin * Common Public License, Version 1.0 *
77c2fbfb3SApril 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 static const char usage[] =
3034f9b3eeSRoland Mainz "[-?\n@(#)$Id: mkfifo (AT&T Research) 2009-01-02 $\n]"
31da2e3ebdSchin USAGE_LICENSE
32da2e3ebdSchin "[+NAME?mkfifo - make FIFOs (named pipes)]"
33da2e3ebdSchin "[+DESCRIPTION?\bmkfifo\b creates one or more FIFO's. By "
34da2e3ebdSchin "default, the mode of created FIFO is \ba=rw\b minus the "
35da2e3ebdSchin "bits set in the \bumask\b(1).]"
36da2e3ebdSchin "[m:mode]:[mode?Set the mode of created FIFO to \amode\a. "
37da2e3ebdSchin "\amode\a is symbolic or octal mode as in \bchmod\b(1). Relative "
38da2e3ebdSchin "modes assume an initial mode of \ba=rw\b.]"
39da2e3ebdSchin "\n"
40da2e3ebdSchin "\nfile ...\n"
41da2e3ebdSchin "\n"
42da2e3ebdSchin "[+EXIT STATUS?]{"
43da2e3ebdSchin "[+0?All FIFO's created successfully.]"
44da2e3ebdSchin "[+>0?One or more FIFO's could not be created.]"
45da2e3ebdSchin "}"
46da2e3ebdSchin "[+SEE ALSO?\bchmod\b(1), \bumask\b(1)]"
47da2e3ebdSchin ;
48da2e3ebdSchin
49da2e3ebdSchin #include <cmd.h>
50da2e3ebdSchin #include <ls.h>
51da2e3ebdSchin
52da2e3ebdSchin int
b_mkfifo(int argc,char * argv[],void * context)53da2e3ebdSchin b_mkfifo(int argc, char *argv[], void* context)
54da2e3ebdSchin {
55da2e3ebdSchin register char* arg;
5634f9b3eeSRoland Mainz register mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
5734f9b3eeSRoland Mainz register mode_t mask = 0;
5834f9b3eeSRoland Mainz register int mflag = 0;
59da2e3ebdSchin
60da2e3ebdSchin cmdinit(argc, argv, context, ERROR_CATALOG, 0);
6134f9b3eeSRoland Mainz for (;;)
62da2e3ebdSchin {
6334f9b3eeSRoland Mainz switch (optget(argv, usage))
6434f9b3eeSRoland Mainz {
6534f9b3eeSRoland Mainz case 0:
6634f9b3eeSRoland Mainz break;
67da2e3ebdSchin case 'm':
6834f9b3eeSRoland Mainz mflag = 1;
69da2e3ebdSchin mode = strperm(arg = opt_info.arg, &opt_info.arg, mode);
70da2e3ebdSchin if (*opt_info.arg)
71da2e3ebdSchin error(ERROR_exit(0), "%s: invalid mode", arg);
7234f9b3eeSRoland Mainz continue;
73da2e3ebdSchin case ':':
74da2e3ebdSchin error(2, "%s", opt_info.arg);
7534f9b3eeSRoland Mainz continue;
76da2e3ebdSchin case '?':
77da2e3ebdSchin error(ERROR_usage(2), "%s", opt_info.arg);
7834f9b3eeSRoland Mainz continue;
7934f9b3eeSRoland Mainz }
80da2e3ebdSchin break;
81da2e3ebdSchin }
82da2e3ebdSchin argv += opt_info.index;
83da2e3ebdSchin if (error_info.errors || !*argv)
84da2e3ebdSchin error(ERROR_usage(2), "%s", optusage(NiL));
8534f9b3eeSRoland Mainz mask = umask(0);
8634f9b3eeSRoland Mainz if (!mflag)
87da2e3ebdSchin {
8834f9b3eeSRoland Mainz mode &= ~mask;
8934f9b3eeSRoland Mainz umask(mask);
9034f9b3eeSRoland Mainz mask = 0;
9134f9b3eeSRoland Mainz }
9234f9b3eeSRoland Mainz while (arg = *argv++)
93da2e3ebdSchin if (mkfifo(arg, mode) < 0)
94da2e3ebdSchin error(ERROR_system(0), "%s:", arg);
95da2e3ebdSchin if (mask)
96da2e3ebdSchin umask(mask);
9734f9b3eeSRoland Mainz return error_info.errors != 0;
98da2e3ebdSchin }
99