From 1135c596fdd0099ae104ec643f0a1be655ceb537 Mon Sep 17 00:00:00 2001 From: Stuart W Baker Date: Wed, 24 Nov 2021 10:47:13 -0600 Subject: [PATCH] Fix ftruncate build (POSIX version). (#584) --- src/os/TempFile.cxx | 11 +++++++++++ src/os/TempFile.hxx | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/os/TempFile.cxx b/src/os/TempFile.cxx index a422f4075..38b6c2835 100644 --- a/src/os/TempFile.cxx +++ b/src/os/TempFile.cxx @@ -66,3 +66,14 @@ TempFile::TempFile(const TempDir& dir, const string& basename) fileName_.c_str(); fd_ = mkstemp((char*)fileName_.c_str()); } + +// +// TempFile::rewrite() +// +void TempFile::rewrite(const string& s) +{ + ::lseek(fd_, 0, SEEK_SET); + ::ftruncate(fd_, 0); + write(s); +} + diff --git a/src/os/TempFile.hxx b/src/os/TempFile.hxx index 0b9a30ac9..bec4b181e 100644 --- a/src/os/TempFile.hxx +++ b/src/os/TempFile.hxx @@ -115,11 +115,7 @@ public: /// writes the given data to the temporary file from offset 0. @param s is /// the data to write. - void rewrite(const string& s) { - ::lseek(fd_, 0, SEEK_SET); - ::ftruncate(fd_, 0); - write(s); - } + void rewrite(const string& s); /// writes the given data to the temporary file. @param s is the data to /// write.