summaryrefslogtreecommitdiff
path: root/common/utils.h
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2021-06-09 05:18:08 -0700
committerLinux Build Service Account <lnxbuild@localhost>2021-06-09 05:18:08 -0700
commitf476d74eefab00e5b40d54513a2621e664c70ddf (patch)
tree01ec931931503ed80f181b2d85efb5df0079e4ba /common/utils.h
parent0482fa15f58c1de5ead9e0e3e2aa1d593d18e6c2 (diff)
parentac7fc8e1debff1f57afe79f144d8d16a1a0ec470 (diff)
Merge ac7fc8e1debff1f57afe79f144d8d16a1a0ec470 on remote branch
Change-Id: I2cd41cefedfd492f9e20617ad9929ebf1cdde79e
Diffstat (limited to 'common/utils.h')
-rw-r--r--common/utils.h8
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;