diff options
author | Brian Orr <brianorr@google.com> | 2021-05-10 11:39:59 -0700 |
---|---|---|
committer | Brian Orr <brianorr@google.com> | 2021-05-10 11:39:59 -0700 |
commit | f79cb91b4218a68642c94a01defc0594e742b3f4 (patch) | |
tree | 01ec931931503ed80f181b2d85efb5df0079e4ba /common/utils.h | |
parent | d650df1d306a5a828e7b13a8cc954196fea44992 (diff) | |
parent | 3d4e6e0d7ed2b609e0fe2b4d0fcb250808f97476 (diff) |
Merge SP1A.210510.001
Change-Id: If7498b293041f2ae00fd93563417d60a0c13e7c9
Diffstat (limited to 'common/utils.h')
-rw-r--r-- | common/utils.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/common/utils.h b/common/utils.h index 5f6e4757..59f236ef 100644 --- a/common/utils.h +++ b/common/utils.h @@ -399,13 +399,19 @@ class ScopedTempFile { // If |open_fd| is true, a writable file descriptor will be opened for this // file. - explicit ScopedTempFile(const std::string& pattern, bool open_fd = false) { + // If |truncate_size| is non-zero, truncate file to that size on creation. + explicit ScopedTempFile(const std::string& pattern, + bool open_fd = false, + size_t truncate_size = 0) { CHECK(utils::MakeTempFile(pattern, &path_, open_fd ? &fd_ : nullptr)); unlinker_.reset(new ScopedPathUnlinker(path_)); if (open_fd) { CHECK_GE(fd_, 0); fd_closer_.reset(new ScopedFdCloser(&fd_)); } + if (truncate_size > 0) { + CHECK_EQ(0, truncate(path_.c_str(), truncate_size)); + } } virtual ~ScopedTempFile() = default; |