From 387e7e19d7eb5444be8da8e99ed7491989dc1cbb Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 27 Sep 2007 15:25:55 +0200 Subject: strbuf_read_file enhancement, and use it. * make strbuf_read_file take a size hint (works like strbuf_read) * use it in a couple of places. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- builtin-apply.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'builtin-apply.c') diff --git a/builtin-apply.c b/builtin-apply.c index 740623e6c0..fec96a8d9d 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1425,8 +1425,6 @@ static void show_stats(struct patch *patch) static int read_old_data(struct stat *st, const char *path, struct strbuf *buf) { - int fd; - switch (st->st_mode & S_IFMT) { case S_IFLNK: strbuf_grow(buf, st->st_size); @@ -1435,14 +1433,8 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf) strbuf_setlen(buf, st->st_size); return 0; case S_IFREG: - fd = open(path, O_RDONLY); - if (fd < 0) - return error("unable to open %s", path); - if (strbuf_read(buf, fd, st->st_size) < 0) { - close(fd); - return -1; - } - close(fd); + if (strbuf_read_file(buf, path, st->st_size) != st->st_size) + return error("unable to open or read %s", path); convert_to_git(path, buf->buf, buf->len, buf); return 0; default: -- cgit v1.2.3