Skip to content

Commit

Permalink
Fix ftruncate build (POSIX version). (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerstu authored Nov 24, 2021
1 parent 0f9a743 commit 1135c59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/os/TempFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

6 changes: 1 addition & 5 deletions src/os/TempFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1135c59

Please sign in to comment.