summaryrefslogtreecommitdiff
path: root/Userland
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
parentf4aef35e6e62f028f40e89c2bb6ab433d6071ea8 (diff)
downloadserenity-0015040ebd2e82edc4d6fc00af8709ad8d850b4f.zip
LibCore: Add syscall wrapper for access()
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibCore/System.cpp18
-rw-r--r--Userland/Libraries/LibCore/System.h3
2 files changed, 19 insertions, 2 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
+}
+
}
diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h
index b8bf14eae4..2489860883 100644
--- a/Userland/Libraries/LibCore/System.h
+++ b/Userland/Libraries/LibCore/System.h
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 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>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -150,5 +150,6 @@ ErrorOr<void> setenv(StringView, StringView, bool);
ErrorOr<int> posix_openpt(int flags);
ErrorOr<void> grantpt(int fildes);
ErrorOr<void> unlockpt(int fildes);
+ErrorOr<void> access(StringView pathname, int mode);
}