浏览代码

LibCore: Add syscall wrapper for ftruncate()

Andreas Kling 3 年之前
父节点
当前提交
4a213869f2
共有 2 个文件被更改,包括 8 次插入0 次删除
  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);
 
 }