1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 19:57:59 +02:00

* Argh, another short-write problem. Added wrappers around

read()/write() to fix this once and for all.
This commit is contained in:
Eelco Dolstra 2003-07-20 21:11:43 +00:00
parent 667a6afb9d
commit 7984cfc7c1
9 changed files with 46 additions and 36 deletions

View file

@ -159,3 +159,26 @@ void debug(const format & f)
{
msg(format("debug: %1%") % f.str());
}
void readFull(int fd, unsigned char * buf, size_t count)
{
while (count) {
ssize_t res = read(fd, (char *) buf, count);
if (res == -1) throw SysError("reading from file");
if (res == 0) throw Error("unexpected end-of-file");
count -= res;
buf += res;
}
}
void writeFull(int fd, const unsigned char * buf, size_t count)
{
while (count) {
ssize_t res = write(fd, (char *) buf, count);
if (res == -1) throw SysError("writing to file");
count -= res;
buf += res;
}
}