diff options
Diffstat (limited to 'write_or_die.c')
-rw-r--r-- | write_or_die.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/write_or_die.c b/write_or_die.c index 650f13fc01..6db1d3123d 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -1,5 +1,21 @@ #include "cache.h" +void read_or_die(int fd, void *buf, size_t count) +{ + char *p = buf; + ssize_t loaded; + + while (count > 0) { + loaded = xread(fd, p, count); + if (loaded == 0) + die("unexpected end of file"); + else if (loaded < 0) + die("read error (%s)", strerror(errno)); + count -= loaded; + p += loaded; + } +} + void write_or_die(int fd, const void *buf, size_t count) { const char *p = buf; |