date and time created 90/06/25 13:56:22 by bostic
[unix-history] / usr / src / usr.bin / mkfifo / mkfifo.c
CommitLineData
4222b0cc
KM
1/*
2 * Copyright (c) 1990 Regents of the University of California.
3 * All rights reserved.
4 *
f15db449 5 * %sccs.include.redist.c%
4222b0cc
KM
6 */
7
8#ifndef lint
9char copyright[] =
10"@(#) Copyright (c) 1990 Regents of the University of California.\n\
11 All rights reserved.\n";
12#endif /* not lint */
13
14#ifndef lint
f15db449 15static char sccsid[] = "@(#)mkfifo.c 5.3 (Berkeley) %G%";
4222b0cc
KM
16#endif /* not lint */
17
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <errno.h>
21#include <stdio.h>
38dde0cd 22#include <string.h>
4222b0cc
KM
23
24main(argc, argv)
25 int argc;
26 char **argv;
27{
28 extern int errno, optind;
29 int ch, exitval, pflag;
30
31 pflag = 0;
32 while ((ch = getopt(argc, argv, "p")) != EOF)
33 switch(ch) {
34 case 'p':
35 pflag = 1;
36 break;
37 case '?':
38 default:
39 usage();
40 }
41
42 if (!*(argv += optind))
43 usage();
44
45 for (exitval = 0; *argv; ++argv) {
46 if (pflag && build(*argv)) {
47 exitval |= 1;
48 continue;
49 }
50 if (mkfifo(*argv, 0777) < 0) {
51 (void)fprintf(stderr, "mkfifo: %s: %s\n",
52 *argv, strerror(errno));
53 exitval |= 1;
54 }
55 }
56 exit(exitval);
57}
58
59build(path)
60 char *path;
61{
62 register char *p;
63 struct stat sb;
64
65 for (p = path; *p; p++) {
66 if (*p != '/')
67 continue;
68 if (stat(path, &sb)) {
69 if (errno != ENOENT || mkdir(path, 0777) < 0) {
70 (void)fprintf(stderr, "mkdir: %s: %s\n",
71 path, strerror(errno));
72 return(1);
73 }
74 }
75 *p = '/';
76 }
77 return(0);
78}
79
80usage()
81{
82 (void)fprintf(stderr, "usage: mkfifo [-p] fifoname ...\n");
83 exit(1);
84}