summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-12-16 20:27:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-16 22:48:17 +0100
commit01c2756e9a6796d56372e2776854c6378b00c0eb (patch)
tree85cd27602f29d89126383a586c1dfb179ac6542d /Userland/Libraries/LibCore
parentf69bd3bd46534f3e675d32e86d360830e5fab100 (diff)
downloadserenity-01c2756e9a6796d56372e2776854c6378b00c0eb.zip
LibCore: Add syscall wrapper for mkdir()
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/System.cpp15
-rw-r--r--Userland/Libraries/LibCore/System.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index f84495a853..c86c22f083 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -465,4 +465,19 @@ ErrorOr<void> symlink(StringView target, StringView link_path)
#endif
}
+ErrorOr<void> mkdir(StringView path, mode_t mode)
+{
+ if (path.is_null())
+ return Error::from_errno(EFAULT);
+#ifdef __serenity__
+ int rc = syscall(SC_mkdir, path.characters_without_null_termination(), path.length(), mode);
+ HANDLE_SYSCALL_RETURN_VALUE("mkdir"sv, rc, {});
+#else
+ String path_string = path;
+ if (::mkdir(path_string.characters(), mode) < 0)
+ return Error::from_syscall("mkdir"sv, -errno);
+ return {};
+#endif
+}
+
}
diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h
index c5bfcb28b8..7032b5553e 100644
--- a/Userland/Libraries/LibCore/System.h
+++ b/Userland/Libraries/LibCore/System.h
@@ -63,5 +63,6 @@ ErrorOr<void> setgid(gid_t);
ErrorOr<void> setegid(gid_t);
ErrorOr<bool> isatty(int fd);
ErrorOr<void> symlink(StringView target, StringView link_path);
+ErrorOr<void> mkdir(StringView path, mode_t);
}