1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00

Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-05-06 12:01:40 +02:00
commit 2f8ee4578f
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
8 changed files with 26 additions and 62 deletions

View file

@ -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);
}