Skip to content

Commit

Permalink
userland: add "mkfifo" command
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmeh committed Jun 19, 2024
1 parent 9283d23 commit 4e8a506
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions userland/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ BIN_TARGET_NAMES := \
ls \
mandelbrot \
mkdir \
mkfifo \
mount \
mouse-cursor \
moused \
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions userland/lib/sys/stat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "stat.h"
#include <unistd.h>

int mkfifo(const char* pathname, mode_t mode) {
return mknod(pathname, mode | S_IFIFO, 0);
}
1 change: 1 addition & 0 deletions userland/lib/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
16 changes: 16 additions & 0 deletions userland/mkfifo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

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;
}

0 comments on commit 4e8a506

Please sign in to comment.