Forráskód Böngészése

LibCore: Add syscall wrapper for close()

Andreas Kling 3 éve
szülő
commit
4bf08e4d52

+ 8 - 0
Userland/Libraries/LibCore/System.cpp

@@ -10,6 +10,7 @@
 #include <fcntl.h>
 #include <stdarg.h>
 #include <sys/mman.h>
+#include <unistd.h>
 
 #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
     if ((rc) < 0) {                                                  \
@@ -115,4 +116,11 @@ ErrorOr<int> open(StringView path, int options, ...)
 #endif
 }
 
+ErrorOr<void> close(int fd)
+{
+    if (::close(fd) < 0)
+        return Error::from_syscall("close"sv, -errno);
+    return {};
+}
+
 }

+ 1 - 0
Userland/Libraries/LibCore/System.h

@@ -23,5 +23,6 @@ ErrorOr<int> fcntl(int fd, int command, ...);
 ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});
 ErrorOr<void> munmap(void* address, size_t);
 ErrorOr<int> open(StringView path, int options, ...);
+ErrorOr<void> close(int fd);
 
 }