10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*484Scf46844 /*
23*484Scf46844 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*484Scf46844 * Use is subject to license terms.
25*484Scf46844 */
26*484Scf46844
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate /* */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <stdlib.h>
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <stdio.h>
370Sstevel@tonic-gate #include <errno.h>
380Sstevel@tonic-gate #include <string.h>
390Sstevel@tonic-gate #include <errno.h>
400Sstevel@tonic-gate #include <locale.h>
410Sstevel@tonic-gate #include <stdarg.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate #define ALLRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
440Sstevel@tonic-gate
450Sstevel@tonic-gate static void
460Sstevel@tonic-gate usage();
470Sstevel@tonic-gate
480Sstevel@tonic-gate void
490Sstevel@tonic-gate errmsg(int severity, int code, char *format, ...);
500Sstevel@tonic-gate
510Sstevel@tonic-gate /* from chmod:common.c: */
520Sstevel@tonic-gate
530Sstevel@tonic-gate extern mode_t
540Sstevel@tonic-gate newmode(char *modestr, mode_t basemode, mode_t umask, char *file, char *path);
550Sstevel@tonic-gate
56*484Scf46844 int
main(int argc,char * argv[])570Sstevel@tonic-gate main(int argc, char *argv[])
580Sstevel@tonic-gate {
590Sstevel@tonic-gate char *path;
600Sstevel@tonic-gate int exitval = 0;
610Sstevel@tonic-gate int c, i;
620Sstevel@tonic-gate int mflag = 0;
630Sstevel@tonic-gate int errflg = 0;
640Sstevel@tonic-gate mode_t umsk = umask(0);
650Sstevel@tonic-gate mode_t mode = ALLRW & (~umsk);
660Sstevel@tonic-gate
670Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
680Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
690Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
700Sstevel@tonic-gate #endif
710Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
720Sstevel@tonic-gate
730Sstevel@tonic-gate if (argc < 2) {
740Sstevel@tonic-gate usage();
750Sstevel@tonic-gate exit(1);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate while ((c = getopt(argc, argv, "m:")) != EOF) {
790Sstevel@tonic-gate switch (c) {
800Sstevel@tonic-gate case 'm':
810Sstevel@tonic-gate mflag++;
820Sstevel@tonic-gate mode = newmode(optarg, ALLRW, umsk, "", "");
830Sstevel@tonic-gate break;
840Sstevel@tonic-gate
850Sstevel@tonic-gate default:
860Sstevel@tonic-gate errflg++;
870Sstevel@tonic-gate break;
880Sstevel@tonic-gate }
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate if (argc < optind || errflg) {
920Sstevel@tonic-gate usage();
930Sstevel@tonic-gate exit(1);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate for (i = optind; i < argc; i++) {
970Sstevel@tonic-gate path = argv[i];
980Sstevel@tonic-gate if (mkfifo(path, mode) < 0) {
990Sstevel@tonic-gate perror("mkfifo");
1000Sstevel@tonic-gate exitval = 1;
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
104*484Scf46844 return (exitval);
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate static void
usage()1090Sstevel@tonic-gate usage()
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate (void) fprintf(stderr,
1120Sstevel@tonic-gate gettext("usage: mkfifo [-m mode] file ...\n"));
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate * errmsg - This is an interface required by the code common to mkfifo and
1170Sstevel@tonic-gate * chmod. The severity parameter is ignored here, but is meaningful
1180Sstevel@tonic-gate * to chmod.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate /* ARGSUSED */
1220Sstevel@tonic-gate /* PRINTFLIKE3 */
1230Sstevel@tonic-gate void
errmsg(int severity,int code,char * format,...)1240Sstevel@tonic-gate errmsg(int severity, int code, char *format, ...)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate va_list ap;
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate va_start(ap, format);
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate (void) fprintf(stderr, "mkfifo: ");
1310Sstevel@tonic-gate (void) vfprintf(stderr, format, ap);
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate va_end(ap);
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate if (code > 0) {
1360Sstevel@tonic-gate exit(code);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate }
139