diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2022-01-14 17:08:46 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-24 14:01:58 +0330 |
commit | 9fe1ebebdcdc7af78606b359b45f34f5b87a0ca6 (patch) | |
tree | b7002fdda87839fbdd3d9aa1c8583aeebe469aba /Userland | |
parent | 38472d7e025e548ba62585bbf9e071e415be926a (diff) | |
download | serenity-9fe1ebebdcdc7af78606b359b45f34f5b87a0ca6.zip |
LibCore: Add mknod() syscall wrapper
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.h | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 7b942b094d..3bb1c698fd 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -928,4 +928,21 @@ ErrorOr<Vector<gid_t>> getgroups() return groups; } +ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev) +{ + if (pathname.is_null()) + return Error::from_syscall("mknod"sv, -EFAULT); + +#ifdef __serenity__ + Syscall::SC_mknod_params params { { pathname.characters_without_null_termination(), pathname.length() }, mode, dev }; + int rc = syscall(SC_mknod, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("mknod"sv, rc, {}); +#else + String path_string = pathname; + if (::mknod(path_string.characters(), mode, dev) < 0) + return Error::from_syscall("mknod"sv, -errno); + return {}; +#endif +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 0bba07f5bc..fb6ba508ed 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -135,4 +135,6 @@ ErrorOr<void> getsockname(int sockfd, struct sockaddr*, socklen_t*); ErrorOr<void> getpeername(int sockfd, struct sockaddr*, socklen_t*); ErrorOr<void> socketpair(int domain, int type, int protocol, int sv[2]); ErrorOr<Vector<gid_t>> getgroups(); +ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev); + } |