summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2dc3a23)
raw | patch | inline | side by side (parent: 2dc3a23)
author | Shawn O. Pearce <spearce@spearce.org> | |
Sat, 23 Dec 2006 07:33:55 +0000 (02:33 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 29 Dec 2006 19:36:44 +0000 (11:36 -0800) |
Like write_or_die read_or_die reads the entire length requested
or it kills the current process with a die call.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
or it kills the current process with a die call.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
write_or_die.c | patch | blob | history |
index cc872440ef85d9bead5df72879eba2bfe0b84347..e6b716495d615a351213f5f8dbc437d7136443b0 100644 (file)
--- a/cache.h
+++ b/cache.h
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 bfe4eeb6494c7076bf7f319cf11628f586142aa5..8cf6486025a0fffba889618ce07a0d4eadd139df 100644 (file)
--- a/write_or_die.c
+++ b/write_or_die.c
#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;