Merge commit 'b1e7e97d3b60469b243b3b2e22c7d8cbd11c7c90'
[unleashed.git] / usr / src / cmd / mkfifo / mkfifo.c
blobf49673f8aa8e56f77c1e24525d48ab4d67c9f66e
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 /* */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <stdio.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <locale.h>
41 #include <stdarg.h>
43 #define ALLRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
45 static void
46 usage();
48 void
49 errmsg(int severity, int code, char *format, ...);
51 /* from chmod:common.c: */
53 extern mode_t
54 newmode(char *modestr, mode_t basemode, mode_t umask, char *file, char *path);
56 int
57 main(int argc, char *argv[])
59 char *path;
60 int exitval = 0;
61 int c, i;
62 int mflag = 0;
63 int errflg = 0;
64 mode_t umsk = umask(0);
65 mode_t mode = ALLRW & (~umsk);
67 (void) setlocale(LC_ALL, "");
68 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
69 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
70 #endif
71 (void) textdomain(TEXT_DOMAIN);
73 if (argc < 2) {
74 usage();
75 exit(1);
78 while ((c = getopt(argc, argv, "m:")) != EOF) {
79 switch (c) {
80 case 'm':
81 mflag++;
82 mode = newmode(optarg, ALLRW, umsk, "", "");
83 break;
85 default:
86 errflg++;
87 break;
91 if (argc < optind || errflg) {
92 usage();
93 exit(1);
96 for (i = optind; i < argc; i++) {
97 path = argv[i];
98 if (mkfifo(path, mode) < 0) {
99 perror("mkfifo");
100 exitval = 1;
104 return (exitval);
108 static void
109 usage()
111 (void) fprintf(stderr,
112 gettext("usage: mkfifo [-m mode] file ...\n"));
116 * errmsg - This is an interface required by the code common to mkfifo and
117 * chmod. The severity parameter is ignored here, but is meaningful
118 * to chmod.
121 /* ARGSUSED */
122 /* PRINTFLIKE3 */
123 void
124 errmsg(int severity, int code, char *format, ...)
126 va_list ap;
128 va_start(ap, format);
130 (void) fprintf(stderr, "mkfifo: ");
131 (void) vfprintf(stderr, format, ap);
133 va_end(ap);
135 if (code > 0) {
136 exit(code);