commit 4542db4e40f68bafaa4586d89fce4567c2d2b71e
Author:     Michael Forney <[email protected]>
AuthorDate: Sun Mar 1 16:30:56 2020 -0800
Commit:     Michael Forney <[email protected]>
CommitDate: Sun Mar 1 16:33:18 2020 -0800

    mknod: Add support for making FIFOs

diff --git a/mknod.1 b/mknod.1
index 180b9cd..2541107 100644
--- a/mknod.1
+++ b/mknod.1
@@ -8,25 +8,32 @@
 .Nm
 .Op Fl m Ar mode
 .Ar name
-.Ar type
+.Cm b Ns | Ns Cm c Ns | Ns Cm u
 .Ar major
 .Ar minor
-.Sh DESCRIPTION
 .Nm
-creates a special device file named
+.Op Fl m Ar mode
 .Ar name
-with major number
-.Ar major ,
-and minor number
-.Ar minor .
-.Ar type
-specifies what kind of special file will be created and must be one of:
+.Cm p
+.Sh DESCRIPTION
+.Nm
+creates a special file named
+.Ar name .
+.Pp
+The following special file types are supported:
 .Bl -tag -width Ds
-.It Ar u | c
-A character device.
-.It Ar b
+.It Cm b
 A block device.
+.It Cm c | u
+A character device.
+.It Cm p
+A named pipe.
 .El
+.Pp
+Block and character devices are created with major number
+.Ar major ,
+and minor number
+.Ar minor .
 .Sh OPTIONS
 .Bl -tag -width Ds
 .It Fl m
diff --git a/mknod.c b/mknod.c
index b4f7e5d..a519ecb 100644
--- a/mknod.c
+++ b/mknod.c
@@ -16,7 +16,9 @@
 static void
 usage(void)
 {
-       eprintf("usage: %s [-m mode] name type major minor\n", argv0);
+       eprintf("usage: %s [-m mode] name b|c|u major minor\n"
+               "       %s [-m mode] name p\n",
+               argv0, argv0);
 }
 
 int
@@ -33,7 +35,7 @@ main(int argc, char *argv[])
                usage();
        } ARGEND;
 
-       if (argc != 4)
+       if (argc < 2)
                usage();
 
        if (strlen(argv[1]) != 1)
@@ -46,12 +48,23 @@ main(int argc, char *argv[])
        case 'c':
                mode |= S_IFCHR;
                break;
+       case 'p':
+               mode |= S_IFIFO;
+               break;
        default:
        invalid:
                eprintf("invalid type '%s'\n", argv[1]);
        }
 
-       dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), estrtonum(argv[3], 0, 
LLONG_MAX));
+       if (S_ISFIFO(mode)) {
+               if (argc != 2)
+                       usage();
+               dev = 0;
+       } else {
+               if (argc != 4)
+                       usage();
+               dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), 
estrtonum(argv[3], 0, LLONG_MAX));
+       }
 
        if (mknod(argv[0], mode, dev) == -1)
                eprintf("mknod %s:", argv[0]);

Reply via email to