From 892da127d044b74dfa10c1558a973fcec3c89d6b Mon Sep 17 00:00:00 2001 From: Romain Chardiny Date: Wed, 27 Mar 2024 06:53:09 +0100 Subject: [PATCH] LibCore: Add wrapper for fsync() --- 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 9b7ee12bb4a..07ce89f39c3 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -598,6 +598,13 @@ ErrorOr ftruncate(int fd, off_t length) return {}; } +ErrorOr fsync(int fd) +{ + if (::fsync(fd) < 0) + return Error::from_syscall("fsync"sv, -errno); + return {}; +} + ErrorOr stat(StringView path) { if (!path.characters_without_null_termination()) diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index a57d1f8faf0..fb74bae9926 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -127,6 +127,7 @@ ErrorOr open(StringView path, int options, mode_t mode = 0); ErrorOr openat(int fd, StringView path, int options, mode_t mode = 0); ErrorOr close(int fd); ErrorOr ftruncate(int fd, off_t length); +ErrorOr fsync(int fd); ErrorOr stat(StringView path); ErrorOr lstat(StringView path); ErrorOr read(int fd, Bytes buffer);