summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/System.cpp
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2022-03-29 19:24:06 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-03-29 21:28:29 -0700
commit0015040ebd2e82edc4d6fc00af8709ad8d850b4f (patch)
tree4d51927ce76df8a3a20476ffed60d77285e8c1cd /Userland/Libraries/LibCore/System.cpp
parentf4aef35e6e62f028f40e89c2bb6ab433d6071ea8 (diff)
downloadserenity-0015040ebd2e82edc4d6fc00af8709ad8d850b4f.zip
LibCore: Add syscall wrapper for access()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r--Userland/Libraries/LibCore/System.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index 01fe7e50ae..00fdfb7f6e 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2021, Kenneth Myhra <kennethmyhra@gmail.com>
+ * Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@gmail.com>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
*
@@ -1119,4 +1119,20 @@ ErrorOr<void> unlockpt(int fildes)
return {};
}
+ErrorOr<void> access(StringView pathname, int mode)
+{
+ if (pathname.is_null())
+ return Error::from_syscall("access"sv, -EFAULT);
+
+#ifdef __serenity__
+ int rc = ::syscall(Syscall::SC_access, pathname.characters_without_null_termination(), pathname.length(), mode);
+ HANDLE_SYSCALL_RETURN_VALUE("access"sv, rc, {});
+#else
+ String path_string = pathname;
+ if (::access(path_string.characters(), mode) < 0)
+ return Error::from_syscall("access"sv, -errno);
+ return {};
+#endif
+}
+
}