aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-05-06 12:01:40 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-05-06 12:01:40 +0200
commit2f8ee4578f0784411a2b14620d598f0d1d604122 (patch)
treee6ec8def584ce57ebf41f927e0f66d3c4ecb715a /src/libutil/util.cc
parent6f3244ce4517cc51ef3ffd39025152aa7046ef69 (diff)
parent74a1bfdcab03d3c6ecb9353f4bae0a0c550ddb98 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index aa695e174..4c8e2b26d 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -317,19 +317,16 @@ string readFile(int fd)
if (fstat(fd, &st) == -1)
throw SysError("statting file");
- std::vector<unsigned char> buf(st.st_size);
- readFull(fd, buf.data(), st.st_size);
-
- return string((char *) buf.data(), st.st_size);
+ return drainFD(fd, true, st.st_size);
}
-string readFile(const Path & path, bool drain)
+string readFile(const Path & path)
{
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (!fd)
throw SysError(format("opening file '%1%'") % path);
- return drain ? drainFD(fd.get()) : readFile(fd.get());
+ return readFile(fd.get());
}
@@ -676,9 +673,9 @@ void writeFull(int fd, const string & s, bool allowInterrupts)
}
-string drainFD(int fd, bool block)
+string drainFD(int fd, bool block, const size_t reserveSize)
{
- StringSink sink;
+ StringSink sink(reserveSize);
drainFD(fd, sink, block);
return std::move(*sink.s);
}