From 8c831a69068a4b0b4c31cf2716d446a91b473509 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 18 Mar 2023 09:13:31 +0100 Subject: [PATCH] libc: Add mknod() --- apps/hello.c | 4 ++-- libc/include/sys/stat.h | 3 +++ libc/src/sys/stat.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/hello.c b/apps/hello.c index 192b335a..cd338452 100644 --- a/apps/hello.c +++ b/apps/hello.c @@ -10,7 +10,7 @@ int main() printf("Hello world!\n"); mkdir("/dev", 0755); - if (syscall(SYS_mknod, "/dev/console", 0666, makedev(1, 0)) < 0) + if (mknod("/dev/console", 0666, makedev(1, 0)) < 0) { perror("mknod"); return 1; @@ -19,6 +19,6 @@ int main() const char* str = "Hello from /dev!"; FILE* f = fopen("/dev/console", "r+"); - fwrite(str, 1, strlen(str), f); + if (f) fwrite(str, 1, strlen(str), f); if (f) fclose(f); } diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index dc89b780..1b77922d 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -14,6 +14,9 @@ extern "C" /* Create a directory. */ int mkdir(const char* path, mode_t mode); + /* Create a special file. */ + int mknod(const char* path, mode_t mode, dev_t dev); + #ifdef __cplusplus } #endif diff --git a/libc/src/sys/stat.cpp b/libc/src/sys/stat.cpp index 1316d0a3..8775170d 100644 --- a/libc/src/sys/stat.cpp +++ b/libc/src/sys/stat.cpp @@ -10,4 +10,10 @@ extern "C" long rc = syscall(SYS_mkdir, path, mode); __errno_return(rc, int); } + + int mknod(const char* path, mode_t mode, dev_t dev) + { + long rc = syscall(SYS_mknod, path, mode, dev); + __errno_return(rc, int); + } }