提交 75025ccd 编写于 作者: S Shawn O. Pearce 提交者: Junio C Hamano

Create read_or_die utility routine.

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: NShawn O. Pearce <spearce@spearce.org>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 2dc3a234
......@@ -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);
......
#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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册