aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache.h1
-rw-r--r--write_or_die.c16
2 files changed, 17 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index cc872440e..e6b716495 100644
--- a/cache.h
+++ b/cache.h
@@ -428,6 +428,7 @@ extern char *git_commit_encoding;
extern char *git_log_output_encoding;
extern int copy_fd(int ifd, int ofd);
+extern void read_or_die(int fd, void *buf, size_t count);
extern void write_or_die(int fd, const void *buf, size_t count);
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
diff --git a/write_or_die.c b/write_or_die.c
index bfe4eeb64..8cf648602 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;