summaryrefslogtreecommitdiff
path: root/sbin/mknod/mknod.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-04-18 19:40:42 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-04-18 19:40:42 +0000
commit4d9f93dd72e2e01f1a67a9921877781abbdba645 (patch)
tree1f35d0a77aa42378c5028aec45d0fec4e98dca97 /sbin/mknod/mknod.c
parente5c20e136bcb15eb3420a59a8c1e38f3210e6171 (diff)
merge mknod and mkfifo, support 'p' in mknod
Diffstat (limited to 'sbin/mknod/mknod.c')
-rw-r--r--sbin/mknod/mknod.c131
1 files changed, 109 insertions, 22 deletions
diff --git a/sbin/mknod/mknod.c b/sbin/mknod/mknod.c
index 4f8549ecf0d..bf8ac60a0f1 100644
--- a/sbin/mknod/mknod.c
+++ b/sbin/mknod/mknod.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $ */
+/* $OpenBSD: mknod.c,v 1.6 1999/04/18 19:40:41 millert Exp $ */
/* $NetBSD: mknod.c,v 1.8 1995/08/11 00:08:18 jtc Exp $ */
/*
- * Copyright (c) 1989, 1993
+ * Copyright (c) 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mknod.c,v 1.6 1999/04/18 19:40:41 millert Exp $";
#endif
#endif /* not lint */
@@ -55,43 +55,104 @@ static char rcsid[] = "$OpenBSD: mknod.c,v 1.5 1997/10/04 19:30:16 deraadt Exp $
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
+#include <locale.h>
#include <err.h>
-static void usage();
+extern char *__progname;
+
+int domknod __P((int, char **, mode_t));
+int domkfifo __P((int, char **, mode_t));
+void usage __P((int));
int
main(argc, argv)
int argc;
char **argv;
{
- dev_t dev;
- char *endp;
- u_int major, minor;
+ int ch, ismkfifo = 0;
+ void *set = NULL;
mode_t mode;
- if (argc != 5) {
- usage();
- /* NOTREACHED */
+ setlocale (LC_ALL, "");
+
+ if (strcmp(__progname, "mkfifo") == 0)
+ ismkfifo = 1;
+
+ while ((ch = getopt(argc, argv, "m:")) != -1)
+ switch(ch) {
+ case 'm':
+ if (!(set = setmode(optarg))) {
+ errx(1, "invalid file mode.");
+ /* NOTREACHED */
+ }
+
+ /*
+ * In symbolic mode strings, the + and - operators are
+ * interpreted relative to an assumed initial mode of
+ * a=rw.
+ */
+ mode = getmode (set, 0666);
+ free(set);
+ break;
+ case '?':
+ default:
+ usage(ismkfifo);
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argv[0] == NULL)
+ usage(ismkfifo);
+ if (!ismkfifo) {
+ if (argc == 2 && argv[1][0] == 'p') {
+ ismkfifo = 2;
+ argc--;
+ argv[1] = NULL;
+ } else if (argc != 4) {
+ usage(ismkfifo);
+ /* NOTREACHED */
+ }
}
- mode = 0666;
- if (argv[2][0] == 'c')
+ /* The default mode is the value of the bitwise inclusive or of
+ S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH */
+ if (!set)
+ mode = 0666;
+
+ if (ismkfifo)
+ exit(domkfifo(argc, argv, mode));
+ else
+ exit(domknod(argc, argv, mode));
+}
+
+int
+domknod(argc, argv, mode)
+ int argc;
+ char **argv;
+ mode_t mode;
+{
+ dev_t dev;
+ char *endp;
+ u_int major, minor;
+
+ if (argv[1][0] == 'c')
mode |= S_IFCHR;
- else if (argv[2][0] == 'b')
+ else if (argv[1][0] == 'b')
mode |= S_IFBLK;
else {
errx(1, "node must be type 'b' or 'c'.");
/* NOTREACHED */
}
- major = (long)strtoul(argv[3], &endp, 10);
- if (endp == argv[3] || *endp != '\0') {
+ major = (long)strtoul(argv[2], &endp, 10);
+ if (endp == argv[2] || *endp != '\0') {
errx(1, "non-numeric major number.");
/* NOTREACHED */
}
- minor = (long)strtoul(argv[4], &endp, 10);
- if (endp == argv[4] || *endp != '\0') {
+ minor = (long)strtoul(argv[3], &endp, 10);
+ if (endp == argv[3] || *endp != '\0') {
errx(1, "non-numeric minor number.");
/* NOTREACHED */
}
@@ -100,17 +161,43 @@ main(argc, argv)
errx(1, "major or minor number too large");
/* NOTREACHED */
}
- if (mknod(argv[1], mode, dev) < 0) {
- err(1, "%s", argv[1]);
+ if (mknod(argv[0], mode, dev) < 0) {
+ err(1, "%s", argv[0]);
/* NOTREACHED */
}
+ return(0);
+}
- exit(0);
+int
+domkfifo(argc, argv, mode)
+ int argc;
+ char **argv;
+ mode_t mode;
+{
+ int rv;
+
+ for (rv = 0; *argv; ++argv) {
+ if (mkfifo(*argv, mode) < 0) {
+ warn("%s", *argv);
+ rv = 1;
+ }
+ }
+ return(rv);
}
void
-usage()
+usage(ismkfifo)
+ int ismkfifo;
{
- fprintf(stderr, "usage: mknod name [b | c] major minor\n");
+
+ if (ismkfifo == 1)
+ (void)fprintf(stderr, "usage: %s [-m mode] fifoname ...\n",
+ __progname);
+ else {
+ (void)fprintf(stderr, "usage: %s [-m mode] name [b | c] major minor\n",
+ __progname);
+ (void)fprintf(stderr, "usage: %s [-m mode] name p\n",
+ __progname);
+ }
exit(1);
}