Browse Source

LibCore: Add syscall wrapper for ftruncate()

Andreas Kling 3 years ago
parent
commit
4a213869f2
2 changed files with 8 additions and 0 deletions
  1. 7 0
      Userland/Libraries/LibCore/System.cpp
  2. 1 0
      Userland/Libraries/LibCore/System.h

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

@@ -123,4 +123,11 @@ ErrorOr<void> close(int fd)
     return {};
 }
 
+ErrorOr<void> ftruncate(int fd, off_t length)
+{
+    if (::ftruncate(fd, length) < 0)
+        return Error::from_syscall("ftruncate"sv, -errno);
+    return {};
+}
+
 }

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

@@ -24,5 +24,6 @@ ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, of
 ErrorOr<void> munmap(void* address, size_t);
 ErrorOr<int> open(StringView path, int options, ...);
 ErrorOr<void> close(int fd);
+ErrorOr<void> ftruncate(int fd, off_t length);
 
 }