summaryrefslogtreecommitdiff
path: root/builtin-apply.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-apply.c')
-rw-r--r--builtin-apply.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 740623e..fec96a8 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: