1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1992-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * David Korn
1N/A * AT&T Bell Laboratories
1N/A *
1N/A * mkfifo
1N/A */
1N/A
1N/Astatic const char usage[] =
1N/A"[-?\n@(#)$Id: mkfifo (AT&T Research) 2009-01-02 $\n]"
1N/AUSAGE_LICENSE
1N/A"[+NAME?mkfifo - make FIFOs (named pipes)]"
1N/A"[+DESCRIPTION?\bmkfifo\b creates one or more FIFO's. By "
1N/A "default, the mode of created FIFO is \ba=rw\b minus the "
1N/A "bits set in the \bumask\b(1).]"
1N/A"[m:mode]:[mode?Set the mode of created FIFO to \amode\a. "
1N/A "\amode\a is symbolic or octal mode as in \bchmod\b(1). Relative "
1N/A "modes assume an initial mode of \ba=rw\b.]"
1N/A"\n"
1N/A"\nfile ...\n"
1N/A"\n"
1N/A"[+EXIT STATUS?]{"
1N/A "[+0?All FIFO's created successfully.]"
1N/A "[+>0?One or more FIFO's could not be created.]"
1N/A"}"
1N/A"[+SEE ALSO?\bchmod\b(1), \bumask\b(1)]"
1N/A;
1N/A
1N/A#include <cmd.h>
1N/A#include <ls.h>
1N/A
1N/Aint
1N/Ab_mkfifo(int argc, char *argv[], void* context)
1N/A{
1N/A register char* arg;
1N/A register mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
1N/A register mode_t mask = 0;
1N/A register int mflag = 0;
1N/A
1N/A cmdinit(argc, argv, context, ERROR_CATALOG, 0);
1N/A for (;;)
1N/A {
1N/A switch (optget(argv, usage))
1N/A {
1N/A case 'm':
1N/A mflag = 1;
1N/A mode = strperm(arg = opt_info.arg, &opt_info.arg, mode);
1N/A if (*opt_info.arg)
1N/A error(ERROR_exit(0), "%s: invalid mode", arg);
1N/A continue;
1N/A case ':':
1N/A error(2, "%s", opt_info.arg);
1N/A break;
1N/A case '?':
1N/A error(ERROR_usage(2), "%s", opt_info.arg);
1N/A break;
1N/A }
1N/A break;
1N/A }
1N/A argv += opt_info.index;
1N/A if (error_info.errors || !*argv)
1N/A error(ERROR_usage(2), "%s", optusage(NiL));
1N/A mask = umask(0);
1N/A if (!mflag)
1N/A {
1N/A mode &= ~mask;
1N/A umask(mask);
1N/A mask = 0;
1N/A }
1N/A while (arg = *argv++)
1N/A if (mkfifo(arg, mode) < 0)
1N/A error(ERROR_system(0), "%s:", arg);
1N/A if (mask)
1N/A umask(mask);
1N/A return error_info.errors != 0;
1N/A}