From 4a213869f2f798399cd3ea6a9985b0fc988cbff3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Nov 2021 12:16:07 +0100 Subject: [PATCH] LibCore: Add syscall wrapper for ftruncate() --- Userland/Libraries/LibCore/System.cpp | 7 +++++++ Userland/Libraries/LibCore/System.h | 1 + 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index ccaa2ed5cb2..05a7341f24e 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -123,4 +123,11 @@ ErrorOr close(int fd) return {}; } +ErrorOr ftruncate(int fd, off_t length) +{ + if (::ftruncate(fd, length) < 0) + return Error::from_syscall("ftruncate"sv, -errno); + return {}; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index de2259683f4..aa2a01d5f5a 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -24,5 +24,6 @@ ErrorOr mmap(void* address, size_t, int protection, int flags, int fd, of ErrorOr munmap(void* address, size_t); ErrorOr open(StringView path, int options, ...); ErrorOr close(int fd); +ErrorOr ftruncate(int fd, off_t length); }