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:
commit
2f8ee4578f
8 changed files with 26 additions and 62 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue