print errno when reporting a system call error

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 3, 2017 at 17:16 UTC 5118d7f4e6e00b7eac3ce08a16392a732edc0b2b
3 files changed +6 -5
builtin/log.c
+2 -1
@@ -858,7 +858,8 @@ static int open_next_file(struct commit *commit, const char *subject,
858 printf("%s\n", filename.buf + outdir_offset);
859
860 if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL)
861 - return error(_("Cannot open patch file %s"), filename.buf);
861 + return error_errno(_("Cannot open patch file %s"),
862 + filename.buf);
863
864 strbuf_release(&filename);
865 return 0;
rerere.c
+2 -2
@@ -484,13 +484,13 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
484 io.input = fopen(path, "r");
485 io.io.wrerror = 0;
486 if (!io.input)
487 - return error("Could not open %s", path);
487 + return error_errno("Could not open %s", path);
488
489 if (output) {
490 io.io.output = fopen(output, "w");
491 if (!io.io.output) {
492 fclose(io.input);
493 - return error("Could not write %s", output);
493 + return error_errno("Could not write %s", output);
494 }
495 }
496
xdiff-interface.c
+2 -2
@@ -164,9 +164,9 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
164 size_t sz;
165
166 if (stat(filename, &st))
167 - return error("Could not stat %s", filename);
167 + return error_errno("Could not stat %s", filename);
168 if ((f = fopen(filename, "rb")) == NULL)
169 - return error("Could not open %s", filename);
169 + return error_errno("Could not open %s", filename);
170 sz = xsize_t(st.st_size);
171 ptr->ptr = xmalloc(sz ? sz : 1);
172 if (sz && fread(ptr->ptr, sz, 1, f) != 1) {