From 4e8a506f8aec09642f2da4c50cf67c163aacbefd Mon Sep 17 00:00:00 2001 From: Yuta Imazu Date: Tue, 18 Jun 2024 08:15:13 +0900 Subject: [PATCH] userland: add "mkfifo" command --- userland/Makefile | 2 ++ userland/lib/sys/stat.c | 6 ++++++ userland/lib/sys/stat.h | 1 + userland/mkfifo.c | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 userland/lib/sys/stat.c create mode 100644 userland/mkfifo.c diff --git a/userland/Makefile b/userland/Makefile index 16b5a686..c653d948 100644 --- a/userland/Makefile +++ b/userland/Makefile @@ -24,6 +24,7 @@ BIN_TARGET_NAMES := \ ls \ mandelbrot \ mkdir \ + mkfifo \ mount \ mouse-cursor \ moused \ @@ -63,6 +64,7 @@ LIB_OBJS := \ lib/stdio.o \ lib/stdlib.o \ lib/string.o \ + lib/sys/stat.o \ lib/syscall.o \ lib/time.o \ lib/unistd.o diff --git a/userland/lib/sys/stat.c b/userland/lib/sys/stat.c new file mode 100644 index 00000000..eea6c5fd --- /dev/null +++ b/userland/lib/sys/stat.c @@ -0,0 +1,6 @@ +#include "stat.h" +#include + +int mkfifo(const char* pathname, mode_t mode) { + return mknod(pathname, mode | S_IFIFO, 0); +} diff --git a/userland/lib/sys/stat.h b/userland/lib/sys/stat.h index 703ac2f2..8dd43914 100644 --- a/userland/lib/sys/stat.h +++ b/userland/lib/sys/stat.h @@ -4,3 +4,4 @@ int stat(const char* pathname, struct stat* buf); int mkdir(const char* pathname, mode_t mode); +int mkfifo(const char* pathname, mode_t mode); diff --git a/userland/mkfifo.c b/userland/mkfifo.c new file mode 100644 index 00000000..4e12f957 --- /dev/null +++ b/userland/mkfifo.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +int main(int argc, char* const argv[]) { + if (argc != 2) { + dprintf(STDERR_FILENO, "Usage: mkfifo NAME\n"); + return EXIT_FAILURE; + } + if (mkfifo(argv[1], 0) < 0) { + perror("mkfifo"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}