forked from lix-project/lix
* Fix handling of pipes (read(2) may not return the required
number of bytes in one call).
This commit is contained in:
parent
822c072cfa
commit
c834a5c597
10
src/nix.cc
10
src/nix.cc
|
@ -250,11 +250,13 @@ struct StdinSource : RestoreSource
|
||||||
{
|
{
|
||||||
virtual void operator () (const unsigned char * data, unsigned int len)
|
virtual void operator () (const unsigned char * data, unsigned int len)
|
||||||
{
|
{
|
||||||
|
while (len) {
|
||||||
ssize_t res = read(STDIN_FILENO, (char *) data, len);
|
ssize_t res = read(STDIN_FILENO, (char *) data, len);
|
||||||
if (res == -1)
|
if (res == -1) throw SysError("reading from stdin");
|
||||||
throw SysError("reading from stdin");
|
if (res == 0) throw SysError("unexpected end-of-file on stdin");
|
||||||
if (res != (ssize_t) len)
|
len -= res;
|
||||||
throw Error("not enough data available on stdin");
|
data += res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue