From 450b65e2e58d9888190d664a2e62eba89463775b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 21 Jan 2020 13:03:49 +1100 Subject: [PATCH] posix/fd: add an `ftruncate` wrapper --- posix/fd.cpp | 10 ++++++++++ posix/fd.hpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/posix/fd.cpp b/posix/fd.cpp index c910d8b1..115bfd93 100644 --- a/posix/fd.cpp +++ b/posix/fd.cpp @@ -215,6 +215,16 @@ fd::lseek (off_t offset, int whence) } +/////////////////////////////////////////////////////////////////////////////// +void +fd::truncate (off_t length) +{ + error::try_call ( + ::ftruncate, m_fd, length + ); +} + + /////////////////////////////////////////////////////////////////////////////// fd::operator int (void) const { diff --git a/posix/fd.hpp b/posix/fd.hpp index cc67f50f..1064b9b0 100644 --- a/posix/fd.hpp +++ b/posix/fd.hpp @@ -73,6 +73,10 @@ namespace cruft::posix { [[nodiscard]] off_t lseek (off_t offset, int whence); + //--------------------------------------------------------------------- + void truncate (off_t length); + + /////////////////////////////////////////////////////////////////////// operator int (void) const; int native (void) const { return m_fd; }