merge with 3.8.3b
[coreutils.git] / src / mkfifo.c
blobc15f740e604fb7e2b414af125631cf2a6c20939e
1 /* mkfifo -- make fifo's (named pipes)
2 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Options:
19 -m, --mode=mode Set the mode of created fifo's to MODE, which is
20 symbolic as in chmod and uses the umask as a point of
21 departure.
23 David MacKenzie <djm@ai.mit.edu> */
25 #ifdef HAVE_CONFIG_H
26 #if defined (CONFIG_BROKETS)
27 /* We use <config.h> instead of "config.h" so that a compilation
28 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
29 (which it would do because it found this file in $srcdir). */
30 #include <config.h>
31 #else
32 #include "config.h"
33 #endif
34 #endif
36 #include <stdio.h>
37 #include <getopt.h>
38 #include <sys/types.h>
39 #include "system.h"
40 #include "modechange.h"
41 #include "version.h"
43 void error ();
45 static void usage ();
47 /* The name this program was run with. */
48 char *program_name;
50 /* If non-zero, display usage information and exit. */
51 static int show_help;
53 /* If non-zero, print the version on standard output and exit. */
54 static int show_version;
56 static struct option const longopts[] =
58 {"mode", required_argument, NULL, 'm'},
59 {"help", no_argument, &show_help, 1},
60 {"version", no_argument, &show_version, 1},
61 {NULL, 0, NULL, 0}
64 void
65 main (argc, argv)
66 int argc;
67 char **argv;
69 unsigned short newmode;
70 struct mode_change *change;
71 char *symbolic_mode;
72 int errors = 0;
73 int optc;
75 program_name = argv[0];
76 symbolic_mode = NULL;
78 #ifndef S_ISFIFO
79 error (4, 0, "fifo files not supported");
80 #else
81 while ((optc = getopt_long (argc, argv, "m:", longopts, (int *) 0)) != EOF)
83 switch (optc)
85 case 0:
86 break;
87 case 'm':
88 symbolic_mode = optarg;
89 break;
90 default:
91 usage ();
95 if (show_version)
97 printf ("%s\n", version_string);
98 exit (0);
101 if (show_help)
102 usage ();
104 if (optind == argc)
105 usage ();
107 newmode = 0666 & ~umask (0);
108 if (symbolic_mode)
110 change = mode_compile (symbolic_mode, 0);
111 if (change == MODE_INVALID)
112 error (1, 0, "invalid mode");
113 else if (change == MODE_MEMORY_EXHAUSTED)
114 error (1, 0, "virtual memory exhausted");
115 newmode = mode_adjust (newmode, change);
118 for (; optind < argc; ++optind)
120 if (mkfifo (argv[optind], newmode))
122 error (0, errno, "cannot make fifo `%s'", argv[optind]);
123 errors = 1;
127 exit (errors);
128 #endif
131 #ifdef S_ISFIFO
132 static void
133 usage ()
135 fprintf (stderr, "\
136 Usage: %s [-m mode] [--mode=mode] [--help] [--version] path...\n",
137 program_name);
138 exit (1);
140 #endif