From 58e4e5118ae3707b417a19e8dc9224ac25c3f32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:21 +0700 Subject: usage.c: move format processing out of die_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fmt_with_err() will be shared with the coming error_errno() and warning_errno(). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/usage.c b/usage.c index 82ff131..8675d72 100644 --- a/usage.c +++ b/usage.c @@ -109,19 +109,11 @@ void NORETURN die(const char *err, ...) va_end(params); } -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err(char *buf, int n, const char *fmt) { - va_list params; - char fmt_with_err[1024]; char str_error[256], *err; int i, j; - if (die_is_recursing()) { - fputs("fatal: recursion detected in die_errno handler\n", - stderr); - exit(128); - } - err = strerror(errno); for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) { if ((str_error[j++] = err[i++]) != '%') @@ -136,10 +128,23 @@ void NORETURN die_errno(const char *fmt, ...) } } str_error[j] = 0; - snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error); + snprintf(buf, n, "%s: %s", fmt, str_error); + return buf; +} + +void NORETURN die_errno(const char *fmt, ...) +{ + char buf[1024]; + va_list params; + + if (die_is_recursing()) { + fputs("fatal: recursion detected in die_errno handler\n", + stderr); + exit(128); + } va_start(params, fmt); - die_routine(fmt_with_err, params); + die_routine(fmt_with_err(buf, sizeof(buf), fmt), params); va_end(params); } -- cgit v0.10.2-6-g49f6 From fd1d672300f36b2b06c2951ec450de0cf8f17797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:22 +0700 Subject: usage.c: add warning_errno() and error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to die_errno(), these functions will append strerror() automatically. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/git-compat-util.h b/git-compat-util.h index 4743954..76efb72 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -412,7 +412,9 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); +extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); +extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); #ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO diff --git a/usage.c b/usage.c index 8675d72..1dad03f 100644 --- a/usage.c +++ b/usage.c @@ -148,6 +148,17 @@ void NORETURN die_errno(const char *fmt, ...) va_end(params); } +int error_errno(const char *fmt, ...) +{ + char buf[1024]; + va_list params; + + va_start(params, fmt); + error_routine(fmt_with_err(buf, sizeof(buf), fmt), params); + va_end(params); + return -1; +} + #undef error int error(const char *err, ...) { @@ -159,6 +170,16 @@ int error(const char *err, ...) return -1; } +void warning_errno(const char *warn, ...) +{ + char buf[1024]; + va_list params; + + va_start(params, warn); + warn_routine(fmt_with_err(buf, sizeof(buf), warn), params); + va_end(params); +} + void warning(const char *warn, ...) { va_list params; -- cgit v0.10.2-6-g49f6 From 23e7a312e115e4cbeda3d944b8020e014f0f908a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:23 +0700 Subject: bisect.c: use die_errno() and warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/bisect.c b/bisect.c index 7996c29..6d93edb 100644 --- a/bisect.c +++ b/bisect.c @@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout) /* Create file BISECT_ANCESTORS_OK. */ fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (fd < 0) - warning("could not create file '%s': %s", - filename, strerror(errno)); + warning_errno("could not create file '%s'", + filename); else close(fd); done: @@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) *read_good = "good"; return; } else { - die("could not read file '%s': %s", filename, - strerror(errno)); + die_errno("could not read file '%s'", filename); } } else { strbuf_getline_lf(&str, fp); -- cgit v0.10.2-6-g49f6 From 6e59e9c0a658c619d390ed93466e457d4b80f0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:24 +0700 Subject: builtin/am.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/am.c b/builtin/am.c index d003939..3dfe70b 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state, in = fopen(*paths, "r"); if (!in) - return error(_("could not open '%s' for reading: %s"), - *paths, strerror(errno)); + return error_errno(_("could not open '%s' for reading"), + *paths); mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1); out = fopen(mail, "w"); if (!out) - return error(_("could not open '%s' for writing: %s"), - mail, strerror(errno)); + return error_errno(_("could not open '%s' for writing"), + mail); ret = fn(out, in, keep_cr); @@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, fp = fopen(*paths, "r"); if (!fp) - return error(_("could not open '%s' for reading: %s"), *paths, - strerror(errno)); + return error_errno(_("could not open '%s' for reading"), *paths); while (!strbuf_getline_lf(&sb, fp)) { if (*sb.buf == '#') -- cgit v0.10.2-6-g49f6 From 896ba1d11269e6e1cbf5c2795f908da5e3e1ce29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:25 +0700 Subject: builtin/branch.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/branch.c b/builtin/branch.c index 7b45b6b..6045dca 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -583,8 +583,7 @@ static int edit_branch_description(const char *branch_name) branch_name, comment_line_char); if (write_file_gently(git_path(edit_description), "%s", buf.buf)) { strbuf_release(&buf); - return error(_("could not write branch description template: %s"), - strerror(errno)); + return error_errno(_("could not write branch description template")); } strbuf_reset(&buf); if (launch_editor(git_path(edit_description), &buf, NULL)) { -- cgit v0.10.2-6-g49f6 From 6da31d7f75fa921f871eda76760b0c622d04147d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:26 +0700 Subject: builtin/fetch.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A couple of newlines are also removed, because both error() and error_errno() automatically append a newline. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/fetch.c b/builtin/fetch.c index e4639d8..4227a40 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fp = fopen(filename, "a"); if (!fp) - return error(_("cannot open %s: %s\n"), filename, strerror(errno)); + return error_errno(_("cannot open %s"), filename); if (raw_url) url = transport_anonymize_url(raw_url); @@ -848,7 +848,7 @@ static int truncate_fetch_head(void) FILE *fp = fopen_for_writing(filename); if (!fp) - return error(_("cannot open %s: %s\n"), filename, strerror(errno)); + return error_errno(_("cannot open %s"), filename); fclose(fp); return 0; } -- cgit v0.10.2-6-g49f6 From 574774980cfdfe72d77cec831024f0229d10a1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:27 +0700 Subject: builtin/help.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/help.c b/builtin/help.c index 3c55ce4..8848013 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page) path = "emacsclient"; strbuf_addf(&man_page, "(woman \"%s\")", page); execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL); - warning(_("failed to exec '%s': %s"), path, strerror(errno)); + warning_errno(_("failed to exec '%s'"), path); } } @@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page) path = "kfmclient"; strbuf_addf(&man_page, "man:%s(1)", page); execlp(path, filename, "newTab", man_page.buf, (char *)NULL); - warning(_("failed to exec '%s': %s"), path, strerror(errno)); + warning_errno(_("failed to exec '%s'"), path); } } @@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page) if (!path) path = "man"; execlp(path, "man", page, (char *)NULL); - warning(_("failed to exec '%s': %s"), path, strerror(errno)); + warning_errno(_("failed to exec '%s'"), path); } static void exec_man_cmd(const char *cmd, const char *page) @@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page) struct strbuf shell_cmd = STRBUF_INIT; strbuf_addf(&shell_cmd, "%s %s", cmd, page); execl(SHELL_PATH, SHELL_PATH, "-c", shell_cmd.buf, (char *)NULL); - warning(_("failed to exec '%s': %s"), cmd, strerror(errno)); + warning(_("failed to exec '%s'"), cmd); } static void add_man_viewer(const char *name) -- cgit v0.10.2-6-g49f6 From 880c0aef0fa8229ff4d3bc96f1f221ebf36443fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:28 +0700 Subject: builtin/mailsplit.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's one change, in split_mbox(), where an error() without strerror() as argument is converted to error_errno(). This is correct because the previous call is fopen (not shown in the context lines), which should set errno if it returns NULL. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 104277a..4859ede 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path) if ((dir = opendir(name)) == NULL) { if (errno == ENOENT) continue; - error("cannot opendir %s (%s)", name, strerror(errno)); + error_errno("cannot opendir %s", name); goto out; } @@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir, f = fopen(file, "r"); if (!f) { - error("cannot open mail %s (%s)", file, strerror(errno)); + error_errno("cannot open mail %s", file); goto out; } if (strbuf_getwholeline(&buf, f, '\n')) { - error("cannot read mail %s (%s)", file, strerror(errno)); + error_errno("cannot read mail %s", file); goto out; } @@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare, int file_done = 0; if (!f) { - error("cannot open mbox %s", file); + error_errno("cannot open mbox %s", file); goto out; } @@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) } if (stat(arg, &argstat) == -1) { - error("cannot stat %s (%s)", arg, strerror(errno)); + error_errno("cannot stat %s", arg); return 1; } -- cgit v0.10.2-6-g49f6 From 62f94d54a98983a19cc9dc82daec5c76df466b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:29 +0700 Subject: builtin/merge-file.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All these error() calls do not print error message previously, but because when they are called, errno should be set. Use error_errno() instead to give more information. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 5544705..13e22a2 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) usage_with_options(merge_file_usage, options); if (quiet) { if (!freopen("/dev/null", "w", stderr)) - return error("failed to redirect stderr to /dev/null: " - "%s", strerror(errno)); + return error_errno("failed to redirect stderr to /dev/null"); } if (prefix) @@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) FILE *f = to_stdout ? stdout : fopen(fpath, "wb"); if (!f) - ret = error("Could not open %s for writing", filename); + ret = error_errno("Could not open %s for writing", + filename); else if (result.size && fwrite(result.ptr, result.size, 1, f) != 1) - ret = error("Could not write to %s", filename); + ret = error_errno("Could not write to %s", filename); else if (fclose(f)) - ret = error("Could not close %s", filename); + ret = error_errno("Could not close %s", filename); free(result.ptr); } -- cgit v0.10.2-6-g49f6 From 54d47394b4307a0c9149007bd3d396b8eda8e995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:30 +0700 Subject: builtin/pack-objects.c: use die_errno() and warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index a27de5b..1145747 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -828,8 +828,7 @@ static void write_pack_file(void) * to preserve this property. */ if (stat(pack_tmp_name, &st) < 0) { - warning("failed to stat %s: %s", - pack_tmp_name, strerror(errno)); + warning_errno("failed to stat %s", pack_tmp_name); } else if (!last_mtime) { last_mtime = st.st_mtime; } else { @@ -837,8 +836,7 @@ static void write_pack_file(void) utb.actime = st.st_atime; utb.modtime = --last_mtime; if (utime(pack_tmp_name, &utb) < 0) - warning("failed utime() on %s: %s", - pack_tmp_name, strerror(errno)); + warning_errno("failed utime() on %s", pack_tmp_name); } strbuf_addf(&tmpname, "%s-", base_name); -- cgit v0.10.2-6-g49f6 From 7dcf3d97fa6098382828551de8f91ad8b23d5a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:31 +0700 Subject: builtin/rm.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While at there, improve the message a bit (what operation failed?) and mark it for translation since the format string is now a sentence. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/rm.c b/builtin/rm.c index 8829b09..fd47d20 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only) if (lstat(ce->name, &st) < 0) { if (errno != ENOENT && errno != ENOTDIR) - warning("'%s': %s", ce->name, strerror(errno)); + warning_errno(_("failed to stat '%s'"), ce->name); /* It already vanished from the working tree */ continue; } -- cgit v0.10.2-6-g49f6 From 23d05364fc5ba9fcc54cf5ae5503f3e987cec315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:32 +0700 Subject: builtin/update-index.c: prefer "err" to "errno" in process_lstat_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "errno" is already passed in as "err". Here we should use err instead of errno. errno is probably a copy/paste mistake in e011054 (Teach git-update-index about gitlinks - 2007-04-12) Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/update-index.c b/builtin/update-index.c index 1c94ca5..b8b8522 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err) { if (err == ENOENT || err == ENOTDIR) return remove_one_path(path); - return error("lstat(\"%s\"): %s", path, strerror(errno)); + return error("lstat(\"%s\"): %s", path, strerror(err)); } static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st) -- cgit v0.10.2-6-g49f6 From 17bef17ef8d319e620c19d032c082a18eb88a65f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:33 +0700 Subject: builtin/upload-archive.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index dbfe14f..2caedf1 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) pfd[1].events = POLLIN; if (poll(pfd, 2, -1) < 0) { if (errno != EINTR) { - error("poll failed resuming: %s", - strerror(errno)); + error_errno("poll failed resuming"); sleep(1); } continue; -- cgit v0.10.2-6-g49f6 From 8d19e9309411ca875928b9336ff626b8b6851fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:34 +0700 Subject: builtin/worktree.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While at there, improve the error message to say _what_ failed to remove. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/worktree.c b/builtin/worktree.c index 38b5609..df4f660 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -109,7 +109,7 @@ static void prune_worktrees(void) if (ret < 0 && errno == ENOTDIR) ret = unlink(path.buf); if (ret) - error(_("failed to remove: %s"), strerror(errno)); + error_errno(_("failed to remove '%s'"), path.buf); } closedir(dir); if (!show_only) -- cgit v0.10.2-6-g49f6 From eb031a580163b396ff0e4ee0f219758b517380d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:35 +0700 Subject: check-racy.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/check-racy.c b/check-racy.c index 00d92a1..24b6542 100644 --- a/check-racy.c +++ b/check-racy.c @@ -12,7 +12,7 @@ int main(int ac, char **av) struct stat st; if (lstat(ce->name, &st)) { - error("lstat(%s): %s", ce->name, strerror(errno)); + error_errno("lstat(%s)", ce->name); continue; } -- cgit v0.10.2-6-g49f6 From 4b94ec9b200e9bafc5fd2c9c4e8b7e7934d60c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:36 +0700 Subject: combine-diff.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/combine-diff.c b/combine-diff.c index 0e1d4b0..8f2313d 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, struct strbuf buf = STRBUF_INIT; if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) { - error("readlink(%s): %s", elem->path, - strerror(errno)); + error_errno("readlink(%s)", elem->path); return; } result_size = buf.len; -- cgit v0.10.2-6-g49f6 From df8e31391da9ec97f907bec32a648da6145f4b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:37 +0700 Subject: compat/win32/syslog.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c index b905aea..6c7c9b6 100644 --- a/compat/win32/syslog.c +++ b/compat/win32/syslog.c @@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...) va_end(ap); if (str_len < 0) { - warning("vsnprintf failed: '%s'", strerror(errno)); + warning_errno("vsnprintf failed"); return; } str = malloc(st_add(str_len, 1)); if (!str) { - warning("malloc failed: '%s'", strerror(errno)); + warning_errno("malloc failed"); return; } @@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...) while ((pos = strstr(str, "%1")) != NULL) { str = realloc(str, st_add(++str_len, 1)); if (!str) { - warning("realloc failed: '%s'", strerror(errno)); + warning_errno("realloc failed"); return; } memmove(pos + 2, pos + 1, strlen(pos)); -- cgit v0.10.2-6-g49f6 From f0658ec9ea996f993e3665786b3f5ac0b92179e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:38 +0700 Subject: config.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/config.c b/config.c index 9ba40bc..0bbf640 100644 --- a/config.c +++ b/config.c @@ -2016,7 +2016,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, lock = xcalloc(1, sizeof(struct lock_file)); fd = hold_lock_file_for_update(lock, config_filename, 0); if (fd < 0) { - error("could not lock config file %s: %s", config_filename, strerror(errno)); + error_errno("could not lock config file %s", config_filename); free(store.key); ret = CONFIG_NO_LOCK; goto out_free; @@ -2030,8 +2030,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, free(store.key); if ( ENOENT != errno ) { - error("opening %s: %s", config_filename, - strerror(errno)); + error_errno("opening %s", config_filename); ret = CONFIG_INVALID_FILE; /* same as "invalid config file" */ goto out_free; } @@ -2115,8 +2114,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, if (contents == MAP_FAILED) { if (errno == ENODEV && S_ISDIR(st.st_mode)) errno = EISDIR; - error("unable to mmap '%s': %s", - config_filename, strerror(errno)); + error_errno("unable to mmap '%s'", config_filename); ret = CONFIG_INVALID_FILE; contents = NULL; goto out_free; @@ -2125,8 +2123,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, in_fd = -1; if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { - error("chmod on %s failed: %s", - get_lock_file_path(lock), strerror(errno)); + error_errno("chmod on %s failed", get_lock_file_path(lock)); ret = CONFIG_NO_WRITE; goto out_free; } @@ -2182,8 +2179,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, } if (commit_lock_file(lock) < 0) { - error("could not write config file %s: %s", config_filename, - strerror(errno)); + error_errno("could not write config file %s", config_filename); ret = CONFIG_NO_WRITE; lock = NULL; goto out_free; @@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename, fstat(fileno(config_file), &st); if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { - ret = error("chmod on %s failed: %s", - get_lock_file_path(lock), strerror(errno)); + ret = error_errno("chmod on %s failed", + get_lock_file_path(lock)); goto out; } @@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename, fclose(config_file); unlock_and_out: if (commit_lock_file(lock) < 0) - ret = error("could not write config file %s: %s", - config_filename, strerror(errno)); + ret = error_errno("could not write config file %s", + config_filename); out: free(filename_buf); return ret; -- cgit v0.10.2-6-g49f6 From 5cc026e218d0ad3962d10c0775fe9b5ac68eed09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:39 +0700 Subject: connected.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/connected.c b/connected.c index 299c560..bf1b12e 100644 --- a/connected.c +++ b/connected.c @@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn, memcpy(commit, sha1_to_hex(sha1), 40); if (write_in_full(rev_list.in, commit, 41) < 0) { if (errno != EPIPE && errno != EINVAL) - error(_("failed write to rev-list: %s"), - strerror(errno)); + error_errno(_("failed write to rev-list")); err = -1; break; } } while (!fn(cb_data, sha1)); - if (close(rev_list.in)) { - error(_("failed to close rev-list's stdin: %s"), strerror(errno)); - err = -1; - } + if (close(rev_list.in)) + err = error_errno(_("failed to close rev-list's stdin")); sigchain_pop(SIGPIPE); return finish_command(&rev_list) || err; -- cgit v0.10.2-6-g49f6 From 37653a130af87f9103cf710bbd018eb9078f4bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:40 +0700 Subject: copy.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/copy.c b/copy.c index 574fa1f..4de6a11 100644 --- a/copy.c +++ b/copy.c @@ -42,15 +42,15 @@ int copy_file(const char *dst, const char *src, int mode) status = copy_fd(fdi, fdo); switch (status) { case COPY_READ_ERROR: - error("copy-fd: read returned %s", strerror(errno)); + error_errno("copy-fd: read returned"); break; case COPY_WRITE_ERROR: - error("copy-fd: write returned %s", strerror(errno)); + error_errno("copy-fd: write returned"); break; } close(fdi); if (close(fdo) != 0) - return error("%s: close error: %s", dst, strerror(errno)); + return error_errno("%s: close error", dst); if (!status && adjust_shared_perm(dst)) return -1; -- cgit v0.10.2-6-g49f6 From 26604f9f621b7b5710309671168d98722b8f5f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:41 +0700 Subject: credential-cache--daemon.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index caef21e..94d18f8 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -170,12 +170,12 @@ static int serve_cache_loop(int fd) client = accept(fd, NULL, NULL); if (client < 0) { - warning("accept failed: %s", strerror(errno)); + warning_errno("accept failed"); return 1; } client2 = dup(client); if (client2 < 0) { - warning("dup failed: %s", strerror(errno)); + warning_errno("dup failed"); close(client); return 1; } -- cgit v0.10.2-6-g49f6 From a1f06be3ff78f088aa5e71cd518b74cdf5a4d34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:42 +0700 Subject: diff-no-index.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/diff-no-index.c b/diff-no-index.c index 03daadb..1f8999b 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -65,8 +65,7 @@ static int populate_from_stdin(struct diff_filespec *s) size_t size = 0; if (strbuf_read(&buf, 0, 0) < 0) - return error("error while reading from stdin %s", - strerror(errno)); + return error_errno("error while reading from stdin"); s->should_munmap = 0; s->data = strbuf_detach(&buf, &size); -- cgit v0.10.2-6-g49f6 From 9f9a522c159d5f7f399c91a22e2f73287a393a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:43 +0700 Subject: editor.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/editor.c b/editor.c index 01c644c..7519ede 100644 --- a/editor.c +++ b/editor.c @@ -63,7 +63,6 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en if (!buffer) return 0; if (strbuf_read_file(buffer, path, 0) < 0) - return error("could not read file '%s': %s", - path, strerror(errno)); + return error_errno("could not read file '%s'", path); return 0; } -- cgit v0.10.2-6-g49f6 From e1ebb3c25bd42b06fe8f5f886af37dfac8a823a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:44 +0700 Subject: entry.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/entry.c b/entry.c index a410957..519e042 100644 --- a/entry.c +++ b/entry.c @@ -168,8 +168,8 @@ static int write_entry(struct cache_entry *ce, ret = symlink(new, path); free(new); if (ret) - return error("unable to create symlink %s (%s)", - path, strerror(errno)); + return error_errno("unable to create symlink %s", + path); break; } @@ -186,8 +186,7 @@ static int write_entry(struct cache_entry *ce, fd = open_output_fd(path, ce, to_tempfile); if (fd < 0) { free(new); - return error("unable to create file %s (%s)", - path, strerror(errno)); + return error_errno("unable to create file %s", path); } wrote = write_in_full(fd, new, size); @@ -284,8 +283,7 @@ int checkout_entry(struct cache_entry *ce, return error("%s is a directory", path.buf); remove_subtree(&path); } else if (unlink(path.buf)) - return error("unable to unlink old '%s' (%s)", - path.buf, strerror(errno)); + return error_errno("unable to unlink old '%s'", path.buf); } else if (state->not_new) return 0; -- cgit v0.10.2-6-g49f6 From 6c223e495877001987e525ca93b7fdd63e03b529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:45 +0700 Subject: fast-import.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/fast-import.c b/fast-import.c index 9fc7093..21881d1 100644 --- a/fast-import.c +++ b/fast-import.c @@ -414,7 +414,7 @@ static void write_crash_report(const char *err) struct recent_command *rc; if (!rpt) { - error("can't write crash report %s: %s", loc, strerror(errno)); + error_errno("can't write crash report %s", loc); free(loc); return; } @@ -1806,8 +1806,8 @@ static void dump_marks(void) return; if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) { - failure |= error("Unable to write marks file %s: %s", - export_marks_file, strerror(errno)); + failure |= error_errno("Unable to write marks file %s", + export_marks_file); return; } @@ -1822,8 +1822,8 @@ static void dump_marks(void) dump_marks_helper(f, 0, marks); if (commit_lock_file(&mark_lock)) { - failure |= error("Unable to write file %s: %s", - export_marks_file, strerror(errno)); + failure |= error_errno("Unable to write file %s", + export_marks_file); return; } } -- cgit v0.10.2-6-g49f6 From ddf362a2a9b6cf784497162d21556a950f99dce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:46 +0700 Subject: gpg-interface.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/gpg-interface.c b/gpg-interface.c index 3dc2fe3..20612fe 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -219,11 +219,9 @@ int verify_signed_buffer(const char *payload, size_t payload_size, args_gpg[0] = gpg_program; fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX"); if (fd < 0) - return error(_("could not create temporary file '%s': %s"), - path, strerror(errno)); + return error_errno(_("could not create temporary file '%s'"), path); if (write_in_full(fd, signature, signature_size) < 0) - return error(_("failed writing detached signature to '%s': %s"), - path, strerror(errno)); + return error_errno(_("failed writing detached signature to '%s'"), path); close(fd); gpg.argv = args_gpg; -- cgit v0.10.2-6-g49f6 From 7645d8f119997320c33423d95670824f05657bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:47 +0700 Subject: grep.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While at there, improve the error message a bit (what operation failed?) Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/grep.c b/grep.c index 528b652..ec6f7ff 100644 --- a/grep.c +++ b/grep.c @@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs) if (lstat(filename, &st) < 0) { err_ret: if (errno != ENOENT) - error(_("'%s': %s"), filename, strerror(errno)); + error_errno(_("failed to stat '%s'"), filename); return -1; } if (!S_ISREG(st.st_mode)) @@ -1743,7 +1743,7 @@ static int grep_source_load_file(struct grep_source *gs) goto err_ret; data = xmallocz(size); if (st.st_size != read_in_full(i, data, size)) { - error(_("'%s': short read %s"), filename, strerror(errno)); + error_errno(_("'%s': short read"), filename); close(i); free(data); return -1; -- cgit v0.10.2-6-g49f6 From d2e255eefab204fa6585963d5670b6cffdee866e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:48 +0700 Subject: http.c: use error_errno() and warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/http.c b/http.c index 69da445..fa39b87 100644 --- a/http.c +++ b/http.c @@ -446,8 +446,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type) rc = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&ka, len); if (rc < 0) - warning("unable to set SO_KEEPALIVE on socket %s", - strerror(errno)); + warning_errno("unable to set SO_KEEPALIVE on socket"); return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */ } @@ -1891,8 +1890,7 @@ struct http_object_request *new_http_object_request(const char *base_url, } if (freq->localfile < 0) { - error("Couldn't create temporary file %s: %s", - freq->tmpfile, strerror(errno)); + error_errno("Couldn't create temporary file %s", freq->tmpfile); goto abort; } @@ -1937,8 +1935,8 @@ struct http_object_request *new_http_object_request(const char *base_url, prev_posn = 0; lseek(freq->localfile, 0, SEEK_SET); if (ftruncate(freq->localfile, 0) < 0) { - error("Couldn't truncate temporary file %s: %s", - freq->tmpfile, strerror(errno)); + error_errno("Couldn't truncate temporary file %s", + freq->tmpfile); goto abort; } } -- cgit v0.10.2-6-g49f6 From a26f4ed682a64dcc6092c28dadb3f5c139d50576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:49 +0700 Subject: ident.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index 6e12582..337a421 100644 --- a/ident.c +++ b/ident.c @@ -75,14 +75,12 @@ static int add_mailname_host(struct strbuf *buf) mailname = fopen("/etc/mailname", "r"); if (!mailname) { if (errno != ENOENT) - warning("cannot open /etc/mailname: %s", - strerror(errno)); + warning_errno("cannot open /etc/mailname"); return -1; } if (strbuf_getline(&mailnamebuf, mailname) == EOF) { if (ferror(mailname)) - warning("cannot read /etc/mailname: %s", - strerror(errno)); + warning_errno("cannot read /etc/mailname"); strbuf_release(&mailnamebuf); fclose(mailname); return -1; @@ -125,7 +123,7 @@ static void add_domainname(struct strbuf *out, int *is_bogus) char buf[1024]; if (gethostname(buf, sizeof(buf))) { - warning("cannot get host name: %s", strerror(errno)); + warning_errno("cannot get host name"); strbuf_addstr(out, "(none)"); *is_bogus = 1; return; -- cgit v0.10.2-6-g49f6 From 60901e4c220e565518c87b1349108ac7dfec0ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:50 +0700 Subject: mailmap.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/mailmap.c b/mailmap.c index f4a0f1c..da4e49a 100644 --- a/mailmap.c +++ b/mailmap.c @@ -189,8 +189,7 @@ static int read_mailmap_file(struct string_list *map, const char *filename, if (!f) { if (errno == ENOENT) return 0; - return error("unable to open mailmap at %s: %s", - filename, strerror(errno)); + return error_errno("unable to open mailmap at %s", filename); } while (fgets(buffer, sizeof(buffer), f) != NULL) -- cgit v0.10.2-6-g49f6 From 9a3acba1caead126a9c009eb00573fc9451f8cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:51 +0700 Subject: reachable.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/reachable.c b/reachable.c index ed35201..d0199ca 100644 --- a/reachable.c +++ b/reachable.c @@ -119,8 +119,7 @@ static int add_recent_loose(const unsigned char *sha1, */ if (errno == ENOENT) return 0; - return error("unable to stat %s: %s", - sha1_to_hex(sha1), strerror(errno)); + return error_errno("unable to stat %s", sha1_to_hex(sha1)); } add_recent_object(sha1, st.st_mtime, data); -- cgit v0.10.2-6-g49f6 From 033e011e64052e61e03b4d4cec06c7445ed36e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:52 +0700 Subject: rerere.c: use error_errno() and warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/rerere.c b/rerere.c index 587b7e2..9e9c66c 100644 --- a/rerere.c +++ b/rerere.c @@ -351,8 +351,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output error("There were errors while writing %s (%s)", path, strerror(io.io.wrerror)); if (io.io.output && fclose(io.io.output)) - io.io.wrerror = error("Failed to flush %s: %s", - path, strerror(errno)); + io.io.wrerror = error_errno("Failed to flush %s", path); if (hunk_no < 0) { if (output) @@ -614,20 +613,17 @@ static int merge(const struct rerere_id *id, const char *path) * Mark that "postimage" was used to help gc. */ if (utime(rerere_path(id, "postimage"), NULL) < 0) - warning("failed utime() on %s: %s", - rerere_path(id, "postimage"), - strerror(errno)); + warning_errno("failed utime() on %s", + rerere_path(id, "postimage")); /* Update "path" with the resolution */ f = fopen(path, "w"); if (!f) - return error("Could not open %s: %s", path, - strerror(errno)); + return error_errno("Could not open %s", path); if (fwrite(result.ptr, result.size, 1, f) != 1) - error("Could not write %s: %s", path, strerror(errno)); + error_errno("Could not write %s", path); if (fclose(f)) - return error("Writing %s failed: %s", path, - strerror(errno)); + return error_errno("Writing %s failed", path); out: free(cur.ptr); @@ -842,7 +838,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr) if (unlink(filename)) return (errno == ENOENT ? error("no remembered resolution for %s", path) - : error("cannot unlink %s: %s", filename, strerror(errno))); + : error_errno("cannot unlink %s", filename)); /* * Update the preimage so that the user can resolve the -- cgit v0.10.2-6-g49f6 From fbcb0e0659618793815a57c5f60ad391ad6f452e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:53 +0700 Subject: run-command.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/run-command.c b/run-command.c index c726010..d645a8d 100644 --- a/run-command.c +++ b/run-command.c @@ -233,7 +233,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal) if (waiting < 0) { failed_errno = errno; - error("waitpid for %s failed: %s", argv0, strerror(errno)); + error_errno("waitpid for %s failed", argv0); } else if (waiting != pid) { error("waitpid is confused (%s)", argv0); } else if (WIFSIGNALED(status)) { @@ -420,8 +420,7 @@ fail_pipe: } } if (cmd->pid < 0) - error("cannot fork() for %s: %s", cmd->argv[0], - strerror(errno)); + error_errno("cannot fork() for %s", cmd->argv[0]); else if (cmd->clean_on_exit) mark_child_for_cleanup(cmd->pid); @@ -482,7 +481,7 @@ fail_pipe: cmd->dir, fhin, fhout, fherr); failed_errno = errno; if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT)) - error("cannot spawn %s: %s", cmd->argv[0], strerror(errno)); + error_errno("cannot spawn %s", cmd->argv[0]); if (cmd->clean_on_exit && cmd->pid >= 0) mark_child_for_cleanup(cmd->pid); @@ -693,7 +692,7 @@ int start_async(struct async *async) if (pipe(fdin) < 0) { if (async->out > 0) close(async->out); - return error("cannot create pipe: %s", strerror(errno)); + return error_errno("cannot create pipe"); } async->in = fdin[1]; } @@ -705,7 +704,7 @@ int start_async(struct async *async) close_pair(fdin); else if (async->in) close(async->in); - return error("cannot create pipe: %s", strerror(errno)); + return error_errno("cannot create pipe"); } async->out = fdout[0]; } @@ -730,7 +729,7 @@ int start_async(struct async *async) async->pid = fork(); if (async->pid < 0) { - error("fork (async) failed: %s", strerror(errno)); + error_errno("fork (async) failed"); goto error; } if (!async->pid) { @@ -777,7 +776,7 @@ int start_async(struct async *async) { int err = pthread_create(&async->tid, NULL, run_thread, async); if (err) { - error("cannot create thread: %s", strerror(err)); + error_errno("cannot create thread"); goto error; } } -- cgit v0.10.2-6-g49f6 From 6c979c74b26d48b82f5e144faf5aeccc2e875a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:54 +0700 Subject: sequencer.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/sequencer.c b/sequencer.c index e66f2fe..4687ad4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -875,8 +875,7 @@ static int sequencer_rollback(struct replay_opts *opts) return rollback_single_pick(); } if (!f) - return error(_("cannot open %s: %s"), git_path_head_file(), - strerror(errno)); + return error_errno(_("cannot open %s"), git_path_head_file()); if (strbuf_getline_lf(&buf, f)) { error(_("cannot read %s: %s"), git_path_head_file(), ferror(f) ? strerror(errno) : _("unexpected end of file")); -- cgit v0.10.2-6-g49f6 From 02382f51b36c09ecacd21be18b55ba6b1433e9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:55 +0700 Subject: server-info.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/server-info.c b/server-info.c index 5a86e29..75dd677 100644 --- a/server-info.c +++ b/server-info.c @@ -36,7 +36,7 @@ static int update_info_file(char *path, int (*generate)(FILE *)) out: if (ret) { - error("unable to update %s: %s", path, strerror(errno)); + error_errno("unable to update %s", path); if (fp) fclose(fp); else if (fd >= 0) -- cgit v0.10.2-6-g49f6 From 7616c6ca9d3559a1768b7293c64c5a39e73bd365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:56 +0700 Subject: sha1_file.c: use {error,die,warning}_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/sha1_file.c b/sha1_file.c index d0f2aa0..a7f45b3 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p, PROT_READ, MAP_PRIVATE, p->pack_fd, win->offset); if (win->base == MAP_FAILED) - die("packfile %s cannot be mapped: %s", - p->pack_name, - strerror(errno)); + die_errno("packfile %s cannot be mapped", + p->pack_name); if (!win->offset && win->len == p->pack_size && !p->do_not_close) close_pack_fd(p); @@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local) dir = opendir(path.buf); if (!dir) { if (errno != ENOENT) - error("unable to open object pack directory: %s: %s", - path.buf, strerror(errno)); + error_errno("unable to open object pack directory: %s", + path.buf); strbuf_release(&path); return; } @@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename) unlink_or_warn(tmpfile); if (ret) { if (ret != EEXIST) { - return error("unable to write sha1 filename %s: %s", filename, strerror(ret)); + return error_errno("unable to write sha1 filename %s", filename); } /* FIXME!!! Collision check here ? */ } @@ -2998,7 +2997,7 @@ out: static int write_buffer(int fd, const void *buf, size_t len) { if (write_in_full(fd, buf, len) < 0) - return error("file write error (%s)", strerror(errno)); + return error_errno("file write error"); return 0; } @@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, if (errno == EACCES) return error("insufficient permission for adding an object to repository database %s", get_object_directory()); else - return error("unable to create temporary file: %s", strerror(errno)); + return error_errno("unable to create temporary file"); } /* Set it up */ @@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, utb.actime = mtime; utb.modtime = mtime; if (utime(tmp_file.buf, &utb) < 0) - warning("failed utime() on %s: %s", - tmp_file.buf, strerror(errno)); + warning_errno("failed utime() on %s", tmp_file.buf); } return finalize_object_file(tmp_file.buf, filename); @@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size, if (size == read_in_full(fd, buf, size)) ret = index_mem(sha1, buf, size, type, path, flags); else - ret = error("short read %s", strerror(errno)); + ret = error_errno("short read"); free(buf); } else { void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); @@ -3425,18 +3423,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned case S_IFREG: fd = open(path, O_RDONLY); if (fd < 0) - return error("open(\"%s\"): %s", path, - strerror(errno)); + return error_errno("open(\"%s\")", path); if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0) return error("%s: failed to insert into database", path); break; case S_IFLNK: - if (strbuf_readlink(&sb, path, st->st_size)) { - char *errstr = strerror(errno); - return error("readlink(\"%s\"): %s", path, - errstr); - } + if (strbuf_readlink(&sb, path, st->st_size)) + return error_errno("readlink(\"%s\")", path); if (!(flags & HASH_WRITE_OBJECT)) hash_sha1_file(sb.buf, sb.len, blob_type, sha1); else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1)) @@ -3492,7 +3486,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr, if (!dir) { if (errno == ENOENT) return 0; - return error("unable to open %s: %s", path->buf, strerror(errno)); + return error_errno("unable to open %s", path->buf); } while ((de = readdir(dir))) { -- cgit v0.10.2-6-g49f6 From 1fee1dce711327811956bd78ad1f7270a3e2d824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:57 +0700 Subject: transport-helper.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/transport-helper.c b/transport-helper.c index b934183..f09fadc 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -1166,7 +1166,7 @@ static int udt_do_read(struct unidirectional_transfer *t) bytes = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse); if (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR) { - error("read(%s) failed: %s", t->src_name, strerror(errno)); + error_errno("read(%s) failed", t->src_name); return -1; } else if (bytes == 0) { transfer_debug("%s EOF (with %i bytes in buffer)", @@ -1193,7 +1193,7 @@ static int udt_do_write(struct unidirectional_transfer *t) transfer_debug("%s is writable", t->dest_name); bytes = xwrite(t->dest, t->buf, t->bufuse); if (bytes < 0 && errno != EWOULDBLOCK) { - error("write(%s) failed: %s", t->dest_name, strerror(errno)); + error_errno("write(%s) failed", t->dest_name); return -1; } else if (bytes > 0) { t->bufuse -= bytes; @@ -1306,7 +1306,7 @@ static int tloop_join(pid_t pid, const char *name) { int tret; if (waitpid(pid, &tret, 0) < 0) { - error("%s process failed to wait: %s", name, strerror(errno)); + error_errno("%s process failed to wait", name); return 1; } if (!WIFEXITED(tret) || WEXITSTATUS(tret)) { -- cgit v0.10.2-6-g49f6 From 43c728e2c2fe81cf401f39a60ab167a9ed542428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:58 +0700 Subject: unpack-trees.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/unpack-trees.c b/unpack-trees.c index 9f55cc2..bb0d142 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1499,8 +1499,7 @@ static int verify_absent_1(const struct cache_entry *ce, path = xmemdupz(ce->name, len); if (lstat(path, &st)) - ret = error("cannot stat '%s': %s", path, - strerror(errno)); + ret = error_errno("cannot stat '%s'", path); else ret = check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st, error_type, o); @@ -1508,8 +1507,7 @@ static int verify_absent_1(const struct cache_entry *ce, return ret; } else if (lstat(ce->name, &st)) { if (errno != ENOENT) - return error("cannot stat '%s': %s", ce->name, - strerror(errno)); + return error_errno("cannot stat '%s'", ce->name); return 0; } else { return check_ok_to_remove(ce->name, ce_namelen(ce), -- cgit v0.10.2-6-g49f6 From d2b6afa2cb2e56d506442dfba96aa08b54d71f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:47:59 +0700 Subject: upload-pack.c: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/upload-pack.c b/upload-pack.c index b3f6653..b1c3e76 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -177,8 +177,7 @@ static void create_pack_file(void) if (ret < 0) { if (errno != EINTR) { - error("poll failed, resuming: %s", - strerror(errno)); + error_errno("poll failed, resuming"); sleep(1); } continue; -- cgit v0.10.2-6-g49f6 From 1c8ead97f842fb385ce729bc45760b439365b79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:48:00 +0700 Subject: vcs-svn: use error_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c index 57cc1ce..e416caf 100644 --- a/vcs-svn/line_buffer.c +++ b/vcs-svn/line_buffer.c @@ -53,9 +53,9 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf) { long pos = ftell(buf->infile); if (pos < 0) - return error("ftell error: %s", strerror(errno)); + return error_errno("ftell error"); if (fseek(buf->infile, 0, SEEK_SET)) - return error("seek error: %s", strerror(errno)); + return error_errno("seek error"); return pos; } diff --git a/vcs-svn/sliding_window.c b/vcs-svn/sliding_window.c index f11d490..06d273c 100644 --- a/vcs-svn/sliding_window.c +++ b/vcs-svn/sliding_window.c @@ -12,7 +12,7 @@ static int input_error(struct line_buffer *file) { if (!buffer_ferror(file)) return error("delta preimage ends early"); - return error("cannot read delta preimage: %s", strerror(errno)); + return error_errno("cannot read delta preimage"); } static int skip_or_whine(struct line_buffer *file, off_t gap) diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c index 74c97c4..75c7531 100644 --- a/vcs-svn/svndiff.c +++ b/vcs-svn/svndiff.c @@ -64,13 +64,13 @@ static int write_strbuf(struct strbuf *sb, FILE *out) { if (fwrite(sb->buf, 1, sb->len, out) == sb->len) /* Success. */ return 0; - return error("cannot write delta postimage: %s", strerror(errno)); + return error_errno("cannot write delta postimage"); } static int error_short_read(struct line_buffer *input) { if (buffer_ferror(input)) - return error("error reading delta: %s", strerror(errno)); + return error_errno("error reading delta"); return error("invalid delta: unexpected end of file"); } diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index 31d1d83..e4b3959 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -501,7 +501,7 @@ static void init(int report_fd) int svndump_init(const char *filename) { if (buffer_init(&input, filename)) - return error("cannot open %s: %s", filename ? filename : "NULL", strerror(errno)); + return error_errno("cannot open %s", filename ? filename : "NULL"); init(REPORT_FILENO); return 0; } @@ -509,7 +509,7 @@ int svndump_init(const char *filename) int svndump_init_fd(int in_fd, int back_fd) { if(buffer_fdinit(&input, xdup(in_fd))) - return error("cannot open fd %d: %s", in_fd, strerror(errno)); + return error_errno("cannot open fd %d", in_fd); init(xdup(back_fd)); return 0; } -- cgit v0.10.2-6-g49f6 From 1da045fb9db5db8f01eb5e7c6106880ca5274643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 8 May 2016 16:48:01 +0700 Subject: wrapper.c: use warning_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/wrapper.c b/wrapper.c index 9afc1a0..3df2fe0 100644 --- a/wrapper.c +++ b/wrapper.c @@ -572,7 +572,7 @@ static int warn_if_unremovable(const char *op, const char *file, int rc) if (!rc || errno == ENOENT) return 0; err = errno; - warning("unable to %s %s: %s", op, file, strerror(errno)); + warning_errno("unable to %s %s", op, file); errno = err; return rc; } @@ -608,7 +608,7 @@ int remove_or_warn(unsigned int mode, const char *file) void warn_on_inaccessible(const char *path) { - warning(_("unable to access '%s': %s"), path, strerror(errno)); + warning_errno(_("unable to access '%s'"), path); } static int access_error_is_ok(int err, unsigned flag) -- cgit v0.10.2-6-g49f6