commit: f9196e3f0294f37c36c90faaeb9440344dbdbaf7
parent 1196a7778a82234d8d6b3e4bc994ec50fd9002d5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 23 Apr 2024 18:55:11 +0200
cmd/mkfifo: new
Diffstat:
8 files changed, 147 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -102,6 +102,10 @@ cmd/mknod: cmd/mknod.c lib/mode.c Makefile
rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
$(CC) -std=c99 $(CFLAGS) -o $@ cmd/mknod.c lib/mode.c $(LDFLAGS) $(LDSTATIC)
+cmd/mkfifo: cmd/mkfifo.c lib/mode.c Makefile
+ rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
+ $(CC) -std=c99 $(CFLAGS) -o $@ cmd/mkfifo.c lib/mode.c $(LDFLAGS) $(LDSTATIC)
+
cmd/seq: cmd/seq.c Makefile
rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
$(CC) -std=c99 $(CFLAGS) -o $@ cmd/seq.c -lm $(LDFLAGS) $(LDSTATIC)
diff --git a/cmd/mkfifo.1 b/cmd/mkfifo.1
@@ -0,0 +1,35 @@
+.\" utils-std: Collection of commonly available Unix tools
+.\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+.\" SPDX-License-Identifier: MPL-2.0
+.Dd 2024-04-23
+.Dt MKFIFO 1
+.Os
+.Sh NAME
+.Nm mkfifo
+.Nd Create FIFO special files
+.Sh SYNOPSIS
+.Nm
+.Op Fl m Ar mode
+.Ar file ...
+.Sh DESCRIPTION
+.Nm
+creates a FIFO special file at
+.Ar file .
+.Sh OPTIONS
+.Bl -tag -width _m_mode
+.It Fl m Ar mode
+Set permission of new special file,
+relative to 0666/rw-rw-rw using the same format as
+.Xr chmod 1 .
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr mknod 1
+.Sh STANDARDS
+.Nm
+should be compliant with the
+.St -p1003.1-2008
+specification.
+.Sh AUTHORS
+.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me
diff --git a/cmd/mkfifo.c b/cmd/mkfifo.c
@@ -0,0 +1,80 @@
+// utils-std: Collection of commonly available Unix tools
+// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+// SPDX-License-Identifier: MPL-2.0
+
+#define _POSIX_C_SOURCE 200809L
+
+#include "../lib/mode.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h> // fprintf
+#include <stdlib.h> // abort
+#include <string.h> // strerror
+#include <sys/stat.h> // mkfifo
+#include <unistd.h> // getopt
+
+mode_t filemask;
+
+static void
+usage()
+{
+ fprintf(stderr, "Usage: mkfifo [-m mode] file\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ mode_t mode = 0666;
+
+ const char *errstr = NULL;
+
+ int c = -1;
+ while((c = getopt(argc, argv, ":m:")) != -1)
+ {
+ switch(c)
+ {
+ case 'm':
+ mode = new_mode(optarg, 0666, &errstr);
+ if(errstr != NULL)
+ {
+ fprintf(stderr, "mkfifo: Failed parsing '%s': %s\n", optarg, errstr);
+ return 1;
+ }
+ break;
+ case ':':
+ fprintf(stderr, "mkfifo: Error: Missing operand for option: '-%c'\n", optopt);
+ usage();
+ return 1;
+ case '?':
+ fprintf(stderr, "mkfifo: Error: Unrecognised option: '-%c'\n", optopt);
+ usage();
+ return 1;
+ default:
+ abort();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ assert(errno == 0);
+
+ if(argc < 1)
+ {
+ fprintf(stderr, "mkfifo: Missing file argument\n");
+ usage();
+ return 1;
+ }
+
+ for(int i = 0; i < argc; i++)
+ {
+ if(mkfifo(argv[i], mode) != 0)
+ {
+ fprintf(stderr, "mkfifo: Failed creating FIFO at '%s': %s\n", argv[i], strerror(errno));
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/coreutils.txt b/coreutils.txt
@@ -44,7 +44,7 @@ logname: Done
ls: ?
md5sum: No
mkdir: Done
-mkfifo: ?
+mkfifo: Done
mknod: Done
mktemp: Todo
mv: Todo
diff --git a/lsb_commands.txt b/lsb_commands.txt
@@ -78,7 +78,7 @@ make: out of scope
man: out of scope
md5sum: No
mkdir: Done
-mkfifo: ?
+mkfifo: Done
mknod: Done
mktemp: Todo
more: No
diff --git a/makeless.sh b/makeless.sh
@@ -25,6 +25,7 @@ $CC -std=c99 $CFLAGS -o cmd/id cmd/id.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/link cmd/link.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/logname cmd/logname.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/mkdir cmd/mkdir.c lib/mode.c $LDFLAGS $LDSTATIC
+$CC -std=c99 $CFLAGS -o cmd/mkfifo cmd/mkfifo.c lib/mode.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/mknod cmd/mknod.c lib/mode.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/nice cmd/nice.c $LDFLAGS $LDSTATIC
$CC -std=c99 $CFLAGS -o cmd/nohup cmd/nohup.c $LDFLAGS $LDSTATIC
diff --git a/posix_utilities.txt b/posix_utilities.txt
@@ -81,7 +81,7 @@ make: no, devtool
man: no, external (for example with mandoc)
mesg: no, external (linked to wall and write)
mkdir: done
-mkfifo
+mkfifo: done
more: no
mv
newgrp
diff --git a/test-cmd/mkfifo.t b/test-cmd/mkfifo.t
@@ -0,0 +1,24 @@
+#!/usr/bin/env cram
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+ $ export PATH="$TESTDIR/../cmd:$PATH"
+
+ $ test "$(command -v mkfifo)" = "$TESTDIR/../cmd/mkfifo"
+
+ $ mkfifo foo
+ $ test -p foo
+ $ rm foo
+
+ $ touch exists
+ $ mkfifo exists
+ mkfifo: Failed creating FIFO at 'exists': File exists
+ [1]
+ $ rm exists
+
+ $ mkfifo /dev/null/e/no/ent
+ mkfifo: Failed creating FIFO at '/dev/null/e/no/ent': Not a directory
+ [1]
+
+ $ find .
+ .