{"thread":{"id":"19751","subject":"[PATCH v3 3/3] Use die_errno() instead of die() when checking syscalls","startedAt":"2009-06-08T21:02:17Z","lastAt":"2009-06-27T18:38:40Z","messageCount":14,"participants":["Thomas Rast","Jeff King","Andreas Ericsson","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"115839","messageId":"cover.1244494646.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1244299302.git.trast@student.ethz.ch","subject":"[PATCH v3 0/3] die_errno()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-08T21:02:17Z","receivedAt":"2009-06-08T21:02:17Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"First off, thanks for the extensive review and discussion...\n\n[1/3] I changed the snprintf handling to tack the error onto the\n  format and pass that to die_routine().  I still think it's crazy to\n  invent new format characters, but who knows.\n\n[2/3] Fixed as per Johannes Sixt's comments.\n\n[3/3] Removed the terrible empty-lines mess caused by pilot error.\n\n  Johannes Sixt wrote:\n  > > @@ -1018,8 +1017,10 @@ int cmd_commit(int argc, const char **argv, const\n  > > char *prefix)\n  > >\n  > >  \tif (commit_index_files())\n  > >  \t\tdie (\"Repository has been updated, but unable to write\\n\"\n  > > -\t\t     \"new_index file. Check that disk is not full or quota is\\n\"\n  > > -\t\t     \"not exceeded, and then \\\"git reset HEAD\\\" to recover.\");\n  > > +\t\t     \"new_index file: %s.\\n\"\n  > > +\t\t     \"Check that disk is not full or quota is not exceeded,\\n\"\n  > > +\t\t     \"and then \\\"git reset HEAD\\\" to recover.\",\n  > > +\t\t     strerror(errno));\n  > \n  > This change should probably not be in this patch.\n\n  Removed...  I'm not enough of an expert to say if\n  commit_index_files() can only fail because the disk is full, so I\n  figured it would still be an improvement to show the real error.\n\n  If you just meant that it should go in a separate patch because it's\n  not a die->die_errno change, I can do that, it just feels like\n  overkill because it is morally the same change, but in a case where\n  I cannot apply the die_errno shortcut.\n\n\nThomas Rast (3):\n  Introduce die_errno() that appends strerror(errno) to die()\n  Convert existing die(..., strerror(errno)) to die_errno()\n  Use die_errno() instead of die() when checking syscalls\n\n abspath.c                |   12 ++++++------\n bisect.c                 |    5 ++---\n branch.c                 |    4 ++--\n builtin-add.c            |    2 +-\n builtin-apply.c          |   12 ++++++------\n builtin-archive.c        |    4 ++--\n builtin-blame.c          |   15 +++++++--------\n builtin-clone.c          |   21 ++++++++++-----------\n builtin-commit-tree.c    |    2 +-\n builtin-commit.c         |   28 +++++++++++++---------------\n builtin-config.c         |    4 ++--\n builtin-diff.c           |    2 +-\n builtin-fast-export.c    |    4 ++--\n builtin-fetch--tool.c    |    2 +-\n builtin-fmt-merge-msg.c  |    5 ++---\n builtin-fsck.c           |   10 +++++-----\n builtin-grep.c           |    2 +-\n builtin-init-db.c        |   21 +++++++++++----------\n builtin-log.c            |    4 ++--\n builtin-mailsplit.c      |    6 +++---\n builtin-merge.c          |   29 ++++++++++++++++-------------\n builtin-mv.c             |    2 +-\n builtin-pack-objects.c   |   14 +++++---------\n builtin-rev-parse.c      |    2 +-\n builtin-revert.c         |    2 +-\n builtin-rm.c             |    2 +-\n builtin-send-pack.c      |    2 +-\n builtin-stripspace.c     |    2 +-\n builtin-tag.c            |    9 ++++-----\n builtin-tar-tree.c       |    2 +-\n builtin-unpack-objects.c |    2 +-\n combine-diff.c           |    2 +-\n csum-file.c              |    5 ++---\n daemon.c                 |   15 +++++++--------\n diff.c                   |   10 +++++-----\n dir.c                    |    2 +-\n entry.c                  |   10 +++++-----\n fast-import.c            |    8 ++++----\n git-compat-util.h        |    1 +\n git.c                    |    6 +++---\n hash-object.c            |    2 +-\n index-pack.c             |   21 ++++++++++-----------\n ll-merge.c               |    2 +-\n merge-recursive.c        |    6 +++---\n mktag.c                  |    2 +-\n pack-refs.c              |    7 +++----\n pack-write.c             |   10 +++++-----\n pkt-line.c               |    4 ++--\n read-cache.c             |    8 ++++----\n refs.c                   |    2 +-\n run-command.c            |    4 ++--\n setup.c                  |   18 +++++++++---------\n sha1_file.c              |    2 +-\n shell.c                  |    2 +-\n test-sha1.c              |    2 +-\n transport.c              |    4 ++--\n unpack-file.c            |    2 +-\n usage.c                  |   12 ++++++++++++\n wrapper.c                |    8 ++++----\n write_or_die.c           |    6 +++---\n 60 files changed, 209 insertions(+), 207 deletions(-)\n"},{"id":"115838","messageId":"5f43aa9d0b69e99600a73bddd4c93217608ab661.1244494647.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1244494646.git.trast@student.ethz.ch","subject":"[PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-08T21:02:18Z","receivedAt":"2009-06-08T21:02:18Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"There are many calls to die() that do, or should, report\nstrerror(errno) to indicate how the syscall they guard failed.\nIntroduce a small helper function for this case.\n\nNote:\n\n- POSIX says vsnprintf can modify errno in some unlikely cases, so we\n  have to use errno early.\n\n- We take some care to pass the original format to die_routine(), in\n  case someone wants to call die_errno() with custom format\n  characters.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n git-compat-util.h |    1 +\n usage.c           |   12 ++++++++++++\n 2 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex f25f7f1..0366cde 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -162,6 +162,7 @@\n /* General helper functions */\n extern void usage(const char *err) NORETURN;\n extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n+extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n \ndiff --git a/usage.c b/usage.c\nindex 820d09f..fd936a1 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -60,6 +60,18 @@ void die(const char *err, ...)\n \tva_end(params);\n }\n \n+void die_errno(const char *fmt, ...)\n+{\n+\tva_list params;\n+\tchar fmt_with_err[1024];\n+\n+\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, strerror(errno));\n+\n+\tva_start(params, fmt);\n+\tdie_routine(fmt_with_err, params);\n+\tva_end(params);\n+}\n+\n int error(const char *err, ...)\n {\n \tva_list params;\n-- \n1.6.3.2.333.g27636\n"},{"id":"115840","messageId":"5a74ed8a911fc1048c021bc3b42e679526bc4c8e.1244494647.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"5f43aa9d0b69e99600a73bddd4c93217608ab661.1244494647.git.trast@student.ethz.ch","subject":"[PATCH v3 2/3] Convert existing die(..., strerror(errno)) to die_errno()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-08T21:02:19Z","receivedAt":"2009-06-08T21:02:19Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Change calls to die(..., strerror(errno)) to use the new die_errno().\n\nIn the process, also make slight style adjustments: at least state\n_something_ about the function that failed (instead of just printing\nthe pathname), and put paths in single quotes.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n bisect.c                 |    5 ++---\n branch.c                 |    4 ++--\n builtin-apply.c          |    6 +++---\n builtin-blame.c          |    7 +++----\n builtin-clone.c          |   11 +++++------\n builtin-commit-tree.c    |    2 +-\n builtin-commit.c         |   23 ++++++++++-------------\n builtin-config.c         |    4 ++--\n builtin-diff.c           |    2 +-\n builtin-fast-export.c    |    2 +-\n builtin-fetch--tool.c    |    2 +-\n builtin-fmt-merge-msg.c  |    3 +--\n builtin-fsck.c           |    8 ++++----\n builtin-grep.c           |    2 +-\n builtin-merge.c          |    8 ++++----\n builtin-mv.c             |    2 +-\n builtin-pack-objects.c   |   14 +++++---------\n builtin-rm.c             |    2 +-\n builtin-send-pack.c      |    2 +-\n builtin-tag.c            |    7 +++----\n builtin-unpack-objects.c |    2 +-\n csum-file.c              |    5 ++---\n daemon.c                 |   15 +++++++--------\n diff.c                   |    4 ++--\n dir.c                    |    2 +-\n entry.c                  |    8 ++++----\n fast-import.c            |    4 ++--\n git.c                    |    6 +++---\n index-pack.c             |   21 ++++++++++-----------\n merge-recursive.c        |    6 +++---\n pack-refs.c              |    7 +++----\n pack-write.c             |   10 +++++-----\n pkt-line.c               |    4 ++--\n read-cache.c             |    6 +++---\n refs.c                   |    2 +-\n run-command.c            |    4 ++--\n setup.c                  |    8 ++++----\n sha1_file.c              |    2 +-\n shell.c                  |    2 +-\n test-sha1.c              |    2 +-\n wrapper.c                |    8 ++++----\n write_or_die.c           |    6 +++---\n 42 files changed, 117 insertions(+), 133 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex c43c120..281e16a 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -461,7 +461,7 @@ void read_bisect_paths(struct argv_array *array)\n \tFILE *fp = fopen(filename, \"r\");\n \n \tif (!fp)\n-\t\tdie(\"Could not open file '%s': %s\", filename, strerror(errno));\n+\t\tdie_errno(\"Could not open file '%s'\", filename);\n \n \twhile (strbuf_getline(&str, fp, '\\n') != EOF) {\n \t\tchar *quoted;\n@@ -632,8 +632,7 @@ static void mark_expected_rev(char *bisect_rev_hex)\n \tint fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n \n \tif (fd < 0)\n-\t\tdie(\"could not create file '%s': %s\",\n-\t\t    filename, strerror(errno));\n+\t\tdie_errno(\"could not create file '%s'\", filename);\n \n \tbisect_rev_hex[len] = '\\n';\n \twrite_or_die(fd, bisect_rev_hex, len + 1);\ndiff --git a/branch.c b/branch.c\nindex 62030af..05ef3f5 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -172,7 +172,7 @@ void create_branch(const char *head,\n \n \tlock = lock_any_ref_for_update(ref.buf, NULL, 0);\n \tif (!lock)\n-\t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n+\t\tdie_errno(\"Failed to lock ref for update\");\n \n \tif (reflog)\n \t\tlog_all_ref_updates = 1;\n@@ -188,7 +188,7 @@ void create_branch(const char *head,\n \t\tsetup_tracking(name, real_ref, track);\n \n \tif (write_ref_sha1(lock, sha1, msg) < 0)\n-\t\tdie(\"Failed to write ref: %s.\", strerror(errno));\n+\t\tdie_errno(\"Failed to write ref\");\n \n \tstrbuf_release(&ref);\n \tfree(real_ref);\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 94ba2bd..6526c08 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,\n static void read_patch_file(struct strbuf *sb, int fd)\n {\n \tif (strbuf_read(sb, fd, 0) < 0)\n-\t\tdie(\"git apply: read returned %s\", strerror(errno));\n+\t\tdie_errno(\"git apply: failed to read\");\n \n \t/*\n \t * Make sure that we have some slop in the buffer\n@@ -2864,7 +2864,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \tstrbuf_release(&nbuf);\n \n \tif (close(fd) < 0)\n-\t\tdie(\"closing file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"closing file '%s'\", path);\n \treturn 0;\n }\n \n@@ -3354,7 +3354,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \n \t\tfd = open(arg, O_RDONLY);\n \t\tif (fd < 0)\n-\t\t\tdie(\"can't open patch '%s': %s\", arg, strerror(errno));\n+\t\t\tdie_errno(\"can't open patch '%s'\", arg);\n \t\tread_stdin = 0;\n \t\tset_default_whitespace_mode(whitespace_option);\n \t\terrs |= apply_patch(fd, arg, options);\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 0c2d29a..7d8fbd5 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2035,7 +2035,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)\n \t\tcontents_from = \"standard input\";\n \t\tmode = 0;\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n-\t\t\tdie(\"read error %s from stdin\", strerror(errno));\n+\t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n \tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n \torigin->file.ptr = buf.buf;\n@@ -2261,8 +2261,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \targc = parse_options_end(&ctx);\n \n \tif (revs_file && read_ancestry(revs_file))\n-\t\tdie(\"reading graft file %s failed: %s\",\n-\t\t    revs_file, strerror(errno));\n+\t\tdie_errno(\"reading graft file '%s' failed\", revs_file);\n \n \tif (cmd_is_annotate) {\n \t\toutput_option |= OUTPUT_ANNOTATE_COMPAT;\n@@ -2350,7 +2349,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \n \t\tsetup_work_tree();\n \t\tif (!has_string_in_work_tree(path))\n-\t\t\tdie(\"cannot stat path %s: %s\", path, strerror(errno));\n+\t\t\tdie_errno(\"cannot stat path '%s'\", path);\n \t}\n \n \tsetup_revisions(argc, argv, &revs, NULL);\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex 5c46496..5f34414 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -252,8 +252,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \t\t}\n \n \t\tif (unlink(dest->buf) && errno != ENOENT)\n-\t\t\tdie(\"failed to unlink %s: %s\",\n-\t\t\t    dest->buf, strerror(errno));\n+\t\t\tdie_errno(\"failed to unlink '%s'\", dest->buf);\n \t\tif (!option_no_hardlinks) {\n \t\t\tif (!link(src->buf, dest->buf))\n \t\t\t\tcontinue;\n@@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tif (!option_bare) {\n \t\tjunk_work_tree = work_tree;\n \t\tif (safe_create_leading_directories_const(work_tree) < 0)\n-\t\t\tdie(\"could not create leading directories of '%s': %s\",\n-\t\t\t\t\twork_tree, strerror(errno));\n+\t\t\tdie_errno(\"could not create leading directories of '%s'\",\n+\t\t\t\t  work_tree);\n \t\tif (!dest_exists && mkdir(work_tree, 0755))\n-\t\t\tdie(\"could not create work tree dir '%s': %s.\",\n-\t\t\t\t\twork_tree, strerror(errno));\n+\t\t\tdie_errno(\"could not create work tree dir '%s'.\",\n+\t\t\t\t  work_tree);\n \t\tset_git_work_tree(work_tree);\n \t}\n \tjunk_git_dir = git_dir;\ndiff --git a/builtin-commit-tree.c b/builtin-commit-tree.c\nindex 0453425..6467077 100644\n--- a/builtin-commit-tree.c\n+++ b/builtin-commit-tree.c\n@@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (strbuf_read(&buffer, 0, 0) < 0)\n-\t\tdie(\"git commit-tree: read returned %s\", strerror(errno));\n+\t\tdie_errno(\"git commit-tree: failed to read\");\n \n \tif (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {\n \t\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 41e222d..88c51bd 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -438,8 +438,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\thook_arg1 = \"message\";\n \t} else if (logfile) {\n \t\tif (strbuf_read_file(&sb, logfile, 0) < 0)\n-\t\t\tdie(\"could not read log file '%s': %s\",\n-\t\t\t    logfile, strerror(errno));\n+\t\t\tdie_errno(\"could not read log file '%s'\",\n+\t\t\t\t  logfile);\n \t\thook_arg1 = \"message\";\n \t} else if (use_message) {\n \t\tbuffer = strstr(use_message_buffer, \"\\n\\n\");\n@@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\thook_arg2 = use_message;\n \t} else if (!stat(git_path(\"MERGE_MSG\"), &statbuf)) {\n \t\tif (strbuf_read_file(&sb, git_path(\"MERGE_MSG\"), 0) < 0)\n-\t\t\tdie(\"could not read MERGE_MSG: %s\", strerror(errno));\n+\t\t\tdie_errno(\"could not read MERGE_MSG\");\n \t\thook_arg1 = \"merge\";\n \t} else if (!stat(git_path(\"SQUASH_MSG\"), &statbuf)) {\n \t\tif (strbuf_read_file(&sb, git_path(\"SQUASH_MSG\"), 0) < 0)\n-\t\t\tdie(\"could not read SQUASH_MSG: %s\", strerror(errno));\n+\t\t\tdie_errno(\"could not read SQUASH_MSG\");\n \t\thook_arg1 = \"squash\";\n \t} else if (template_file && !stat(template_file, &statbuf)) {\n \t\tif (strbuf_read_file(&sb, template_file, 0) < 0)\n-\t\t\tdie(\"could not read %s: %s\",\n-\t\t\t    template_file, strerror(errno));\n+\t\t\tdie_errno(\"could not read '%s'\", template_file);\n \t\thook_arg1 = \"template\";\n \t}\n \n@@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \n \tfp = fopen(git_path(commit_editmsg), \"w\");\n \tif (fp == NULL)\n-\t\tdie(\"could not open %s: %s\",\n-\t\t    git_path(commit_editmsg), strerror(errno));\n+\t\tdie_errno(\"could not open '%s'\", git_path(commit_editmsg));\n \n \tif (cleanup_mode != CLEANUP_NONE)\n \t\tstripspace(&sb, 0);\n@@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t}\n \n \tif (fwrite(sb.buf, 1, sb.len, fp) < sb.len)\n-\t\tdie(\"could not write commit template: %s\", strerror(errno));\n+\t\tdie_errno(\"could not write commit template\");\n \n \tstrbuf_release(&sb);\n \n@@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tpptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;\n \t\tfp = fopen(git_path(\"MERGE_HEAD\"), \"r\");\n \t\tif (fp == NULL)\n-\t\t\tdie(\"could not open %s for reading: %s\",\n-\t\t\t    git_path(\"MERGE_HEAD\"), strerror(errno));\n+\t\t\tdie_errno(\"could not open '%s' for reading\",\n+\t\t\t\t  git_path(\"MERGE_HEAD\"));\n \t\twhile (strbuf_getline(&m, fp, '\\n') != EOF) {\n \t\t\tunsigned char sha1[20];\n \t\t\tif (get_sha1_hex(m.buf, sha1) < 0)\n@@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tstrbuf_release(&m);\n \t\tif (!stat(git_path(\"MERGE_MODE\"), &statbuf)) {\n \t\t\tif (strbuf_read_file(&sb, git_path(\"MERGE_MODE\"), 0) < 0)\n-\t\t\t\tdie(\"could not read MERGE_MODE: %s\",\n-\t\t\t\t\t\tstrerror(errno));\n+\t\t\t\tdie_errno(\"could not read MERGE_MODE\");\n \t\t\tif (!strcmp(sb.buf, \"no-ff\"))\n \t\t\t\tallow_fast_forward = 0;\n \t\t}\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 60915f9..a2d656e 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config(show_all_config, NULL) < 0) {\n \t\t\tif (config_exclusive_filename)\n-\t\t\t\tdie(\"unable to read config file %s: %s\",\n-\t\t\t\t    config_exclusive_filename, strerror(errno));\n+\t\t\t\tdie_errno(\"unable to read config file '%s'\",\n+\t\t\t\t\t  config_exclusive_filename);\n \t\t\telse\n \t\t\t\tdie(\"error processing config file(s)\");\n \t\t}\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex d75d69b..2e51f40 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,\n \t\tusage(builtin_diff_usage);\n \n \tif (lstat(path, &st))\n-\t\tdie(\"'%s': %s\", path, strerror(errno));\n+\t\tdie_errno(\"failed to stat '%s'\", path);\n \tif (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))\n \t\tdie(\"'%s': not a regular file or symlink\", path);\n \ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 6cef810..333d438 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -451,7 +451,7 @@ static void import_marks(char *input_file)\n \tchar line[512];\n \tFILE *f = fopen(input_file, \"r\");\n \tif (!f)\n-\t\tdie(\"cannot read %s: %s\", input_file, strerror(errno));\n+\t\tdie_errno(\"cannot read '%s'\", input_file);\n \n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuint32_t mark;\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 29356d2..3dbdf7a 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -8,7 +8,7 @@\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tif (strbuf_read(&buf, 0, 1024) < 0) {\n-\t\tdie(\"error reading standard input: %s\", strerror(errno));\n+\t\tdie_errno(\"error reading standard input\");\n \t}\n \treturn strbuf_detach(&buf, NULL);\n }\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex fbf9582..1248d5e 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -372,8 +372,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (strbuf_read(&input, fileno(in), 0) < 0)\n-\t\tdie(\"could not read input file %s\", strerror(errno));\n-\n+\t\tdie_errno(\"could not read input file\");\n \tret = fmt_merge_msg(merge_summary, &input, &output);\n \tif (ret)\n \t\treturn ret;\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 7da706c..a49dbe1 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)\n \t\t\t\t\t\t&type, &size);\n \t\t\t\tif (buf) {\n \t\t\t\t\tif (fwrite(buf, size, 1, f) != 1)\n-\t\t\t\t\t\tdie(\"Could not write %s: %s\",\n-\t\t\t\t\t\t    filename, strerror(errno));\n+\t\t\t\t\t\tdie_errno(\"Could not write '%s'\",\n+\t\t\t\t\t\t\t  filename);\n \t\t\t\t\tfree(buf);\n \t\t\t\t}\n \t\t\t} else\n \t\t\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n \t\t\tif (fclose(f))\n-\t\t\t\tdie(\"Could not finish %s: %s\",\n-\t\t\t\t    filename, strerror(errno));\n+\t\t\t\tdie_errno(\"Could not finish '%s'\",\n+\t\t\t\t\t  filename);\n \t\t}\n \t\treturn;\n \t}\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 73fc922..e558368 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)\n \n \tpatterns = fopen(arg, \"r\");\n \tif (!patterns)\n-\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\tdie_errno(\"cannot open '%s'\", arg);\n \twhile (strbuf_getline(&sb, patterns, '\\n') == 0) {\n \t\t/* ignore empty line like grep does */\n \t\tif (sb.len == 0)\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 8d101ef..436263b 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -294,9 +294,9 @@ static void squash_message(void)\n \t\t\tNULL, NULL, rev.date_mode, 0);\n \t}\n \tif (write(fd, out.buf, out.len) < 0)\n-\t\tdie(\"Writing SQUASH_MSG: %s\", strerror(errno));\n+\t\tdie_errno(\"Writing SQUASH_MSG\");\n \tif (close(fd))\n-\t\tdie(\"Finishing SQUASH_MSG: %s\", strerror(errno));\n+\t\tdie_errno(\"Finishing SQUASH_MSG\");\n \tstrbuf_release(&out);\n }\n \n@@ -428,8 +428,8 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \n \t\tfp = fopen(git_path(\"FETCH_HEAD\"), \"r\");\n \t\tif (!fp)\n-\t\t\tdie(\"could not open %s for reading: %s\",\n-\t\t\t\tgit_path(\"FETCH_HEAD\"), strerror(errno));\n+\t\t\tdie_errno(\"could not open '%s' for reading\",\n+\t\t\t\t  git_path(\"FETCH_HEAD\"));\n \t\tstrbuf_getline(&line, fp, '\\n');\n \t\tfclose(fp);\n \t\tptr = strstr(line.buf, \"\\tnot-for-merge\\t\");\ndiff --git a/builtin-mv.c b/builtin-mv.c\nindex 8b81d4b..024dfeb 100644\n--- a/builtin-mv.c\n+++ b/builtin-mv.c\n@@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(\"Renaming %s to %s\\n\", src, dst);\n \t\tif (!show_only && mode != INDEX &&\n \t\t\t\trename(src, dst) < 0 && !ignore_errors)\n-\t\t\tdie (\"renaming %s failed: %s\", src, strerror(errno));\n+\t\t\tdie_errno (\"renaming '%s' failed\", src);\n \n \t\tif (mode == WORKING_DIRECTORY)\n \t\t\tcontinue;\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 9742b45..60355d4 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -536,11 +536,9 @@ static void write_pack_file(void)\n \t\t\t\t base_name, sha1_to_hex(sha1));\n \t\t\tfree_pack_by_name(tmpname);\n \t\t\tif (adjust_perm(pack_tmp_name, mode))\n-\t\t\t\tdie(\"unable to make temporary pack file readable: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to make temporary pack file readable\");\n \t\t\tif (rename(pack_tmp_name, tmpname))\n-\t\t\t\tdie(\"unable to rename temporary pack file: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to rename temporary pack file\");\n \n \t\t\t/*\n \t\t\t * Packs are runtime accessed in their mtime\n@@ -566,11 +564,9 @@ static void write_pack_file(void)\n \t\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.idx\",\n \t\t\t\t base_name, sha1_to_hex(sha1));\n \t\t\tif (adjust_perm(idx_tmp_name, mode))\n-\t\t\t\tdie(\"unable to make temporary index file readable: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to make temporary index file readable\");\n \t\t\tif (rename(idx_tmp_name, tmpname))\n-\t\t\t\tdie(\"unable to rename temporary index file: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to rename temporary index file\");\n \n \t\t\tfree(idx_tmp_name);\n \t\t\tfree(pack_tmp_name);\n@@ -1880,7 +1876,7 @@ static void read_object_list_from_stdin(void)\n \t\t\tif (!ferror(stdin))\n \t\t\t\tdie(\"fgets returned NULL, not EOF, not error!\");\n \t\t\tif (errno != EINTR)\n-\t\t\t\tdie(\"fgets: %s\", strerror(errno));\n+\t\t\t\tdie_errno(\"fgets\");\n \t\t\tclearerr(stdin);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex 0cc4912..57975db 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!removed)\n-\t\t\t\tdie(\"git rm: %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"git rm: '%s'\", path);\n \t\t}\n \t}\n \ndiff --git a/builtin-send-pack.c b/builtin-send-pack.c\nindex be3b092..8fe5ab9 100644\n--- a/builtin-send-pack.c\n+++ b/builtin-send-pack.c\n@@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext\n \tpo.out = fd;\n \tpo.git_cmd = 1;\n \tif (start_command(&po))\n-\t\tdie(\"git pack-objects failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"git pack-objects failed\");\n \n \t/*\n \t * We feed the pack-objects we just spawned with revision\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex dc3db62..7b51095 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \t\tpath = git_pathdup(\"TAG_EDITMSG\");\n \t\tfd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n \t\tif (fd < 0)\n-\t\t\tdie(\"could not create file '%s': %s\",\n-\t\t\t\t\t\tpath, strerror(errno));\n+\t\t\tdie_errno(\"could not create file '%s'\", path);\n \n \t\tif (!is_null_sha1(prev))\n \t\t\twrite_tag_body(fd, prev);\n@@ -446,8 +445,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tdie(\"cannot read %s\", msgfile);\n \t\t\t} else {\n \t\t\t\tif (strbuf_read_file(&buf, msgfile, 1024) < 0)\n-\t\t\t\t\tdie(\"could not open or read '%s': %s\",\n-\t\t\t\t\t\tmsgfile, strerror(errno));\n+\t\t\t\t\tdie_errno(\"could not open or read '%s'\",\n+\t\t\t\t\t\tmsgfile);\n \t\t\t}\n \t\t}\n \t}\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 9a77323..41e9ac5 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -68,7 +68,7 @@ static void add_object_buffer(struct object *object, char *buffer, unsigned long\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\n \t\t\t\tdie(\"early EOF\");\n-\t\t\tdie(\"read error on input: %s\", strerror(errno));\n+\t\t\tdie_errno(\"read error on input\");\n \t\t}\n \t\tlen += ret;\n \t} while (len < min);\ndiff --git a/csum-file.c b/csum-file.c\nindex 2ddb12a..4d50cc5 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -26,7 +26,7 @@ static void flush(struct sha1file *f, void * buf, unsigned int count)\n \t\t}\n \t\tif (!ret)\n \t\t\tdie(\"sha1 file '%s' write error. Out of diskspace\", f->name);\n-\t\tdie(\"sha1 file '%s' write error (%s)\", f->name, strerror(errno));\n+\t\tdie_errno(\"sha1 file '%s' write error\", f->name);\n \t}\n }\n \n@@ -55,8 +55,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)\n \t\tif (flags & CSUM_FSYNC)\n \t\t\tfsync_or_die(f->fd, f->name);\n \t\tif (close(f->fd))\n-\t\t\tdie(\"%s: sha1 file error on close (%s)\",\n-\t\t\t    f->name, strerror(errno));\n+\t\t\tdie_errno(\"%s: sha1 file error on close\", f->name);\n \t\tfd = 0;\n \t} else\n \t\tfd = f->fd;\ndiff --git a/daemon.c b/daemon.c\nindex b2babcc..0c2f326 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -862,7 +862,7 @@ static int service_loop(int socknum, int *socklist)\n \t\t\t\t\tcase ECONNABORTED:\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\tdefault:\n-\t\t\t\t\t\tdie(\"accept returned %s\", strerror(errno));\n+\t\t\t\t\t\tdie_errno(\"accept returned\");\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\thandle(incoming, (struct sockaddr *)&ss, sslen);\n@@ -878,7 +878,7 @@ static void sanitize_stdfds(void)\n \twhile (fd != -1 && fd < 2)\n \t\tfd = dup(fd);\n \tif (fd == -1)\n-\t\tdie(\"open /dev/null or dup failed: %s\", strerror(errno));\n+\t\tdie_errno(\"open /dev/null or dup failed\");\n \tif (fd > 2)\n \t\tclose(fd);\n }\n@@ -889,12 +889,12 @@ static void daemonize(void)\n \t\tcase 0:\n \t\t\tbreak;\n \t\tcase -1:\n-\t\t\tdie(\"fork failed: %s\", strerror(errno));\n+\t\t\tdie_errno(\"fork failed\");\n \t\tdefault:\n \t\t\texit(0);\n \t}\n \tif (setsid() == -1)\n-\t\tdie(\"setsid failed: %s\", strerror(errno));\n+\t\tdie_errno(\"setsid failed\");\n \tclose(0);\n \tclose(1);\n \tclose(2);\n@@ -905,9 +905,9 @@ static void store_pid(const char *path)\n {\n \tFILE *f = fopen(path, \"w\");\n \tif (!f)\n-\t\tdie(\"cannot open pid file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"cannot open pid file '%s'\", path);\n \tif (fprintf(f, \"%\"PRIuMAX\"\\n\", (uintmax_t) getpid()) < 0 || fclose(f) != 0)\n-\t\tdie(\"failed to write pid file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"failed to write pid file '%s'\", path);\n }\n \n static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)\n@@ -1107,8 +1107,7 @@ int main(int argc, char **argv)\n \t\tsocklen_t slen = sizeof(ss);\n \n \t\tif (!freopen(\"/dev/null\", \"w\", stderr))\n-\t\t\tdie(\"failed to redirect stderr to /dev/null: %s\",\n-\t\t\t    strerror(errno));\n+\t\t\tdie_errno(\"failed to redirect stderr to /dev/null\");\n \n \t\tif (getpeername(0, peer, &slen))\n \t\t\tpeer = NULL;\ndiff --git a/diff.c b/diff.c\nindex 4d0a5b9..48043f5 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1975,7 +1975,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \tfd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,\n \t\t\tstrlen(base) + 1);\n \tif (fd < 0)\n-\t\tdie(\"unable to create temp-file: %s\", strerror(errno));\n+\t\tdie_errno(\"unable to create temp-file\");\n \tif (convert_to_working_tree(path,\n \t\t\t(const char *)blob, (size_t)size, &buf)) {\n \t\tblob = buf.buf;\n@@ -2021,7 +2021,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tif (lstat(name, &st) < 0) {\n \t\t\tif (errno == ENOENT)\n \t\t\t\tgoto not_a_valid_file;\n-\t\t\tdie(\"stat(%s): %s\", name, strerror(errno));\n+\t\t\tdie_errno(\"stat(%s)\", name);\n \t\t}\n \t\tif (S_ISLNK(st.st_mode)) {\n \t\t\tstruct strbuf sb = STRBUF_INIT;\ndiff --git a/dir.c b/dir.c\nindex bbfcb56..74b3bbf 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -759,7 +759,7 @@ int file_exists(const char *f)\n \tif (!dir)\n \t\treturn NULL;\n \tif (!getcwd(buffer, size))\n-\t\tdie(\"can't find the current directory: %s\", strerror(errno));\n+\t\tdie_errno(\"can't find the current directory\");\n \n \tif (!is_absolute_path(dir))\n \t\tdir = make_absolute_path(dir);\ndiff --git a/entry.c b/entry.c\nindex cc841ed..8ec880b 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -51,7 +51,7 @@ static void remove_subtree(const char *path)\n \tchar *name;\n \n \tif (!dir)\n-\t\tdie(\"cannot opendir %s (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"cannot opendir '%s'\", path);\n \tstrcpy(pathbuf, path);\n \tname = pathbuf + strlen(path);\n \t*name++ = '/';\n@@ -61,15 +61,15 @@ static void remove_subtree(const char *path)\n \t\t\tcontinue;\n \t\tstrcpy(name, de->d_name);\n \t\tif (lstat(pathbuf, &st))\n-\t\t\tdie(\"cannot lstat %s (%s)\", pathbuf, strerror(errno));\n+\t\t\tdie_errno(\"cannot lstat '%s'\", pathbuf);\n \t\tif (S_ISDIR(st.st_mode))\n \t\t\tremove_subtree(pathbuf);\n \t\telse if (unlink(pathbuf))\n-\t\t\tdie(\"cannot unlink %s (%s)\", pathbuf, strerror(errno));\n+\t\t\tdie_errno(\"cannot unlink '%s'\", pathbuf);\n \t}\n \tclosedir(dir);\n \tif (rmdir(path))\n-\t\tdie(\"cannot rmdir %s (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"cannot rmdir '%s'\", path);\n }\n \n static int create_file(const char *path, unsigned int mode)\ndiff --git a/fast-import.c b/fast-import.c\nindex a2a2458..d31a4e8 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2342,7 +2342,7 @@ static void import_marks(const char *input_file)\n \tchar line[512];\n \tFILE *f = fopen(input_file, \"r\");\n \tif (!f)\n-\t\tdie(\"cannot read %s: %s\", input_file, strerror(errno));\n+\t\tdie_errno(\"cannot read '%s'\", input_file);\n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuintmax_t mark;\n \t\tchar *end;\n@@ -2448,7 +2448,7 @@ int main(int argc, const char **argv)\n \t\t\t\tfclose(pack_edges);\n \t\t\tpack_edges = fopen(a + 20, \"a\");\n \t\t\tif (!pack_edges)\n-\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n+\t\t\t\tdie_errno(\"Cannot open '%s'\", a + 20);\n \t\t} else if (!strcmp(a, \"--force\"))\n \t\t\tforce_update = 1;\n \t\telse if (!strcmp(a, \"--quiet\"))\ndiff --git a/git.c b/git.c\nindex 7d7f949..b035676 100644\n--- a/git.c\n+++ b/git.c\n@@ -200,7 +200,7 @@ static int handle_alias(int *argcp, const char ***argv)\n \t}\n \n \tif (subdir && chdir(subdir))\n-\t\tdie(\"Cannot change to %s: %s\", subdir, strerror(errno));\n+\t\tdie_errno(\"Cannot change to '%s'\", subdir);\n \n \terrno = saved_errno;\n \n@@ -257,11 +257,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \t/* Check for ENOSPC and EIO errors.. */\n \tif (fflush(stdout))\n-\t\tdie(\"write failure on standard output: %s\", strerror(errno));\n+\t\tdie_errno(\"write failure on standard output\");\n \tif (ferror(stdout))\n \t\tdie(\"unknown write failure on standard output\");\n \tif (fclose(stdout))\n-\t\tdie(\"close failed on standard output: %s\", strerror(errno));\n+\t\tdie_errno(\"close failed on standard output\");\n \treturn 0;\n }\n \ndiff --git a/index-pack.c b/index-pack.c\nindex 6e93ee6..cf6446f 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -143,7 +143,7 @@ static void flush(void)\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\n \t\t\t\tdie(\"early EOF\");\n-\t\t\tdie(\"read error on input: %s\", strerror(errno));\n+\t\t\tdie_errno(\"read error on input\");\n \t\t}\n \t\tinput_len += ret;\n \t\tif (from_stdin)\n@@ -178,13 +178,12 @@ static void use(int bytes)\n \t\t} else\n \t\t\toutput_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);\n \t\tif (output_fd < 0)\n-\t\t\tdie(\"unable to create %s: %s\", pack_name, strerror(errno));\n+\t\t\tdie_errno(\"unable to create '%s'\", pack_name);\n \t\tpack_fd = output_fd;\n \t} else {\n \t\tinput_fd = open(pack_name, O_RDONLY);\n \t\tif (input_fd < 0)\n-\t\t\tdie(\"cannot open packfile '%s': %s\",\n-\t\t\t    pack_name, strerror(errno));\n+\t\t\tdie_errno(\"cannot open packfile '%s'\", pack_name);\n \t\toutput_fd = -1;\n \t\tpack_fd = input_fd;\n \t}\n@@ -370,7 +369,7 @@ static void unlink_base_data(struct base_data *c)\n \tdo {\n \t\tssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);\n \t\tif (n < 0)\n-\t\t\tdie(\"cannot pread pack file: %s\", strerror(errno));\n+\t\t\tdie_errno(\"cannot pread pack file\");\n \t\tif (!n)\n \t\t\tdie(\"premature end of pack file, %lu bytes missing\",\n \t\t\t    len - rdy);\n@@ -631,7 +630,7 @@ static void parse_pack_objects(unsigned char *sha1)\n \n \t/* If input_fd is a file, we should have reached its end now. */\n \tif (fstat(input_fd, &st))\n-\t\tdie(\"cannot fstat packfile: %s\", strerror(errno));\n+\t\tdie_errno(\"cannot fstat packfile\");\n \tif (S_ISREG(st.st_mode) &&\n \t\t\tlseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size)\n \t\tdie(\"pack has junk at the end\");\n@@ -788,7 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \t\tfsync_or_die(output_fd, curr_pack_name);\n \t\terr = close(output_fd);\n \t\tif (err)\n-\t\t\tdie(\"error while closing pack file: %s\", strerror(errno));\n+\t\t\tdie_errno(\"error while closing pack file\");\n \t}\n \n \tif (keep_msg) {\n@@ -801,16 +800,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \n \t\tif (keep_fd < 0) {\n \t\t\tif (errno != EEXIST)\n-\t\t\t\tdie(\"cannot write keep file '%s' (%s)\",\n-\t\t\t\t    keep_name, strerror(errno));\n+\t\t\t\tdie_errno(\"cannot write keep file '%s'\",\n+\t\t\t\t\t  keep_name);\n \t\t} else {\n \t\t\tif (keep_msg_len > 0) {\n \t\t\t\twrite_or_die(keep_fd, keep_msg, keep_msg_len);\n \t\t\t\twrite_or_die(keep_fd, \"\\n\", 1);\n \t\t\t}\n \t\t\tif (close(keep_fd) != 0)\n-\t\t\t\tdie(\"cannot close written keep file '%s' (%s)\",\n-\t\t\t\t    keep_name, strerror(errno));\n+\t\t\t\tdie_errno(\"cannot close written keep file '%s'\",\n+\t\t\t\t    keep_name);\n \t\t\treport = \"keep\";\n \t\t}\n \t}\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex f5df9b9..5d9140b 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -438,7 +438,7 @@ static void flush_buffer(int fd, const char *buf, unsigned long size)\n \t\t\t/* Ignore epipe */\n \t\t\tif (errno == EPIPE)\n \t\t\t\tbreak;\n-\t\t\tdie(\"merge-recursive: %s\", strerror(errno));\n+\t\t\tdie_errno(\"merge-recursive\");\n \t\t} else if (!ret) {\n \t\t\tdie(\"merge-recursive: disk full?\");\n \t\t}\n@@ -554,7 +554,7 @@ static void update_file_flags(struct merge_options *o,\n \t\t\t\tmode = 0666;\n \t\t\tfd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);\n \t\t\tif (fd < 0)\n-\t\t\t\tdie(\"failed to open %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"failed to open '%s'\", path);\n \t\t\tflush_buffer(fd, buf, size);\n \t\t\tclose(fd);\n \t\t} else if (S_ISLNK(mode)) {\n@@ -562,7 +562,7 @@ static void update_file_flags(struct merge_options *o,\n \t\t\tsafe_create_leading_directories_const(path);\n \t\t\tunlink(path);\n \t\t\tif (symlink(lnk, path))\n-\t\t\t\tdie(\"failed to symlink %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"failed to symlink '%s'\", path);\n \t\t\tfree(lnk);\n \t\t} else\n \t\t\tdie(\"do not know what to do with %06o %s '%s'\",\ndiff --git a/pack-refs.c b/pack-refs.c\nindex 301fc60..7f43f8a 100644\n--- a/pack-refs.c\n+++ b/pack-refs.c\n@@ -93,8 +93,7 @@ int pack_refs(unsigned int flags)\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \tcbdata.refs_file = fdopen(fd, \"w\");\n \tif (!cbdata.refs_file)\n-\t\tdie(\"unable to create ref-pack file structure (%s)\",\n-\t\t    strerror(errno));\n+\t\tdie_errno(\"unable to create ref-pack file structure\");\n \n \t/* perhaps other traits later as well */\n \tfprintf(cbdata.refs_file, \"# pack-refs with: peeled \\n\");\n@@ -103,7 +102,7 @@ int pack_refs(unsigned int flags)\n \tif (ferror(cbdata.refs_file))\n \t\tdie(\"failed to write ref-pack file\");\n \tif (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))\n-\t\tdie(\"failed to write ref-pack file (%s)\", strerror(errno));\n+\t\tdie_errno(\"failed to write ref-pack file\");\n \t/*\n \t * Since the lock file was fdopen()'ed and then fclose()'ed above,\n \t * assign -1 to the lock file descriptor so that commit_lock_file()\n@@ -111,7 +110,7 @@ int pack_refs(unsigned int flags)\n \t */\n \tpacked.fd = -1;\n \tif (commit_lock_file(&packed) < 0)\n-\t\tdie(\"unable to overwrite old ref-pack file (%s)\", strerror(errno));\n+\t\tdie_errno(\"unable to overwrite old ref-pack file\");\n \tif (cbdata.flags & PACK_REFS_PRUNE)\n \t\tprune_refs(cbdata.ref_to_prune);\n \treturn 0;\ndiff --git a/pack-write.c b/pack-write.c\nindex 7053538..741efcd 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -51,7 +51,7 @@ static int sha1_compare(const void *_a, const void *_b)\n \t\tfd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);\n \t}\n \tif (fd < 0)\n-\t\tdie(\"unable to create %s: %s\", index_name, strerror(errno));\n+\t\tdie_errno(\"unable to create '%s'\", index_name);\n \tf = sha1fd(fd, index_name);\n \n \t/* if last object's offset is >= 2^31 we should use index V2 */\n@@ -174,11 +174,11 @@ void fixup_pack_header_footer(int pack_fd,\n \tgit_SHA1_Init(&new_sha1_ctx);\n \n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n-\t\tdie(\"Failed seeking to start of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n \tif (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))\n-\t\tdie(\"Unable to reread header of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Unable to reread header of '%s'\", pack_name);\n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n-\t\tdie(\"Failed seeking to start of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n \tgit_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));\n \thdr.hdr_entries = htonl(object_count);\n \tgit_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));\n@@ -195,7 +195,7 @@ void fixup_pack_header_footer(int pack_fd,\n \t\tif (!n)\n \t\t\tbreak;\n \t\tif (n < 0)\n-\t\t\tdie(\"Failed to checksum %s: %s\", pack_name, strerror(errno));\n+\t\t\tdie_errno(\"Failed to checksum '%s'\", pack_name);\n \t\tgit_SHA1_Update(&new_sha1_ctx, buf, n);\n \n \t\taligned_sz -= n;\ndiff --git a/pkt-line.c b/pkt-line.c\nindex f5d0086..b691abe 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -28,7 +28,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)\n \t\t}\n \t\tif (!ret)\n \t\t\tdie(\"write error (disk full?)\");\n-\t\tdie(\"write error (%s)\", strerror(errno));\n+\t\tdie_errno(\"write error\");\n \t}\n \treturn nn;\n }\n@@ -67,7 +67,7 @@ static void safe_read(int fd, void *buffer, unsigned size)\n {\n \tssize_t ret = read_in_full(fd, buffer, size);\n \tif (ret < 0)\n-\t\tdie(\"read error (%s)\", strerror(errno));\n+\t\tdie_errno(\"read error\");\n \telse if (ret < size)\n \t\tdie(\"The remote end hung up unexpectedly\");\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 3f58711..f76b5bb 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -638,7 +638,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)\n {\n \tstruct stat st;\n \tif (lstat(path, &st))\n-\t\tdie(\"%s: unable to stat (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"unable to stat '%s'\", path);\n \treturn add_to_index(istate, path, &st, flags);\n }\n \n@@ -1251,11 +1251,11 @@ int read_index_from(struct index_state *istate, const char *path)\n \tif (fd < 0) {\n \t\tif (errno == ENOENT)\n \t\t\treturn 0;\n-\t\tdie(\"index file open failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"index file open failed\");\n \t}\n \n \tif (fstat(fd, &st))\n-\t\tdie(\"cannot stat the open index (%s)\", strerror(errno));\n+\t\tdie_errno(\"cannot stat the open index\");\n \n \terrno = EINVAL;\n \tmmap_size = xsize_t(st.st_size);\ndiff --git a/refs.c b/refs.c\nindex 24438c6..dffe395 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1418,7 +1418,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *\n \tlogfile = git_path(\"logs/%s\", ref);\n \tlogfd = open(logfile, O_RDONLY, 0);\n \tif (logfd < 0)\n-\t\tdie(\"Unable to read log %s: %s\", logfile, strerror(errno));\n+\t\tdie_errno(\"Unable to read log '%s'\", logfile);\n \tfstat(logfd, &st);\n \tif (!st.st_size)\n \t\tdie(\"Log %s is empty.\", logfile);\ndiff --git a/run-command.c b/run-command.c\nindex eb2efc3..ff3d8e2 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -101,8 +101,8 @@ int start_command(struct child_process *cmd)\n \t\t}\n \n \t\tif (cmd->dir && chdir(cmd->dir))\n-\t\t\tdie(\"exec %s: cd to %s failed (%s)\", cmd->argv[0],\n-\t\t\t    cmd->dir, strerror(errno));\n+\t\t\tdie_errno(\"exec '%s': cd to '%s' failed\", cmd->argv[0],\n+\t\t\t    cmd->dir);\n \t\tif (cmd->env) {\n \t\t\tfor (; *cmd->env; cmd->env++) {\n \t\t\t\tif (strchr(*cmd->env, '='))\ndiff --git a/setup.c b/setup.c\nindex ebd60de..4d27f28 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -81,7 +81,7 @@ void verify_filename(const char *prefix, const char *arg)\n \tif (errno == ENOENT)\n \t\tdie(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n \t\t    \"Use '--' to separate paths from revisions\", arg);\n-\tdie(\"'%s': %s\", arg, strerror(errno));\n+\tdie_errno(\"failed to stat '%s'\", arg);\n }\n \n /*\n@@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg)\n \t\tdie(\"ambiguous argument '%s': both revision and filename\\n\"\n \t\t    \"Use '--' to separate filenames from revisions\", arg);\n \tif (errno != ENOENT && errno != ENOTDIR)\n-\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\tdie_errno(\"failed to stat '%s'\", arg);\n }\n \n const char **get_pathspec(const char *prefix, const char **pathspec)\n@@ -257,7 +257,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\treturn NULL;\n \tfd = open(path, O_RDONLY);\n \tif (fd < 0)\n-\t\tdie(\"Error opening %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"Error opening '%s'\", path);\n \tbuf = xmalloc(st.st_size + 1);\n \tlen = read_in_full(fd, buf, st.st_size);\n \tclose(fd);\n@@ -389,7 +389,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\t\tdie(\"Not a git repository (or any of the parent directories): %s\", DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\t}\n \t\tif (chdir(\"..\"))\n-\t\t\tdie(\"Cannot change to %s/..: %s\", cwd, strerror(errno));\n+\t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n \t}\n \n \tinside_git_dir = 0;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex e73cd4f..1964a6d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2287,7 +2287,7 @@ static void close_sha1_file(int fd)\n \tif (fsync_object_files)\n \t\tfsync_or_die(fd, \"sha1 file\");\n \tif (close(fd) != 0)\n-\t\tdie(\"error when closing sha1 file (%s)\", strerror(errno));\n+\t\tdie_errno(\"error when closing sha1 file\");\n }\n \n /* Size of directory component, including the ending '/' */\ndiff --git a/shell.c b/shell.c\nindex b968be7..e4864e0 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -60,7 +60,7 @@ int main(int argc, char **argv)\n \twhile (devnull_fd >= 0 && devnull_fd <= 2)\n \t\tdevnull_fd = dup(devnull_fd);\n \tif (devnull_fd == -1)\n-\t\tdie(\"opening /dev/null failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"opening /dev/null failed\");\n \tclose (devnull_fd);\n \n \t/*\ndiff --git a/test-sha1.c b/test-sha1.c\nindex 9b98d07..80daba9 100644\n--- a/test-sha1.c\n+++ b/test-sha1.c\n@@ -32,7 +32,7 @@ int main(int ac, char **av)\n \t\t\tif (sz == 0)\n \t\t\t\tbreak;\n \t\t\tif (sz < 0)\n-\t\t\t\tdie(\"test-sha1: %s\", strerror(errno));\n+\t\t\t\tdie_errno(\"test-sha1\");\n \t\t\tthis_sz += sz;\n \t\t\tcp += sz;\n \t\t\troom -= sz;\ndiff --git a/wrapper.c b/wrapper.c\nindex 7eb3218..c9be140 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -96,7 +96,7 @@\n \t\trelease_pack_memory(length, fd);\n \t\tret = mmap(start, length, prot, flags, fd, offset);\n \t\tif (ret == MAP_FAILED)\n-\t\t\tdie(\"Out of memory? mmap failed: %s\", strerror(errno));\n+\t\t\tdie_errno(\"Out of memory? mmap failed\");\n \t}\n \treturn ret;\n }\n@@ -175,7 +175,7 @@ int xdup(int fd)\n {\n \tint ret = dup(fd);\n \tif (ret < 0)\n-\t\tdie(\"dup failed: %s\", strerror(errno));\n+\t\tdie_errno(\"dup failed\");\n \treturn ret;\n }\n \n@@ -183,7 +183,7 @@ int xdup(int fd)\n {\n \tFILE *stream = fdopen(fd, mode);\n \tif (stream == NULL)\n-\t\tdie(\"Out of memory? fdopen failed: %s\", strerror(errno));\n+\t\tdie_errno(\"Out of memory? fdopen failed\");\n \treturn stream;\n }\n \n@@ -193,7 +193,7 @@ int xmkstemp(char *template)\n \n \tfd = mkstemp(template);\n \tif (fd < 0)\n-\t\tdie(\"Unable to create temporary file: %s\", strerror(errno));\n+\t\tdie_errno(\"Unable to create temporary file\");\n \treturn fd;\n }\n \ndiff --git a/write_or_die.c b/write_or_die.c\nindex 4c29255..d45b536 100644\n--- a/write_or_die.c\n+++ b/write_or_die.c\n@@ -41,14 +41,14 @@ void maybe_flush_or_die(FILE *f, const char *desc)\n \t\t */\n \t\tif (errno == EPIPE || errno == EINVAL)\n \t\t\texit(0);\n-\t\tdie(\"write failure on %s: %s\", desc, strerror(errno));\n+\t\tdie_errno(\"write failure on '%s'\", desc);\n \t}\n }\n \n void fsync_or_die(int fd, const char *msg)\n {\n \tif (fsync(fd) < 0) {\n-\t\tdie(\"%s: fsync error (%s)\", msg, strerror(errno));\n+\t\tdie_errno(\"fsync error on '%s'\", msg);\n \t}\n }\n \n@@ -57,7 +57,7 @@ void write_or_die(int fd, const void *buf, size_t count)\n \tif (write_in_full(fd, buf, count) < 0) {\n \t\tif (errno == EPIPE)\n \t\t\texit(0);\n-\t\tdie(\"write error (%s)\", strerror(errno));\n+\t\tdie_errno(\"write error\");\n \t}\n }\n \n-- \n1.6.3.2.333.g27636\n"},{"id":"115837","messageId":"00748543db1ade0ba92fc4a23038efa538b209d3.1244494647.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"5a74ed8a911fc1048c021bc3b42e679526bc4c8e.1244494647.git.trast@student.ethz.ch","subject":"[PATCH v3 3/3] Use die_errno() instead of die() when checking syscalls","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-08T21:02:20Z","receivedAt":"2009-06-08T21:02:20Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Lots of die() calls did not actually report the kind of error, which\ncan leave the user confused as to the real problem.  Use die_errno()\nwhere we check a system/library call that sets errno on failure, or\none of the following that wrap such calls:\n\n  Function              Passes on error from\n  --------              --------------------\n  odb_pack_keep         open\n  read_ancestry         fopen\n  read_in_full          xread\n  strbuf_read           xread\n  strbuf_read_file      open or strbuf_read_file\n  strbuf_readlink       readlink\n  write_in_full         xwrite\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n abspath.c               |   12 ++++++------\n builtin-add.c           |    2 +-\n builtin-apply.c         |    6 +++---\n builtin-archive.c       |    4 ++--\n builtin-blame.c         |    8 ++++----\n builtin-clone.c         |   10 +++++-----\n builtin-commit.c        |    5 +++--\n builtin-fast-export.c   |    2 +-\n builtin-fmt-merge-msg.c |    2 +-\n builtin-fsck.c          |    2 +-\n builtin-init-db.c       |   21 +++++++++++----------\n builtin-log.c           |    4 ++--\n builtin-mailsplit.c     |    6 +++---\n builtin-merge.c         |   21 ++++++++++++---------\n builtin-rev-parse.c     |    2 +-\n builtin-revert.c        |    2 +-\n builtin-stripspace.c    |    2 +-\n builtin-tag.c           |    2 +-\n builtin-tar-tree.c      |    2 +-\n combine-diff.c          |    2 +-\n diff.c                  |    6 +++---\n entry.c                 |    2 +-\n fast-import.c           |    4 ++--\n hash-object.c           |    2 +-\n ll-merge.c              |    2 +-\n mktag.c                 |    2 +-\n read-cache.c            |    2 +-\n setup.c                 |   10 +++++-----\n transport.c             |    4 ++--\n unpack-file.c           |    2 +-\n 30 files changed, 79 insertions(+), 74 deletions(-)\n\ndiff --git a/abspath.c b/abspath.c\nindex 649f34f..4bee0ba 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -41,13 +41,13 @@ int is_directory(const char *path)\n \n \t\tif (*buf) {\n \t\t\tif (!*cwd && !getcwd(cwd, sizeof(cwd)))\n-\t\t\t\tdie (\"Could not get current working directory\");\n+\t\t\t\tdie_errno (\"Could not get current working directory\");\n \n \t\t\tif (chdir(buf))\n-\t\t\t\tdie (\"Could not switch to '%s'\", buf);\n+\t\t\t\tdie_errno (\"Could not switch to '%s'\", buf);\n \t\t}\n \t\tif (!getcwd(buf, PATH_MAX))\n-\t\t\tdie (\"Could not get current working directory\");\n+\t\t\tdie_errno (\"Could not get current working directory\");\n \n \t\tif (last_elem) {\n \t\t\tint len = strlen(buf);\n@@ -63,7 +63,7 @@ int is_directory(const char *path)\n \t\tif (!lstat(buf, &st) && S_ISLNK(st.st_mode)) {\n \t\t\tlen = readlink(buf, next_buf, PATH_MAX);\n \t\t\tif (len < 0)\n-\t\t\t\tdie (\"Invalid symlink: %s\", buf);\n+\t\t\t\tdie_errno (\"Invalid symlink '%s'\", buf);\n \t\t\tif (PATH_MAX <= len)\n \t\t\t\tdie(\"symbolic link too long: %s\", buf);\n \t\t\tnext_buf[len] = '\\0';\n@@ -75,7 +75,7 @@ int is_directory(const char *path)\n \t}\n \n \tif (*cwd && chdir(cwd))\n-\t\tdie (\"Could not change back to '%s'\", cwd);\n+\t\tdie_errno (\"Could not change back to '%s'\", cwd);\n \n \treturn buf;\n }\n@@ -109,7 +109,7 @@ int is_directory(const char *path)\n \t} else {\n \t\tconst char *cwd = get_pwd_cwd();\n \t\tif (!cwd)\n-\t\t\tdie(\"Cannot determine the current working directory\");\n+\t\t\tdie_errno(\"Cannot determine the current working directory\");\n \t\tif (snprintf(buf, PATH_MAX, \"%s/%s\", cwd, path) >= PATH_MAX)\n \t\t\tdie(\"Too long path: %.*s\", 60, path);\n \t}\ndiff --git a/builtin-add.c b/builtin-add.c\nindex c1b229a..8f651c1 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -220,7 +220,7 @@ int edit_patch(int argc, const char **argv, const char *prefix)\n \tlaunch_editor(file, NULL, NULL);\n \n \tif (stat(file, &st))\n-\t\tdie(\"Could not stat '%s'\", file);\n+\t\tdie_errno(\"Could not stat '%s'\", file);\n \tif (!st.st_size)\n \t\tdie(\"Empty patch. Aborted.\");\n \ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 6526c08..dbc7f21 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2823,8 +2823,8 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned \n \t} else {\n \t\tif (!cached) {\n \t\t\tif (lstat(path, &st) < 0)\n-\t\t\t\tdie(\"unable to stat newly created file %s\",\n-\t\t\t\t    path);\n+\t\t\t\tdie_errno(\"unable to stat newly created file '%s'\",\n+\t\t\t\t\t  path);\n \t\t\tfill_stat_cache_info(ce, &st);\n \t\t}\n \t\tif (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)\n@@ -2913,7 +2913,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned\n \t\t\t++nr;\n \t\t}\n \t}\n-\tdie(\"unable to write file %s mode %o\", path, mode);\n+\tdie_errno(\"unable to write file '%s' mode %o\", path, mode);\n }\n \n static void create_file(struct patch *patch)\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 3c5a5a7..f9a4bea 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -13,10 +13,10 @@ static void create_output_file(const char *output_file)\n {\n \tint output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);\n \tif (output_fd < 0)\n-\t\tdie(\"could not create archive file: %s \", output_file);\n+\t\tdie_errno(\"could not create archive file '%s'\", output_file);\n \tif (output_fd != 1) {\n \t\tif (dup2(output_fd, 1) < 0)\n-\t\t\tdie(\"could not redirect output\");\n+\t\t\tdie_errno(\"could not redirect output\");\n \t\telse\n \t\t\tclose(output_fd);\n \t}\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 7d8fbd5..fd6ca51 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2008,23 +2008,23 @@ static int git_blame_config(const char *var, const char *value, void *cb)\n \n \t\tif (contents_from) {\n \t\t\tif (stat(contents_from, &st) < 0)\n-\t\t\t\tdie(\"Cannot stat %s\", contents_from);\n+\t\t\t\tdie_errno(\"Cannot stat '%s'\", contents_from);\n \t\t\tread_from = contents_from;\n \t\t}\n \t\telse {\n \t\t\tif (lstat(path, &st) < 0)\n-\t\t\t\tdie(\"Cannot lstat %s\", path);\n+\t\t\t\tdie_errno(\"Cannot lstat '%s'\", path);\n \t\t\tread_from = path;\n \t\t}\n \t\tmode = canon_mode(st.st_mode);\n \t\tswitch (st.st_mode & S_IFMT) {\n \t\tcase S_IFREG:\n \t\t\tif (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)\n-\t\t\t\tdie(\"cannot open or read %s\", read_from);\n+\t\t\t\tdie_errno(\"cannot open or read '%s'\", read_from);\n \t\t\tbreak;\n \t\tcase S_IFLNK:\n \t\t\tif (strbuf_readlink(&buf, read_from, st.st_size) < 0)\n-\t\t\t\tdie(\"cannot readlink %s\", read_from);\n+\t\t\t\tdie_errno(\"cannot readlink '%s'\", read_from);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tdie(\"unsupported file type %s\", read_from);\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex 5f34414..d2b0757 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -220,13 +220,13 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \n \tdir = opendir(src->buf);\n \tif (!dir)\n-\t\tdie(\"failed to open %s\", src->buf);\n+\t\tdie_errno(\"failed to open '%s'\", src->buf);\n \n \tif (mkdir(dest->buf, 0777)) {\n \t\tif (errno != EEXIST)\n-\t\t\tdie(\"failed to create directory %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to create directory '%s'\", dest->buf);\n \t\telse if (stat(dest->buf, &buf))\n-\t\t\tdie(\"failed to stat %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to stat '%s'\", dest->buf);\n \t\telse if (!S_ISDIR(buf.st_mode))\n \t\t\tdie(\"%s exists and is not a directory\", dest->buf);\n \t}\n@@ -257,11 +257,11 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \t\t\tif (!link(src->buf, dest->buf))\n \t\t\t\tcontinue;\n \t\t\tif (option_local)\n-\t\t\t\tdie(\"failed to create link %s\", dest->buf);\n+\t\t\t\tdie_errno(\"failed to create link '%s'\", dest->buf);\n \t\t\toption_no_hardlinks = 1;\n \t\t}\n \t\tif (copy_file(dest->buf, src->buf, 0666))\n-\t\t\tdie(\"failed to copy file to %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to copy file to '%s'\", dest->buf);\n \t}\n \tclosedir(dir);\n }\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 88c51bd..4bcce06 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -434,7 +434,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\tif (isatty(0))\n \t\t\tfprintf(stderr, \"(reading log message from standard input)\\n\");\n \t\tif (strbuf_read(&sb, 0, 0) < 0)\n-\t\t\tdie(\"could not read log from standard input\");\n+\t\t\tdie_errno(\"could not read log from standard input\");\n \t\thook_arg1 = \"message\";\n \t} else if (logfile) {\n \t\tif (strbuf_read_file(&sb, logfile, 0) < 0)\n@@ -964,8 +964,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t/* Finally, get the commit message */\n \tstrbuf_reset(&sb);\n \tif (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n+\t\tint saved_errno = errno;\n \t\trollback_index_files();\n-\t\tdie(\"could not read commit message\");\n+\t\tdie(\"could not read commit message: %s\", strerror(saved_errno));\n \t}\n \n \t/* Truncate the message just before the diff, if any. */\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 333d438..9a8a6fc 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -119,7 +119,7 @@ static void handle_object(const unsigned char *sha1)\n \n \tprintf(\"blob\\nmark :%\"PRIu32\"\\ndata %lu\\n\", last_idnum, size);\n \tif (size && fwrite(buf, size, 1, stdout) != 1)\n-\t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n+\t\tdie_errno (\"Could not write blob '%s'\", sha1_to_hex(sha1));\n \tprintf(\"\\n\");\n \n \tshow_progress();\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 1248d5e..9d52400 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -368,7 +368,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tif (inpath && strcmp(inpath, \"-\")) {\n \t\tin = fopen(inpath, \"r\");\n \t\tif (!in)\n-\t\t\tdie(\"cannot open %s\", inpath);\n+\t\t\tdie_errno(\"cannot open '%s'\", inpath);\n \t}\n \n \tif (strbuf_read(&input, fileno(in), 0) < 0)\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex a49dbe1..d0f48cd 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -217,7 +217,7 @@ static void check_unreachable_object(struct object *obj)\n \t\t\t\treturn;\n \t\t\t}\n \t\t\tif (!(f = fopen(filename, \"w\")))\n-\t\t\t\tdie(\"Could not open %s\", filename);\n+\t\t\t\tdie_errno(\"Could not open '%s'\", filename);\n \t\t\tif (obj->type == OBJ_BLOB) {\n \t\t\t\tenum object_type type;\n \t\t\t\tunsigned long size;\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex d1fa12a..4a56006 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -61,20 +61,20 @@ static void copy_templates_1(char *path, int baselen,\n \t\tmemcpy(template + template_baselen, de->d_name, namelen+1);\n \t\tif (lstat(path, &st_git)) {\n \t\t\tif (errno != ENOENT)\n-\t\t\t\tdie(\"cannot stat %s\", path);\n+\t\t\t\tdie_errno(\"cannot stat '%s'\", path);\n \t\t}\n \t\telse\n \t\t\texists = 1;\n \n \t\tif (lstat(template, &st_template))\n-\t\t\tdie(\"cannot stat template %s\", template);\n+\t\t\tdie_errno(\"cannot stat template '%s'\", template);\n \n \t\tif (S_ISDIR(st_template.st_mode)) {\n \t\t\tDIR *subdir = opendir(template);\n \t\t\tint baselen_sub = baselen + namelen;\n \t\t\tint template_baselen_sub = template_baselen + namelen;\n \t\t\tif (!subdir)\n-\t\t\t\tdie(\"cannot opendir %s\", template);\n+\t\t\t\tdie_errno(\"cannot opendir '%s'\", template);\n \t\t\tpath[baselen_sub++] =\n \t\t\t\ttemplate[template_baselen_sub++] = '/';\n \t\t\tpath[baselen_sub] =\n@@ -91,16 +91,17 @@ static void copy_templates_1(char *path, int baselen,\n \t\t\tint len;\n \t\t\tlen = readlink(template, lnk, sizeof(lnk));\n \t\t\tif (len < 0)\n-\t\t\t\tdie(\"cannot readlink %s\", template);\n+\t\t\t\tdie_errno(\"cannot readlink '%s'\", template);\n \t\t\tif (sizeof(lnk) <= len)\n \t\t\t\tdie(\"insanely long symlink %s\", template);\n \t\t\tlnk[len] = 0;\n \t\t\tif (symlink(lnk, path))\n-\t\t\t\tdie(\"cannot symlink %s %s\", lnk, path);\n+\t\t\t\tdie_errno(\"cannot symlink '%s' '%s'\", lnk, path);\n \t\t}\n \t\telse if (S_ISREG(st_template.st_mode)) {\n \t\t\tif (copy_file(path, template, st_template.st_mode))\n-\t\t\t\tdie(\"cannot copy %s to %s\", template, path);\n+\t\t\t\tdie_errno(\"cannot copy '%s' to '%s'\", template,\n+\t\t\t\t\t  path);\n \t\t}\n \t\telse\n \t\t\terror(\"ignoring template %s\", template);\n@@ -350,7 +351,7 @@ static int guess_repository_type(const char *git_dir)\n \tif (!strcmp(\".\", git_dir))\n \t\treturn 1;\n \tif (!getcwd(cwd, sizeof(cwd)))\n-\t\tdie(\"cannot tell cwd\");\n+\t\tdie_errno(\"cannot tell cwd\");\n \tif (!strcmp(git_dir, cwd))\n \t\treturn 1;\n \t/*\n@@ -440,11 +441,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tif (!git_work_tree_cfg) {\n \t\t\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n \t\t\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n-\t\t\t\tdie (\"Cannot access current working directory.\");\n+\t\t\t\tdie_errno (\"Cannot access current working directory\");\n \t\t}\n \t\tif (access(get_git_work_tree(), X_OK))\n-\t\t\tdie (\"Cannot access work tree '%s'\",\n-\t\t\t     get_git_work_tree());\n+\t\t\tdie_errno (\"Cannot access work tree '%s'\",\n+\t\t\t\t   get_git_work_tree());\n \t}\n \n \tset_git_dir(make_absolute_path(git_dir));\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 0d34050..750957c 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -1013,8 +1013,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tif (use_stdout)\n \t\t\tdie(\"standard output, or directory, which one?\");\n \t\tif (mkdir(output_directory, 0777) < 0 && errno != EEXIST)\n-\t\t\tdie(\"Could not create directory %s\",\n-\t\t\t    output_directory);\n+\t\t\tdie_errno(\"Could not create directory '%s'\",\n+\t\t\t\t  output_directory);\n \t}\n \n \tif (rev.pending.nr == 1) {\ndiff --git a/builtin-mailsplit.c b/builtin-mailsplit.c\nindex 71f3b3b..ad5f6b5 100644\n--- a/builtin-mailsplit.c\n+++ b/builtin-mailsplit.c\n@@ -81,7 +81,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \n \tfd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);\n \tif (fd < 0)\n-\t\tdie(\"cannot open output file %s\", name);\n+\t\tdie_errno(\"cannot open output file '%s'\", name);\n \toutput = fdopen(fd, \"w\");\n \n \t/* Copy it out, while searching for a line that begins with\n@@ -91,7 +91,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \t\tint is_partial = len && buf[len-1] != '\\n';\n \n \t\tif (fwrite(buf, 1, len, output) != len)\n-\t\t\tdie(\"cannot write output\");\n+\t\t\tdie_errno(\"cannot write output\");\n \n \t\tlen = read_line_with_nul(buf, sizeof(buf), mbox);\n \t\tif (len == 0) {\n@@ -99,7 +99,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \t\t\t\tstatus = 1;\n \t\t\t\tbreak;\n \t\t\t}\n-\t\t\tdie(\"cannot read mbox\");\n+\t\t\tdie_errno(\"cannot read mbox\");\n \t\t}\n \t\tif (!is_partial && !is_bare && is_from_line(buf, len))\n \t\t\tbreak; /* done with one message */\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 436263b..82335b0 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -268,7 +268,7 @@ static void squash_message(void)\n \tprintf(\"Squash commit -- not updating HEAD\\n\");\n \tfd = open(git_path(\"SQUASH_MSG\"), O_WRONLY | O_CREAT, 0666);\n \tif (fd < 0)\n-\t\tdie(\"Could not write to %s\", git_path(\"SQUASH_MSG\"));\n+\t\tdie_errno(\"Could not write to '%s'\", git_path(\"SQUASH_MSG\"));\n \n \tinit_revisions(&rev, NULL);\n \trev.ignore_merges = 1;\n@@ -764,7 +764,8 @@ static int suggest_conflicts(void)\n \n \tfp = fopen(git_path(\"MERGE_MSG\"), \"a\");\n \tif (!fp)\n-\t\tdie(\"Could not open %s for writing\", git_path(\"MERGE_MSG\"));\n+\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t  git_path(\"MERGE_MSG\"));\n \tfprintf(fp, \"\\nConflicts:\\n\");\n \tfor (pos = 0; pos < active_nr; pos++) {\n \t\tstruct cache_entry *ce = active_cache[pos];\n@@ -1186,27 +1187,29 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t\tsha1_to_hex(j->item->object.sha1));\n \t\tfd = open(git_path(\"MERGE_HEAD\"), O_WRONLY | O_CREAT, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\",\n-\t\t\t\tgit_path(\"MERGE_HEAD\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_HEAD\"));\n \t\tif (write_in_full(fd, buf.buf, buf.len) != buf.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_HEAD\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_HEAD\"));\n \t\tclose(fd);\n \t\tstrbuf_addch(&merge_msg, '\\n');\n \t\tfd = open(git_path(\"MERGE_MSG\"), O_WRONLY | O_CREAT, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\", git_path(\"MERGE_MSG\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_MSG\"));\n \t\tif (write_in_full(fd, merge_msg.buf, merge_msg.len) !=\n \t\t\tmerge_msg.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_MSG\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_MSG\"));\n \t\tclose(fd);\n \t\tfd = open(git_path(\"MERGE_MODE\"), O_WRONLY | O_CREAT | O_TRUNC, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\", git_path(\"MERGE_MODE\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_MODE\"));\n \t\tstrbuf_reset(&buf);\n \t\tif (!allow_fast_forward)\n \t\t\tstrbuf_addf(&buf, \"no-ff\");\n \t\tif (write_in_full(fd, buf.buf, buf.len) != buf.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_MODE\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_MODE\"));\n \t\tclose(fd);\n \t}\n \ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 112d622..da26dbc 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -592,7 +592,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n \t\t\t\tif (!getcwd(cwd, PATH_MAX))\n-\t\t\t\t\tdie(\"unable to get current working directory\");\n+\t\t\t\t\tdie_errno(\"unable to get current working directory\");\n \t\t\t\tprintf(\"%s/.git\\n\", cwd);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin-revert.c b/builtin-revert.c\nindex c87115a..151aa6a 100644\n--- a/builtin-revert.c\n+++ b/builtin-revert.c\n@@ -135,7 +135,7 @@ static void add_to_msg(const char *string)\n {\n \tint len = strlen(string);\n \tif (write_in_full(msg_fd, string, len) < 0)\n-\t\tdie (\"Could not write to MERGE_MSG\");\n+\t\tdie_errno (\"Could not write to MERGE_MSG\");\n }\n \n static void add_message_to_msg(const char *message)\ndiff --git a/builtin-stripspace.c b/builtin-stripspace.c\nindex d6e3896..1fd2205 100644\n--- a/builtin-stripspace.c\n+++ b/builtin-stripspace.c\n@@ -78,7 +78,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)\n \t\tstrip_comments = 1;\n \n \tif (strbuf_read(&buf, 0, 1024) < 0)\n-\t\tdie(\"could not read the input\");\n+\t\tdie_errno(\"could not read the input\");\n \n \tstripspace(&buf, strip_comments);\n \ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex 7b51095..165bec3 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -442,7 +442,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\telse {\n \t\t\tif (!strcmp(msgfile, \"-\")) {\n \t\t\t\tif (strbuf_read(&buf, 0, 1024) < 0)\n-\t\t\t\t\tdie(\"cannot read %s\", msgfile);\n+\t\t\t\t\tdie_errno(\"cannot read '%s'\", msgfile);\n \t\t\t} else {\n \t\t\t\tif (strbuf_read_file(&buf, msgfile, 1024) < 0)\n \t\t\t\t\tdie_errno(\"could not open or read '%s'\",\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f88e721..8b3a35e 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -91,7 +91,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)\n \n \tn = write_in_full(1, content + 11, 41);\n \tif (n < 41)\n-\t\tdie(\"git get-tar-commit-id: write error\");\n+\t\tdie_errno(\"git get-tar-commit-id: write error\");\n \n \treturn 0;\n }\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 60d0367..bbf74fc 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -746,7 +746,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \t\t\tdone = read_in_full(fd, result, len);\n \t\t\tif (done < 0)\n-\t\t\t\tdie(\"read error '%s'\", elem->path);\n+\t\t\t\tdie_errno(\"read error '%s'\", elem->path);\n \t\t\telse if (done < len)\n \t\t\t\tdie(\"early EOF '%s'\", elem->path);\n \ndiff --git a/diff.c b/diff.c\nindex 48043f5..aec613f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1982,7 +1982,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tsize = buf.len;\n \t}\n \tif (write_in_full(fd, blob, size) != size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n \ttemp->name = temp->tmp_path;\n \tstrcpy(temp->hex, sha1_to_hex(sha1));\n@@ -2026,7 +2026,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tif (S_ISLNK(st.st_mode)) {\n \t\t\tstruct strbuf sb = STRBUF_INIT;\n \t\t\tif (strbuf_readlink(&sb, name, st.st_size) < 0)\n-\t\t\t\tdie(\"readlink(%s)\", name);\n+\t\t\t\tdie_errno(\"readlink(%s)\", name);\n \t\t\tprep_temp_blob(name, temp, sb.buf, sb.len,\n \t\t\t\t       (one->sha1_valid ?\n \t\t\t\t\tone->sha1 : null_sha1),\n@@ -2219,7 +2219,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)\n \t\t\t\treturn;\n \t\t\t}\n \t\t\tif (lstat(one->path, &st) < 0)\n-\t\t\t\tdie(\"stat %s\", one->path);\n+\t\t\t\tdie_errno(\"stat '%s'\", one->path);\n \t\t\tif (index_path(one->sha1, one->path, &st, 0))\n \t\t\t\tdie(\"cannot hash %s\", one->path);\n \t\t}\ndiff --git a/entry.c b/entry.c\nindex 8ec880b..d3e86c7 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -37,7 +37,7 @@ static void create_directories(const char *path, int path_len,\n \t\t\tif (errno == EEXIST && state->force &&\n \t\t\t    !unlink_or_warn(buf) && !mkdir(buf, 0777))\n \t\t\t\tcontinue;\n-\t\t\tdie(\"cannot create directory at %s\", buf);\n+\t\t\tdie_errno(\"cannot create directory at '%s'\", buf);\n \t\t}\n \t}\n \tfree(buf);\ndiff --git a/fast-import.c b/fast-import.c\nindex d31a4e8..7ef9865 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -905,10 +905,10 @@ static int oecmp (const void *a_, const void *b_)\n \n \tkeep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);\n \tif (keep_fd < 0)\n-\t\tdie(\"cannot create keep file\");\n+\t\tdie_errno(\"cannot create keep file\");\n \twrite_or_die(keep_fd, keep_msg, strlen(keep_msg));\n \tif (close(keep_fd))\n-\t\tdie(\"failed to write keep file\");\n+\t\tdie_errno(\"failed to write keep file\");\n \n \tsnprintf(name, sizeof(name), \"%s/pack/pack-%s.pack\",\n \t\t get_object_directory(), sha1_to_hex(pack_data->sha1));\ndiff --git a/hash-object.c b/hash-object.c\nindex 47cf43c..9455dd0 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -29,7 +29,7 @@ static void hash_object(const char *path, const char *type, int write_object,\n \tint fd;\n \tfd = open(path, O_RDONLY);\n \tif (fd < 0)\n-\t\tdie(\"Cannot open %s\", path);\n+\t\tdie_errno(\"Cannot open '%s'\", path);\n \thash_fd(fd, type, write_object, vpath);\n }\n \ndiff --git a/ll-merge.c b/ll-merge.c\nindex 81c02ad..caf22be 100644\n--- a/ll-merge.c\n+++ b/ll-merge.c\n@@ -152,7 +152,7 @@ static void create_temp(mmfile_t *src, char *path)\n \tstrcpy(path, \".merge_file_XXXXXX\");\n \tfd = xmkstemp(path);\n \tif (write_in_full(fd, src->ptr, src->size) != src->size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n }\n \ndiff --git a/mktag.c b/mktag.c\nindex 99a356e..a609e3e 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -165,7 +165,7 @@ int main(int argc, char **argv)\n \tsetup_git_directory();\n \n \tif (strbuf_read(&buf, 0, 4096) < 0) {\n-\t\tdie(\"could not read from stdin\");\n+\t\tdie_errno(\"could not read from stdin\");\n \t}\n \n \t/* Verify it for some basic sanity: it needs to start with\ndiff --git a/read-cache.c b/read-cache.c\nindex f76b5bb..4e3e272 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1265,7 +1265,7 @@ int read_index_from(struct index_state *istate, const char *path)\n \tmmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n \tclose(fd);\n \tif (mmap == MAP_FAILED)\n-\t\tdie(\"unable to map index file\");\n+\t\tdie_errno(\"unable to map index file\");\n \n \thdr = mmap;\n \tif (verify_hdr(hdr, mmap_size) < 0)\ndiff --git a/setup.c b/setup.c\nindex 4d27f28..e3781b6 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -327,7 +327,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\t\t\treturn NULL;\n \t\t\tset_git_dir(make_absolute_path(gitdirenv));\n \t\t\tif (chdir(work_tree_env) < 0)\n-\t\t\t\tdie (\"Could not chdir to %s\", work_tree_env);\n+\t\t\t\tdie_errno (\"Could not chdir to '%s'\", work_tree_env);\n \t\t\tstrcat(buffer, \"/\");\n \t\t\treturn retval;\n \t\t}\n@@ -339,7 +339,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t}\n \n \tif (!getcwd(cwd, sizeof(cwd)-1))\n-\t\tdie(\"Unable to read current working directory\");\n+\t\tdie_errno(\"Unable to read current working directory\");\n \n \tceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);\n \tif (ceil_offset < 0 && has_dos_drive_prefix(cwd))\n@@ -382,7 +382,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\tif (offset <= ceil_offset) {\n \t\t\tif (nongit_ok) {\n \t\t\t\tif (chdir(cwd))\n-\t\t\t\t\tdie(\"Cannot come back to cwd\");\n+\t\t\t\t\tdie_errno(\"Cannot come back to cwd\");\n \t\t\t\t*nongit_ok = 1;\n \t\t\t\treturn NULL;\n \t\t\t}\n@@ -493,10 +493,10 @@ int check_repository_format(void)\n \t\tstatic char buffer[PATH_MAX + 1];\n \t\tchar *rel;\n \t\tif (retval && chdir(retval))\n-\t\t\tdie (\"Could not jump back into original cwd\");\n+\t\t\tdie_errno (\"Could not jump back into original cwd\");\n \t\trel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());\n \t\tif (rel && *rel && chdir(get_git_work_tree()))\n-\t\t\tdie (\"Could not jump to working directory\");\n+\t\t\tdie_errno (\"Could not jump to working directory\");\n \t\treturn rel && *rel ? strcat(rel, \"/\") : NULL;\n \t}\n \ndiff --git a/transport.c b/transport.c\nindex 17891d5..8decd66 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -158,7 +158,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)\n \n \tstrbuf_addstr(&temp_dir, git_path(\"rsync-refs-XXXXXX\"));\n \tif (!mkdtemp(temp_dir.buf))\n-\t\tdie (\"Could not make temporary directory\");\n+\t\tdie_errno (\"Could not make temporary directory\");\n \ttemp_dir_len = temp_dir.len;\n \n \tstrbuf_addstr(&buf, rsync_url(transport->url));\n@@ -321,7 +321,7 @@ static int rsync_transport_push(struct transport *transport,\n \n \tstrbuf_addstr(&temp_dir, git_path(\"rsync-refs-XXXXXX\"));\n \tif (!mkdtemp(temp_dir.buf))\n-\t\tdie (\"Could not make temporary directory\");\n+\t\tdie_errno (\"Could not make temporary directory\");\n \tstrbuf_addch(&temp_dir, '/');\n \n \tif (flags & TRANSPORT_PUSH_ALL) {\ndiff --git a/unpack-file.c b/unpack-file.c\nindex 75cd2f1..ac9cbf7 100644\n--- a/unpack-file.c\n+++ b/unpack-file.c\n@@ -17,7 +17,7 @@\n \tstrcpy(path, \".merge_file_XXXXXX\");\n \tfd = xmkstemp(path);\n \tif (write_in_full(fd, buf, size) != size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n \treturn path;\n }\n-- \n1.6.3.2.333.g27636\n"},{"id":"115853","messageId":"20090608220713.GB29942@sigill.intra.peff.net","threadId":"19751","inReplyTo":"5f43aa9d0b69e99600a73bddd4c93217608ab661.1244494647.git.trast@student.ethz.ch","subject":"Re: [PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-06-08T22:07:13Z","receivedAt":"2009-06-08T22:07:13Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 08, 2009 at 11:02:18PM +0200, Thomas Rast wrote:\n\n> +void die_errno(const char *fmt, ...)\n> +{\n> +\tva_list params;\n> +\tchar fmt_with_err[1024];\n> +\n> +\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, strerror(errno));\n> +\n> +\tva_start(params, fmt);\n> +\tdie_routine(fmt_with_err, params);\n> +\tva_end(params);\n> +}\n\nAren't you assuming that strerror(errno) has no '%'-signs here, which is\nwhat kicked off the whole discussion?\n\n-Peff\n"},{"id":"115886","messageId":"200906091022.31738.trast@student.ethz.ch","threadId":"19751","inReplyTo":"20090608220713.GB29942@sigill.intra.peff.net","subject":"Re: [PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-09T08:22:30Z","receivedAt":"2009-06-09T08:22:30Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Jeff King wrote:\n> On Mon, Jun 08, 2009 at 11:02:18PM +0200, Thomas Rast wrote:\n> \n> > +void die_errno(const char *fmt, ...)\n> > +{\n> > +\tva_list params;\n> > +\tchar fmt_with_err[1024];\n> > +\n> > +\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, strerror(errno));\n> > +\n> > +\tva_start(params, fmt);\n> > +\tdie_routine(fmt_with_err, params);\n> > +\tva_end(params);\n> > +}\n> \n> Aren't you assuming that strerror(errno) has no '%'-signs here, which is\n> what kicked off the whole discussion?\n\nTrue, of course.  Hrm.\n\nSo do we go back to v2 (for 1/3) and ask future callers to never use\ncustom formats with die_errno, or should I write a version that\ndoubles the % characters while tacking the error message onto the\nformat?\n\n[It's a pity that it seems impossible to add an extra argument to the\nva_args...]\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"115890","messageId":"20090609085328.GA25721@coredump.intra.peff.net","threadId":"19751","inReplyTo":"200906091022.31738.trast@student.ethz.ch","subject":"Re: [PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-06-09T08:53:28Z","receivedAt":"2009-06-09T08:53:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 09, 2009 at 10:22:30AM +0200, Thomas Rast wrote:\n\n> > Aren't you assuming that strerror(errno) has no '%'-signs here, which is\n> > what kicked off the whole discussion?\n> \n> True, of course.  Hrm.\n> \n> So do we go back to v2 (for 1/3) and ask future callers to never use\n> custom formats with die_errno, or should I write a version that\n> doubles the % characters while tacking the error message onto the\n> format?\n\nPersonally, I think it is fine to assume that the format and arguments\nto die(), die_errno(), and to the die_routine() are all\nprintf-compatible. That is how it has always been until now, and I don't\nsee any callers who would want to change that.\n\nThis is all internal to git.  It's not as if we are talking about a\nlibrary being called by arbitrary code, and we want to leave doors open\nfor arbitrary clients. libgit2 would probably take a different approach\n(though I imagine their general strategy is never to die(), but to\nalways return an error condition, anyway).\n\n> [It's a pity that it seems impossible to add an extra argument to the\n> va_args...]\n\nAgreed, but I think we are out of luck short of variadic macros (which\nare a C99-ism, and even then have some issues).\n\n-Peff\n"},{"id":"115892","messageId":"4A2E2B8F.3020005@op5.se","threadId":"19751","inReplyTo":"20090609085328.GA25721@coredump.intra.peff.net","subject":"Re: [PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2009-06-09T09:29:51Z","receivedAt":"2009-06-09T09:29:51Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Jeff King wrote:\n> On Tue, Jun 09, 2009 at 10:22:30AM +0200, Thomas Rast wrote:\n> \n>>> Aren't you assuming that strerror(errno) has no '%'-signs here, which is\n>>> what kicked off the whole discussion?\n>> True, of course.  Hrm.\n>>\n>> So do we go back to v2 (for 1/3) and ask future callers to never use\n>> custom formats with die_errno, or should I write a version that\n>> doubles the % characters while tacking the error message onto the\n>> format?\n> \n> Personally, I think it is fine to assume that the format and arguments\n> to die(), die_errno(), and to the die_routine() are all\n> printf-compatible. That is how it has always been until now, and I don't\n> see any callers who would want to change that.\n> \n> This is all internal to git.  It's not as if we are talking about a\n> library being called by arbitrary code, and we want to leave doors open\n> for arbitrary clients. libgit2 would probably take a different approach\n> (though I imagine their general strategy is never to die(), but to\n> always return an error condition, anyway).\n> \n\nYup. libgit2 sets an internal git_errno variable and returns an error\ncode for each error it encounters, and we're referring callers to\nregular \"errno\" to find out more about *why* a particular git_errno\ncondition was encountered.\n\nWe might want to give applications an easy way to die with a sensible\nerror message, but that's so far in the future that it's not worth\nbothering with.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"117091","messageId":"cover.1246115204.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1244494646.git.trast@student.ethz.ch","subject":"[PATCH v4 0/4] die_errno()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-27T15:58:43Z","receivedAt":"2009-06-27T15:58:43Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Sorry for taking so long to come up with another iteration; I was on\nholiday last week and rather busy otherwise.\n\nThis just picks up Junio's %-doubling patch from pu, with the extra\nchange I suggested in <200906121204.37752.trast@student.ethz.ch> to\nhandle the border case where a lone % would end up at the end of the\nbuffer.  The rest is the same as v3.\n\n\nJunio C Hamano (1):\n  die_errno(): double % in strerror() output just in case\n\nThomas Rast (3):\n  Introduce die_errno() that appends strerror(errno) to die()\n  Convert existing die(..., strerror(errno)) to die_errno()\n  Use die_errno() instead of die() when checking syscalls\n\n abspath.c                |   12 ++++++------\n bisect.c                 |    5 ++---\n branch.c                 |    4 ++--\n builtin-add.c            |    2 +-\n builtin-apply.c          |   12 ++++++------\n builtin-archive.c        |    4 ++--\n builtin-blame.c          |   15 +++++++--------\n builtin-clone.c          |   21 ++++++++++-----------\n builtin-commit-tree.c    |    2 +-\n builtin-commit.c         |   28 +++++++++++++---------------\n builtin-config.c         |    4 ++--\n builtin-diff.c           |    2 +-\n builtin-fast-export.c    |    4 ++--\n builtin-fetch--tool.c    |    2 +-\n builtin-fmt-merge-msg.c  |    5 ++---\n builtin-fsck.c           |   10 +++++-----\n builtin-grep.c           |    2 +-\n builtin-init-db.c        |   21 +++++++++++----------\n builtin-log.c            |    4 ++--\n builtin-mailsplit.c      |    6 +++---\n builtin-merge.c          |   29 ++++++++++++++++-------------\n builtin-mv.c             |    2 +-\n builtin-pack-objects.c   |   14 +++++---------\n builtin-rev-parse.c      |    2 +-\n builtin-revert.c         |    2 +-\n builtin-rm.c             |    2 +-\n builtin-send-pack.c      |    2 +-\n builtin-stripspace.c     |    2 +-\n builtin-tag.c            |    9 ++++-----\n builtin-tar-tree.c       |    2 +-\n builtin-unpack-objects.c |    2 +-\n combine-diff.c           |    2 +-\n csum-file.c              |    5 ++---\n daemon.c                 |   15 +++++++--------\n diff.c                   |   10 +++++-----\n dir.c                    |    2 +-\n entry.c                  |   10 +++++-----\n fast-import.c            |    8 ++++----\n git-compat-util.h        |    1 +\n git.c                    |    6 +++---\n hash-object.c            |    2 +-\n index-pack.c             |   21 ++++++++++-----------\n ll-merge.c               |    2 +-\n merge-recursive.c        |    6 +++---\n mktag.c                  |    2 +-\n pack-refs.c              |    7 +++----\n pack-write.c             |   10 +++++-----\n pkt-line.c               |    4 ++--\n read-cache.c             |    8 ++++----\n refs.c                   |    2 +-\n run-command.c            |    4 ++--\n setup.c                  |   18 +++++++++---------\n sha1_file.c              |    2 +-\n shell.c                  |    2 +-\n test-sha1.c              |    2 +-\n transport.c              |    4 ++--\n unpack-file.c            |    2 +-\n usage.c                  |   28 ++++++++++++++++++++++++++++\n wrapper.c                |    8 ++++----\n write_or_die.c           |    6 +++---\n 60 files changed, 225 insertions(+), 207 deletions(-)\n"},{"id":"117093","messageId":"352b76f4c7b442cae5c16451396ad129d25ef29a.1246115205.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1246115204.git.trast@student.ethz.ch","subject":"[PATCH v4 1/4] Introduce die_errno() that appends strerror(errno) to die()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-27T15:58:44Z","receivedAt":"2009-06-27T15:58:44Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"There are many calls to die() that do, or should, report\nstrerror(errno) to indicate how the syscall they guard failed.\nIntroduce a small helper function for this case.\n\nNote:\n\n- POSIX says vsnprintf can modify errno in some unlikely cases, so we\n  have to use errno early.\n\n- We take some care to pass the original format to die_routine(), in\n  case someone wants to call die_errno() with custom format\n  characters.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-compat-util.h |    1 +\n usage.c           |   12 ++++++++++++\n 2 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 919b7f1..9609eaa 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -175,6 +175,7 @@\n /* General helper functions */\n extern void usage(const char *err) NORETURN;\n extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n+extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n \ndiff --git a/usage.c b/usage.c\nindex 820d09f..fd936a1 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -60,6 +60,18 @@ void die(const char *err, ...)\n \tva_end(params);\n }\n \n+void die_errno(const char *fmt, ...)\n+{\n+\tva_list params;\n+\tchar fmt_with_err[1024];\n+\n+\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, strerror(errno));\n+\n+\tva_start(params, fmt);\n+\tdie_routine(fmt_with_err, params);\n+\tva_end(params);\n+}\n+\n int error(const char *err, ...)\n {\n \tva_list params;\n-- \n1.6.3.3.433.gc91b\n"},{"id":"117092","messageId":"c3635ed5bd260b5f358893917d05bd09320ae9d6.1246115205.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1246115204.git.trast@student.ethz.ch","subject":"[PATCH v4 2/4] die_errno(): double % in strerror() output just in case","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-27T15:58:45Z","receivedAt":"2009-06-27T15:58:45Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\n[tr: handle border case where % is placed at end of buffer]\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n usage.c |   20 ++++++++++++++++++--\n 1 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/usage.c b/usage.c\nindex fd936a1..b6aea45 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -64,8 +64,24 @@ void die_errno(const char *fmt, ...)\n {\n \tva_list params;\n \tchar fmt_with_err[1024];\n-\n-\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, strerror(errno));\n+\tchar str_error[256], *err;\n+\tint i, j;\n+\n+\terr = strerror(errno);\n+\tfor (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {\n+\t\tif ((str_error[j++] = err[i++]) != '%')\n+\t\t\tcontinue;\n+\t\tif (j < sizeof(str_error) - 1) {\n+\t\t\tstr_error[j++] = '%';\n+\t\t} else {\n+\t\t\t/* No room to double the '%', so we overwrite it with\n+\t\t\t * '\\0' below */\n+\t\t\tj--;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tstr_error[j] = 0;\n+\tsnprintf(fmt_with_err, sizeof(fmt_with_err), \"%s: %s\", fmt, str_error);\n \n \tva_start(params, fmt);\n \tdie_routine(fmt_with_err, params);\n-- \n1.6.3.3.433.gc91b\n"},{"id":"117095","messageId":"4cdc708912562f284a5561bdd862828db169cda6.1246115205.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1246115204.git.trast@student.ethz.ch","subject":"[PATCH v4 3/4] Convert existing die(..., strerror(errno)) to die_errno()","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-27T15:58:46Z","receivedAt":"2009-06-27T15:58:46Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Change calls to die(..., strerror(errno)) to use the new die_errno().\n\nIn the process, also make slight style adjustments: at least state\n_something_ about the function that failed (instead of just printing\nthe pathname), and put paths in single quotes.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n bisect.c                 |    5 ++---\n branch.c                 |    4 ++--\n builtin-apply.c          |    6 +++---\n builtin-blame.c          |    7 +++----\n builtin-clone.c          |   11 +++++------\n builtin-commit-tree.c    |    2 +-\n builtin-commit.c         |   23 ++++++++++-------------\n builtin-config.c         |    4 ++--\n builtin-diff.c           |    2 +-\n builtin-fast-export.c    |    2 +-\n builtin-fetch--tool.c    |    2 +-\n builtin-fmt-merge-msg.c  |    3 +--\n builtin-fsck.c           |    8 ++++----\n builtin-grep.c           |    2 +-\n builtin-merge.c          |    8 ++++----\n builtin-mv.c             |    2 +-\n builtin-pack-objects.c   |   14 +++++---------\n builtin-rm.c             |    2 +-\n builtin-send-pack.c      |    2 +-\n builtin-tag.c            |    7 +++----\n builtin-unpack-objects.c |    2 +-\n csum-file.c              |    5 ++---\n daemon.c                 |   15 +++++++--------\n diff.c                   |    4 ++--\n dir.c                    |    2 +-\n entry.c                  |    8 ++++----\n fast-import.c            |    4 ++--\n git.c                    |    6 +++---\n index-pack.c             |   21 ++++++++++-----------\n merge-recursive.c        |    6 +++---\n pack-refs.c              |    7 +++----\n pack-write.c             |   10 +++++-----\n pkt-line.c               |    4 ++--\n read-cache.c             |    6 +++---\n refs.c                   |    2 +-\n run-command.c            |    4 ++--\n setup.c                  |    8 ++++----\n sha1_file.c              |    2 +-\n shell.c                  |    2 +-\n test-sha1.c              |    2 +-\n wrapper.c                |    8 ++++----\n write_or_die.c           |    6 +++---\n 42 files changed, 117 insertions(+), 133 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex dbeb287..20286cc 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -461,7 +461,7 @@ static void read_bisect_paths(struct argv_array *array)\n \tFILE *fp = fopen(filename, \"r\");\n \n \tif (!fp)\n-\t\tdie(\"Could not open file '%s': %s\", filename, strerror(errno));\n+\t\tdie_errno(\"Could not open file '%s'\", filename);\n \n \twhile (strbuf_getline(&str, fp, '\\n') != EOF) {\n \t\tchar *quoted;\n@@ -712,8 +712,7 @@ static void mark_expected_rev(char *bisect_rev_hex)\n \tint fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n \n \tif (fd < 0)\n-\t\tdie(\"could not create file '%s': %s\",\n-\t\t    filename, strerror(errno));\n+\t\tdie_errno(\"could not create file '%s'\", filename);\n \n \tbisect_rev_hex[len] = '\\n';\n \twrite_or_die(fd, bisect_rev_hex, len + 1);\ndiff --git a/branch.c b/branch.c\nindex 62030af..05ef3f5 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -172,7 +172,7 @@ void create_branch(const char *head,\n \n \tlock = lock_any_ref_for_update(ref.buf, NULL, 0);\n \tif (!lock)\n-\t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n+\t\tdie_errno(\"Failed to lock ref for update\");\n \n \tif (reflog)\n \t\tlog_all_ref_updates = 1;\n@@ -188,7 +188,7 @@ void create_branch(const char *head,\n \t\tsetup_tracking(name, real_ref, track);\n \n \tif (write_ref_sha1(lock, sha1, msg) < 0)\n-\t\tdie(\"Failed to write ref: %s.\", strerror(errno));\n+\t\tdie_errno(\"Failed to write ref\");\n \n \tstrbuf_release(&ref);\n \tfree(real_ref);\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 4cf819c..2df2cb9 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,\n static void read_patch_file(struct strbuf *sb, int fd)\n {\n \tif (strbuf_read(sb, fd, 0) < 0)\n-\t\tdie(\"git apply: read returned %s\", strerror(errno));\n+\t\tdie_errno(\"git apply: failed to read\");\n \n \t/*\n \t * Make sure that we have some slop in the buffer\n@@ -2864,7 +2864,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \tstrbuf_release(&nbuf);\n \n \tif (close(fd) < 0)\n-\t\tdie(\"closing file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"closing file '%s'\", path);\n \treturn 0;\n }\n \n@@ -3356,7 +3356,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \n \t\tfd = open(arg, O_RDONLY);\n \t\tif (fd < 0)\n-\t\t\tdie(\"can't open patch '%s': %s\", arg, strerror(errno));\n+\t\t\tdie_errno(\"can't open patch '%s'\", arg);\n \t\tread_stdin = 0;\n \t\tset_default_whitespace_mode(whitespace_option);\n \t\terrs |= apply_patch(fd, arg, options);\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 0c2d29a..7d8fbd5 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2035,7 +2035,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)\n \t\tcontents_from = \"standard input\";\n \t\tmode = 0;\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n-\t\t\tdie(\"read error %s from stdin\", strerror(errno));\n+\t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n \tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n \torigin->file.ptr = buf.buf;\n@@ -2261,8 +2261,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \targc = parse_options_end(&ctx);\n \n \tif (revs_file && read_ancestry(revs_file))\n-\t\tdie(\"reading graft file %s failed: %s\",\n-\t\t    revs_file, strerror(errno));\n+\t\tdie_errno(\"reading graft file '%s' failed\", revs_file);\n \n \tif (cmd_is_annotate) {\n \t\toutput_option |= OUTPUT_ANNOTATE_COMPAT;\n@@ -2350,7 +2349,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \n \t\tsetup_work_tree();\n \t\tif (!has_string_in_work_tree(path))\n-\t\t\tdie(\"cannot stat path %s: %s\", path, strerror(errno));\n+\t\t\tdie_errno(\"cannot stat path '%s'\", path);\n \t}\n \n \tsetup_revisions(argc, argv, &revs, NULL);\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex 2ceacb7..ccb0480 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -252,8 +252,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \t\t}\n \n \t\tif (unlink(dest->buf) && errno != ENOENT)\n-\t\t\tdie(\"failed to unlink %s: %s\",\n-\t\t\t    dest->buf, strerror(errno));\n+\t\t\tdie_errno(\"failed to unlink '%s'\", dest->buf);\n \t\tif (!option_no_hardlinks) {\n \t\t\tif (!link(src->buf, dest->buf))\n \t\t\t\tcontinue;\n@@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tif (!option_bare) {\n \t\tjunk_work_tree = work_tree;\n \t\tif (safe_create_leading_directories_const(work_tree) < 0)\n-\t\t\tdie(\"could not create leading directories of '%s': %s\",\n-\t\t\t\t\twork_tree, strerror(errno));\n+\t\t\tdie_errno(\"could not create leading directories of '%s'\",\n+\t\t\t\t  work_tree);\n \t\tif (!dest_exists && mkdir(work_tree, 0755))\n-\t\t\tdie(\"could not create work tree dir '%s': %s.\",\n-\t\t\t\t\twork_tree, strerror(errno));\n+\t\t\tdie_errno(\"could not create work tree dir '%s'.\",\n+\t\t\t\t  work_tree);\n \t\tset_git_work_tree(work_tree);\n \t}\n \tjunk_git_dir = git_dir;\ndiff --git a/builtin-commit-tree.c b/builtin-commit-tree.c\nindex 0453425..6467077 100644\n--- a/builtin-commit-tree.c\n+++ b/builtin-commit-tree.c\n@@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (strbuf_read(&buffer, 0, 0) < 0)\n-\t\tdie(\"git commit-tree: read returned %s\", strerror(errno));\n+\t\tdie_errno(\"git commit-tree: failed to read\");\n \n \tif (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {\n \t\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 41e222d..88c51bd 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -438,8 +438,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\thook_arg1 = \"message\";\n \t} else if (logfile) {\n \t\tif (strbuf_read_file(&sb, logfile, 0) < 0)\n-\t\t\tdie(\"could not read log file '%s': %s\",\n-\t\t\t    logfile, strerror(errno));\n+\t\t\tdie_errno(\"could not read log file '%s'\",\n+\t\t\t\t  logfile);\n \t\thook_arg1 = \"message\";\n \t} else if (use_message) {\n \t\tbuffer = strstr(use_message_buffer, \"\\n\\n\");\n@@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\thook_arg2 = use_message;\n \t} else if (!stat(git_path(\"MERGE_MSG\"), &statbuf)) {\n \t\tif (strbuf_read_file(&sb, git_path(\"MERGE_MSG\"), 0) < 0)\n-\t\t\tdie(\"could not read MERGE_MSG: %s\", strerror(errno));\n+\t\t\tdie_errno(\"could not read MERGE_MSG\");\n \t\thook_arg1 = \"merge\";\n \t} else if (!stat(git_path(\"SQUASH_MSG\"), &statbuf)) {\n \t\tif (strbuf_read_file(&sb, git_path(\"SQUASH_MSG\"), 0) < 0)\n-\t\t\tdie(\"could not read SQUASH_MSG: %s\", strerror(errno));\n+\t\t\tdie_errno(\"could not read SQUASH_MSG\");\n \t\thook_arg1 = \"squash\";\n \t} else if (template_file && !stat(template_file, &statbuf)) {\n \t\tif (strbuf_read_file(&sb, template_file, 0) < 0)\n-\t\t\tdie(\"could not read %s: %s\",\n-\t\t\t    template_file, strerror(errno));\n+\t\t\tdie_errno(\"could not read '%s'\", template_file);\n \t\thook_arg1 = \"template\";\n \t}\n \n@@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \n \tfp = fopen(git_path(commit_editmsg), \"w\");\n \tif (fp == NULL)\n-\t\tdie(\"could not open %s: %s\",\n-\t\t    git_path(commit_editmsg), strerror(errno));\n+\t\tdie_errno(\"could not open '%s'\", git_path(commit_editmsg));\n \n \tif (cleanup_mode != CLEANUP_NONE)\n \t\tstripspace(&sb, 0);\n@@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t}\n \n \tif (fwrite(sb.buf, 1, sb.len, fp) < sb.len)\n-\t\tdie(\"could not write commit template: %s\", strerror(errno));\n+\t\tdie_errno(\"could not write commit template\");\n \n \tstrbuf_release(&sb);\n \n@@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tpptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;\n \t\tfp = fopen(git_path(\"MERGE_HEAD\"), \"r\");\n \t\tif (fp == NULL)\n-\t\t\tdie(\"could not open %s for reading: %s\",\n-\t\t\t    git_path(\"MERGE_HEAD\"), strerror(errno));\n+\t\t\tdie_errno(\"could not open '%s' for reading\",\n+\t\t\t\t  git_path(\"MERGE_HEAD\"));\n \t\twhile (strbuf_getline(&m, fp, '\\n') != EOF) {\n \t\t\tunsigned char sha1[20];\n \t\t\tif (get_sha1_hex(m.buf, sha1) < 0)\n@@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tstrbuf_release(&m);\n \t\tif (!stat(git_path(\"MERGE_MODE\"), &statbuf)) {\n \t\t\tif (strbuf_read_file(&sb, git_path(\"MERGE_MODE\"), 0) < 0)\n-\t\t\t\tdie(\"could not read MERGE_MODE: %s\",\n-\t\t\t\t\t\tstrerror(errno));\n+\t\t\t\tdie_errno(\"could not read MERGE_MODE\");\n \t\t\tif (!strcmp(sb.buf, \"no-ff\"))\n \t\t\t\tallow_fast_forward = 0;\n \t\t}\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 60915f9..a2d656e 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config(show_all_config, NULL) < 0) {\n \t\t\tif (config_exclusive_filename)\n-\t\t\t\tdie(\"unable to read config file %s: %s\",\n-\t\t\t\t    config_exclusive_filename, strerror(errno));\n+\t\t\t\tdie_errno(\"unable to read config file '%s'\",\n+\t\t\t\t\t  config_exclusive_filename);\n \t\t\telse\n \t\t\t\tdie(\"error processing config file(s)\");\n \t\t}\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex d75d69b..2e51f40 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,\n \t\tusage(builtin_diff_usage);\n \n \tif (lstat(path, &st))\n-\t\tdie(\"'%s': %s\", path, strerror(errno));\n+\t\tdie_errno(\"failed to stat '%s'\", path);\n \tif (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))\n \t\tdie(\"'%s': not a regular file or symlink\", path);\n \ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 6cef810..333d438 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -451,7 +451,7 @@ static void import_marks(char *input_file)\n \tchar line[512];\n \tFILE *f = fopen(input_file, \"r\");\n \tif (!f)\n-\t\tdie(\"cannot read %s: %s\", input_file, strerror(errno));\n+\t\tdie_errno(\"cannot read '%s'\", input_file);\n \n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuint32_t mark;\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 29356d2..3dbdf7a 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -8,7 +8,7 @@\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tif (strbuf_read(&buf, 0, 1024) < 0) {\n-\t\tdie(\"error reading standard input: %s\", strerror(errno));\n+\t\tdie_errno(\"error reading standard input\");\n \t}\n \treturn strbuf_detach(&buf, NULL);\n }\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex fbf9582..1248d5e 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -372,8 +372,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (strbuf_read(&input, fileno(in), 0) < 0)\n-\t\tdie(\"could not read input file %s\", strerror(errno));\n-\n+\t\tdie_errno(\"could not read input file\");\n \tret = fmt_merge_msg(merge_summary, &input, &output);\n \tif (ret)\n \t\treturn ret;\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex e077e72..32a1e41 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)\n \t\t\t\t\t\t&type, &size);\n \t\t\t\tif (buf) {\n \t\t\t\t\tif (fwrite(buf, size, 1, f) != 1)\n-\t\t\t\t\t\tdie(\"Could not write %s: %s\",\n-\t\t\t\t\t\t    filename, strerror(errno));\n+\t\t\t\t\t\tdie_errno(\"Could not write '%s'\",\n+\t\t\t\t\t\t\t  filename);\n \t\t\t\t\tfree(buf);\n \t\t\t\t}\n \t\t\t} else\n \t\t\t\tfprintf(f, \"%s\\n\", sha1_to_hex(obj->sha1));\n \t\t\tif (fclose(f))\n-\t\t\t\tdie(\"Could not finish %s: %s\",\n-\t\t\t\t    filename, strerror(errno));\n+\t\t\t\tdie_errno(\"Could not finish '%s'\",\n+\t\t\t\t\t  filename);\n \t\t}\n \t\treturn;\n \t}\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 73fc922..e558368 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)\n \n \tpatterns = fopen(arg, \"r\");\n \tif (!patterns)\n-\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\tdie_errno(\"cannot open '%s'\", arg);\n \twhile (strbuf_getline(&sb, patterns, '\\n') == 0) {\n \t\t/* ignore empty line like grep does */\n \t\tif (sb.len == 0)\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex af9adab..5ad2188 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -294,9 +294,9 @@ static void squash_message(void)\n \t\t\tNULL, NULL, rev.date_mode, 0);\n \t}\n \tif (write(fd, out.buf, out.len) < 0)\n-\t\tdie(\"Writing SQUASH_MSG: %s\", strerror(errno));\n+\t\tdie_errno(\"Writing SQUASH_MSG\");\n \tif (close(fd))\n-\t\tdie(\"Finishing SQUASH_MSG: %s\", strerror(errno));\n+\t\tdie_errno(\"Finishing SQUASH_MSG\");\n \tstrbuf_release(&out);\n }\n \n@@ -428,8 +428,8 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \n \t\tfp = fopen(git_path(\"FETCH_HEAD\"), \"r\");\n \t\tif (!fp)\n-\t\t\tdie(\"could not open %s for reading: %s\",\n-\t\t\t\tgit_path(\"FETCH_HEAD\"), strerror(errno));\n+\t\t\tdie_errno(\"could not open '%s' for reading\",\n+\t\t\t\t  git_path(\"FETCH_HEAD\"));\n \t\tstrbuf_getline(&line, fp, '\\n');\n \t\tfclose(fp);\n \t\tptr = strstr(line.buf, \"\\tnot-for-merge\\t\");\ndiff --git a/builtin-mv.c b/builtin-mv.c\nindex 8b81d4b..024dfeb 100644\n--- a/builtin-mv.c\n+++ b/builtin-mv.c\n@@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(\"Renaming %s to %s\\n\", src, dst);\n \t\tif (!show_only && mode != INDEX &&\n \t\t\t\trename(src, dst) < 0 && !ignore_errors)\n-\t\t\tdie (\"renaming %s failed: %s\", src, strerror(errno));\n+\t\t\tdie_errno (\"renaming '%s' failed\", src);\n \n \t\tif (mode == WORKING_DIRECTORY)\n \t\t\tcontinue;\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 941cc2d..a27c2f6 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -536,11 +536,9 @@ static void write_pack_file(void)\n \t\t\t\t base_name, sha1_to_hex(sha1));\n \t\t\tfree_pack_by_name(tmpname);\n \t\t\tif (adjust_perm(pack_tmp_name, mode))\n-\t\t\t\tdie(\"unable to make temporary pack file readable: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to make temporary pack file readable\");\n \t\t\tif (rename(pack_tmp_name, tmpname))\n-\t\t\t\tdie(\"unable to rename temporary pack file: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to rename temporary pack file\");\n \n \t\t\t/*\n \t\t\t * Packs are runtime accessed in their mtime\n@@ -566,11 +564,9 @@ static void write_pack_file(void)\n \t\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.idx\",\n \t\t\t\t base_name, sha1_to_hex(sha1));\n \t\t\tif (adjust_perm(idx_tmp_name, mode))\n-\t\t\t\tdie(\"unable to make temporary index file readable: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to make temporary index file readable\");\n \t\t\tif (rename(idx_tmp_name, tmpname))\n-\t\t\t\tdie(\"unable to rename temporary index file: %s\",\n-\t\t\t\t    strerror(errno));\n+\t\t\t\tdie_errno(\"unable to rename temporary index file\");\n \n \t\t\tfree(idx_tmp_name);\n \t\t\tfree(pack_tmp_name);\n@@ -1879,7 +1875,7 @@ static void read_object_list_from_stdin(void)\n \t\t\tif (!ferror(stdin))\n \t\t\t\tdie(\"fgets returned NULL, not EOF, not error!\");\n \t\t\tif (errno != EINTR)\n-\t\t\t\tdie(\"fgets: %s\", strerror(errno));\n+\t\t\t\tdie_errno(\"fgets\");\n \t\t\tclearerr(stdin);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex 0cc4912..57975db 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!removed)\n-\t\t\t\tdie(\"git rm: %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"git rm: '%s'\", path);\n \t\t}\n \t}\n \ndiff --git a/builtin-send-pack.c b/builtin-send-pack.c\nindex c375a3d..47fb9f7 100644\n--- a/builtin-send-pack.c\n+++ b/builtin-send-pack.c\n@@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext\n \tpo.out = fd;\n \tpo.git_cmd = 1;\n \tif (start_command(&po))\n-\t\tdie(\"git pack-objects failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"git pack-objects failed\");\n \n \t/*\n \t * We feed the pack-objects we just spawned with revision\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex 080e04a..4f6e414 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \t\tpath = git_pathdup(\"TAG_EDITMSG\");\n \t\tfd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n \t\tif (fd < 0)\n-\t\t\tdie(\"could not create file '%s': %s\",\n-\t\t\t\t\t\tpath, strerror(errno));\n+\t\t\tdie_errno(\"could not create file '%s'\", path);\n \n \t\tif (!is_null_sha1(prev))\n \t\t\twrite_tag_body(fd, prev);\n@@ -446,8 +445,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tdie(\"cannot read %s\", msgfile);\n \t\t\t} else {\n \t\t\t\tif (strbuf_read_file(&buf, msgfile, 1024) < 0)\n-\t\t\t\t\tdie(\"could not open or read '%s': %s\",\n-\t\t\t\t\t\tmsgfile, strerror(errno));\n+\t\t\t\t\tdie_errno(\"could not open or read '%s'\",\n+\t\t\t\t\t\tmsgfile);\n \t\t\t}\n \t\t}\n \t}\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 7e3ea73..557148a 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -68,7 +68,7 @@ static void add_object_buffer(struct object *object, char *buffer, unsigned long\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\n \t\t\t\tdie(\"early EOF\");\n-\t\t\tdie(\"read error on input: %s\", strerror(errno));\n+\t\t\tdie_errno(\"read error on input\");\n \t\t}\n \t\tlen += ret;\n \t} while (len < min);\ndiff --git a/csum-file.c b/csum-file.c\nindex 2ddb12a..4d50cc5 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -26,7 +26,7 @@ static void flush(struct sha1file *f, void * buf, unsigned int count)\n \t\t}\n \t\tif (!ret)\n \t\t\tdie(\"sha1 file '%s' write error. Out of diskspace\", f->name);\n-\t\tdie(\"sha1 file '%s' write error (%s)\", f->name, strerror(errno));\n+\t\tdie_errno(\"sha1 file '%s' write error\", f->name);\n \t}\n }\n \n@@ -55,8 +55,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)\n \t\tif (flags & CSUM_FSYNC)\n \t\t\tfsync_or_die(f->fd, f->name);\n \t\tif (close(f->fd))\n-\t\t\tdie(\"%s: sha1 file error on close (%s)\",\n-\t\t\t    f->name, strerror(errno));\n+\t\t\tdie_errno(\"%s: sha1 file error on close\", f->name);\n \t\tfd = 0;\n \t} else\n \t\tfd = f->fd;\ndiff --git a/daemon.c b/daemon.c\nindex 366db37..fdbcf4f 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -862,7 +862,7 @@ static int service_loop(int socknum, int *socklist)\n \t\t\t\t\tcase ECONNABORTED:\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\tdefault:\n-\t\t\t\t\t\tdie(\"accept returned %s\", strerror(errno));\n+\t\t\t\t\t\tdie_errno(\"accept returned\");\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\thandle(incoming, (struct sockaddr *)&ss, sslen);\n@@ -878,7 +878,7 @@ static void sanitize_stdfds(void)\n \twhile (fd != -1 && fd < 2)\n \t\tfd = dup(fd);\n \tif (fd == -1)\n-\t\tdie(\"open /dev/null or dup failed: %s\", strerror(errno));\n+\t\tdie_errno(\"open /dev/null or dup failed\");\n \tif (fd > 2)\n \t\tclose(fd);\n }\n@@ -889,12 +889,12 @@ static void daemonize(void)\n \t\tcase 0:\n \t\t\tbreak;\n \t\tcase -1:\n-\t\t\tdie(\"fork failed: %s\", strerror(errno));\n+\t\t\tdie_errno(\"fork failed\");\n \t\tdefault:\n \t\t\texit(0);\n \t}\n \tif (setsid() == -1)\n-\t\tdie(\"setsid failed: %s\", strerror(errno));\n+\t\tdie_errno(\"setsid failed\");\n \tclose(0);\n \tclose(1);\n \tclose(2);\n@@ -905,9 +905,9 @@ static void store_pid(const char *path)\n {\n \tFILE *f = fopen(path, \"w\");\n \tif (!f)\n-\t\tdie(\"cannot open pid file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"cannot open pid file '%s'\", path);\n \tif (fprintf(f, \"%\"PRIuMAX\"\\n\", (uintmax_t) getpid()) < 0 || fclose(f) != 0)\n-\t\tdie(\"failed to write pid file %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"failed to write pid file '%s'\", path);\n }\n \n static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)\n@@ -1107,8 +1107,7 @@ int main(int argc, char **argv)\n \t\tsocklen_t slen = sizeof(ss);\n \n \t\tif (!freopen(\"/dev/null\", \"w\", stderr))\n-\t\t\tdie(\"failed to redirect stderr to /dev/null: %s\",\n-\t\t\t    strerror(errno));\n+\t\t\tdie_errno(\"failed to redirect stderr to /dev/null\");\n \n \t\tif (getpeername(0, peer, &slen))\n \t\t\tpeer = NULL;\ndiff --git a/diff.c b/diff.c\nindex 43835d7..79aea7f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1975,7 +1975,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \tfd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,\n \t\t\tstrlen(base) + 1);\n \tif (fd < 0)\n-\t\tdie(\"unable to create temp-file: %s\", strerror(errno));\n+\t\tdie_errno(\"unable to create temp-file\");\n \tif (convert_to_working_tree(path,\n \t\t\t(const char *)blob, (size_t)size, &buf)) {\n \t\tblob = buf.buf;\n@@ -2021,7 +2021,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tif (lstat(name, &st) < 0) {\n \t\t\tif (errno == ENOENT)\n \t\t\t\tgoto not_a_valid_file;\n-\t\t\tdie(\"stat(%s): %s\", name, strerror(errno));\n+\t\t\tdie_errno(\"stat(%s)\", name);\n \t\t}\n \t\tif (S_ISLNK(st.st_mode)) {\n \t\t\tstruct strbuf sb = STRBUF_INIT;\ndiff --git a/dir.c b/dir.c\nindex bbfcb56..74b3bbf 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -759,7 +759,7 @@ int file_exists(const char *f)\n \tif (!dir)\n \t\treturn NULL;\n \tif (!getcwd(buffer, size))\n-\t\tdie(\"can't find the current directory: %s\", strerror(errno));\n+\t\tdie_errno(\"can't find the current directory\");\n \n \tif (!is_absolute_path(dir))\n \t\tdir = make_absolute_path(dir);\ndiff --git a/entry.c b/entry.c\nindex cc841ed..8ec880b 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -51,7 +51,7 @@ static void remove_subtree(const char *path)\n \tchar *name;\n \n \tif (!dir)\n-\t\tdie(\"cannot opendir %s (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"cannot opendir '%s'\", path);\n \tstrcpy(pathbuf, path);\n \tname = pathbuf + strlen(path);\n \t*name++ = '/';\n@@ -61,15 +61,15 @@ static void remove_subtree(const char *path)\n \t\t\tcontinue;\n \t\tstrcpy(name, de->d_name);\n \t\tif (lstat(pathbuf, &st))\n-\t\t\tdie(\"cannot lstat %s (%s)\", pathbuf, strerror(errno));\n+\t\t\tdie_errno(\"cannot lstat '%s'\", pathbuf);\n \t\tif (S_ISDIR(st.st_mode))\n \t\t\tremove_subtree(pathbuf);\n \t\telse if (unlink(pathbuf))\n-\t\t\tdie(\"cannot unlink %s (%s)\", pathbuf, strerror(errno));\n+\t\t\tdie_errno(\"cannot unlink '%s'\", pathbuf);\n \t}\n \tclosedir(dir);\n \tif (rmdir(path))\n-\t\tdie(\"cannot rmdir %s (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"cannot rmdir '%s'\", path);\n }\n \n static int create_file(const char *path, unsigned int mode)\ndiff --git a/fast-import.c b/fast-import.c\nindex a2a2458..d31a4e8 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2342,7 +2342,7 @@ static void import_marks(const char *input_file)\n \tchar line[512];\n \tFILE *f = fopen(input_file, \"r\");\n \tif (!f)\n-\t\tdie(\"cannot read %s: %s\", input_file, strerror(errno));\n+\t\tdie_errno(\"cannot read '%s'\", input_file);\n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuintmax_t mark;\n \t\tchar *end;\n@@ -2448,7 +2448,7 @@ int main(int argc, const char **argv)\n \t\t\t\tfclose(pack_edges);\n \t\t\tpack_edges = fopen(a + 20, \"a\");\n \t\t\tif (!pack_edges)\n-\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n+\t\t\t\tdie_errno(\"Cannot open '%s'\", a + 20);\n \t\t} else if (!strcmp(a, \"--force\"))\n \t\t\tforce_update = 1;\n \t\telse if (!strcmp(a, \"--quiet\"))\ndiff --git a/git.c b/git.c\nindex 7d7f949..b035676 100644\n--- a/git.c\n+++ b/git.c\n@@ -200,7 +200,7 @@ static int handle_alias(int *argcp, const char ***argv)\n \t}\n \n \tif (subdir && chdir(subdir))\n-\t\tdie(\"Cannot change to %s: %s\", subdir, strerror(errno));\n+\t\tdie_errno(\"Cannot change to '%s'\", subdir);\n \n \terrno = saved_errno;\n \n@@ -257,11 +257,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \t/* Check for ENOSPC and EIO errors.. */\n \tif (fflush(stdout))\n-\t\tdie(\"write failure on standard output: %s\", strerror(errno));\n+\t\tdie_errno(\"write failure on standard output\");\n \tif (ferror(stdout))\n \t\tdie(\"unknown write failure on standard output\");\n \tif (fclose(stdout))\n-\t\tdie(\"close failed on standard output: %s\", strerror(errno));\n+\t\tdie_errno(\"close failed on standard output\");\n \treturn 0;\n }\n \ndiff --git a/index-pack.c b/index-pack.c\nindex c72cbd4..340074f 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -143,7 +143,7 @@ static void flush(void)\n \t\tif (ret <= 0) {\n \t\t\tif (!ret)\n \t\t\t\tdie(\"early EOF\");\n-\t\t\tdie(\"read error on input: %s\", strerror(errno));\n+\t\t\tdie_errno(\"read error on input\");\n \t\t}\n \t\tinput_len += ret;\n \t\tif (from_stdin)\n@@ -178,13 +178,12 @@ static void use(int bytes)\n \t\t} else\n \t\t\toutput_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);\n \t\tif (output_fd < 0)\n-\t\t\tdie(\"unable to create %s: %s\", pack_name, strerror(errno));\n+\t\t\tdie_errno(\"unable to create '%s'\", pack_name);\n \t\tpack_fd = output_fd;\n \t} else {\n \t\tinput_fd = open(pack_name, O_RDONLY);\n \t\tif (input_fd < 0)\n-\t\t\tdie(\"cannot open packfile '%s': %s\",\n-\t\t\t    pack_name, strerror(errno));\n+\t\t\tdie_errno(\"cannot open packfile '%s'\", pack_name);\n \t\toutput_fd = -1;\n \t\tpack_fd = input_fd;\n \t}\n@@ -370,7 +369,7 @@ static void unlink_base_data(struct base_data *c)\n \tdo {\n \t\tssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);\n \t\tif (n < 0)\n-\t\t\tdie(\"cannot pread pack file: %s\", strerror(errno));\n+\t\t\tdie_errno(\"cannot pread pack file\");\n \t\tif (!n)\n \t\t\tdie(\"premature end of pack file, %lu bytes missing\",\n \t\t\t    len - rdy);\n@@ -631,7 +630,7 @@ static void parse_pack_objects(unsigned char *sha1)\n \n \t/* If input_fd is a file, we should have reached its end now. */\n \tif (fstat(input_fd, &st))\n-\t\tdie(\"cannot fstat packfile: %s\", strerror(errno));\n+\t\tdie_errno(\"cannot fstat packfile\");\n \tif (S_ISREG(st.st_mode) &&\n \t\t\tlseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size)\n \t\tdie(\"pack has junk at the end\");\n@@ -788,7 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \t\tfsync_or_die(output_fd, curr_pack_name);\n \t\terr = close(output_fd);\n \t\tif (err)\n-\t\t\tdie(\"error while closing pack file: %s\", strerror(errno));\n+\t\t\tdie_errno(\"error while closing pack file\");\n \t}\n \n \tif (keep_msg) {\n@@ -801,16 +800,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \n \t\tif (keep_fd < 0) {\n \t\t\tif (errno != EEXIST)\n-\t\t\t\tdie(\"cannot write keep file '%s' (%s)\",\n-\t\t\t\t    keep_name, strerror(errno));\n+\t\t\t\tdie_errno(\"cannot write keep file '%s'\",\n+\t\t\t\t\t  keep_name);\n \t\t} else {\n \t\t\tif (keep_msg_len > 0) {\n \t\t\t\twrite_or_die(keep_fd, keep_msg, keep_msg_len);\n \t\t\t\twrite_or_die(keep_fd, \"\\n\", 1);\n \t\t\t}\n \t\t\tif (close(keep_fd) != 0)\n-\t\t\t\tdie(\"cannot close written keep file '%s' (%s)\",\n-\t\t\t\t    keep_name, strerror(errno));\n+\t\t\t\tdie_errno(\"cannot close written keep file '%s'\",\n+\t\t\t\t    keep_name);\n \t\t\treport = \"keep\";\n \t\t}\n \t}\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex c703445..efad149 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -438,7 +438,7 @@ static void flush_buffer(int fd, const char *buf, unsigned long size)\n \t\t\t/* Ignore epipe */\n \t\t\tif (errno == EPIPE)\n \t\t\t\tbreak;\n-\t\t\tdie(\"merge-recursive: %s\", strerror(errno));\n+\t\t\tdie_errno(\"merge-recursive\");\n \t\t} else if (!ret) {\n \t\t\tdie(\"merge-recursive: disk full?\");\n \t\t}\n@@ -554,7 +554,7 @@ static void update_file_flags(struct merge_options *o,\n \t\t\t\tmode = 0666;\n \t\t\tfd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);\n \t\t\tif (fd < 0)\n-\t\t\t\tdie(\"failed to open %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"failed to open '%s'\", path);\n \t\t\tflush_buffer(fd, buf, size);\n \t\t\tclose(fd);\n \t\t} else if (S_ISLNK(mode)) {\n@@ -562,7 +562,7 @@ static void update_file_flags(struct merge_options *o,\n \t\t\tsafe_create_leading_directories_const(path);\n \t\t\tunlink(path);\n \t\t\tif (symlink(lnk, path))\n-\t\t\t\tdie(\"failed to symlink %s: %s\", path, strerror(errno));\n+\t\t\t\tdie_errno(\"failed to symlink '%s'\", path);\n \t\t\tfree(lnk);\n \t\t} else\n \t\t\tdie(\"do not know what to do with %06o %s '%s'\",\ndiff --git a/pack-refs.c b/pack-refs.c\nindex 301fc60..7f43f8a 100644\n--- a/pack-refs.c\n+++ b/pack-refs.c\n@@ -93,8 +93,7 @@ int pack_refs(unsigned int flags)\n \t\t\t\t       LOCK_DIE_ON_ERROR);\n \tcbdata.refs_file = fdopen(fd, \"w\");\n \tif (!cbdata.refs_file)\n-\t\tdie(\"unable to create ref-pack file structure (%s)\",\n-\t\t    strerror(errno));\n+\t\tdie_errno(\"unable to create ref-pack file structure\");\n \n \t/* perhaps other traits later as well */\n \tfprintf(cbdata.refs_file, \"# pack-refs with: peeled \\n\");\n@@ -103,7 +102,7 @@ int pack_refs(unsigned int flags)\n \tif (ferror(cbdata.refs_file))\n \t\tdie(\"failed to write ref-pack file\");\n \tif (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))\n-\t\tdie(\"failed to write ref-pack file (%s)\", strerror(errno));\n+\t\tdie_errno(\"failed to write ref-pack file\");\n \t/*\n \t * Since the lock file was fdopen()'ed and then fclose()'ed above,\n \t * assign -1 to the lock file descriptor so that commit_lock_file()\n@@ -111,7 +110,7 @@ int pack_refs(unsigned int flags)\n \t */\n \tpacked.fd = -1;\n \tif (commit_lock_file(&packed) < 0)\n-\t\tdie(\"unable to overwrite old ref-pack file (%s)\", strerror(errno));\n+\t\tdie_errno(\"unable to overwrite old ref-pack file\");\n \tif (cbdata.flags & PACK_REFS_PRUNE)\n \t\tprune_refs(cbdata.ref_to_prune);\n \treturn 0;\ndiff --git a/pack-write.c b/pack-write.c\nindex 7053538..741efcd 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -51,7 +51,7 @@ static int sha1_compare(const void *_a, const void *_b)\n \t\tfd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);\n \t}\n \tif (fd < 0)\n-\t\tdie(\"unable to create %s: %s\", index_name, strerror(errno));\n+\t\tdie_errno(\"unable to create '%s'\", index_name);\n \tf = sha1fd(fd, index_name);\n \n \t/* if last object's offset is >= 2^31 we should use index V2 */\n@@ -174,11 +174,11 @@ void fixup_pack_header_footer(int pack_fd,\n \tgit_SHA1_Init(&new_sha1_ctx);\n \n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n-\t\tdie(\"Failed seeking to start of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n \tif (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))\n-\t\tdie(\"Unable to reread header of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Unable to reread header of '%s'\", pack_name);\n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n-\t\tdie(\"Failed seeking to start of %s: %s\", pack_name, strerror(errno));\n+\t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n \tgit_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));\n \thdr.hdr_entries = htonl(object_count);\n \tgit_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));\n@@ -195,7 +195,7 @@ void fixup_pack_header_footer(int pack_fd,\n \t\tif (!n)\n \t\t\tbreak;\n \t\tif (n < 0)\n-\t\t\tdie(\"Failed to checksum %s: %s\", pack_name, strerror(errno));\n+\t\t\tdie_errno(\"Failed to checksum '%s'\", pack_name);\n \t\tgit_SHA1_Update(&new_sha1_ctx, buf, n);\n \n \t\taligned_sz -= n;\ndiff --git a/pkt-line.c b/pkt-line.c\nindex f5d0086..b691abe 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -28,7 +28,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)\n \t\t}\n \t\tif (!ret)\n \t\t\tdie(\"write error (disk full?)\");\n-\t\tdie(\"write error (%s)\", strerror(errno));\n+\t\tdie_errno(\"write error\");\n \t}\n \treturn nn;\n }\n@@ -67,7 +67,7 @@ static void safe_read(int fd, void *buffer, unsigned size)\n {\n \tssize_t ret = read_in_full(fd, buffer, size);\n \tif (ret < 0)\n-\t\tdie(\"read error (%s)\", strerror(errno));\n+\t\tdie_errno(\"read error\");\n \telse if (ret < size)\n \t\tdie(\"The remote end hung up unexpectedly\");\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 3f58711..f76b5bb 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -638,7 +638,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)\n {\n \tstruct stat st;\n \tif (lstat(path, &st))\n-\t\tdie(\"%s: unable to stat (%s)\", path, strerror(errno));\n+\t\tdie_errno(\"unable to stat '%s'\", path);\n \treturn add_to_index(istate, path, &st, flags);\n }\n \n@@ -1251,11 +1251,11 @@ int read_index_from(struct index_state *istate, const char *path)\n \tif (fd < 0) {\n \t\tif (errno == ENOENT)\n \t\t\treturn 0;\n-\t\tdie(\"index file open failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"index file open failed\");\n \t}\n \n \tif (fstat(fd, &st))\n-\t\tdie(\"cannot stat the open index (%s)\", strerror(errno));\n+\t\tdie_errno(\"cannot stat the open index\");\n \n \terrno = EINVAL;\n \tmmap_size = xsize_t(st.st_size);\ndiff --git a/refs.c b/refs.c\nindex 24438c6..dffe395 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1418,7 +1418,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *\n \tlogfile = git_path(\"logs/%s\", ref);\n \tlogfd = open(logfile, O_RDONLY, 0);\n \tif (logfd < 0)\n-\t\tdie(\"Unable to read log %s: %s\", logfile, strerror(errno));\n+\t\tdie_errno(\"Unable to read log '%s'\", logfile);\n \tfstat(logfd, &st);\n \tif (!st.st_size)\n \t\tdie(\"Log %s is empty.\", logfile);\ndiff --git a/run-command.c b/run-command.c\nindex eb2efc3..ff3d8e2 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -101,8 +101,8 @@ int start_command(struct child_process *cmd)\n \t\t}\n \n \t\tif (cmd->dir && chdir(cmd->dir))\n-\t\t\tdie(\"exec %s: cd to %s failed (%s)\", cmd->argv[0],\n-\t\t\t    cmd->dir, strerror(errno));\n+\t\t\tdie_errno(\"exec '%s': cd to '%s' failed\", cmd->argv[0],\n+\t\t\t    cmd->dir);\n \t\tif (cmd->env) {\n \t\t\tfor (; *cmd->env; cmd->env++) {\n \t\t\t\tif (strchr(*cmd->env, '='))\ndiff --git a/setup.c b/setup.c\nindex ebd60de..4d27f28 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -81,7 +81,7 @@ void verify_filename(const char *prefix, const char *arg)\n \tif (errno == ENOENT)\n \t\tdie(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n \t\t    \"Use '--' to separate paths from revisions\", arg);\n-\tdie(\"'%s': %s\", arg, strerror(errno));\n+\tdie_errno(\"failed to stat '%s'\", arg);\n }\n \n /*\n@@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg)\n \t\tdie(\"ambiguous argument '%s': both revision and filename\\n\"\n \t\t    \"Use '--' to separate filenames from revisions\", arg);\n \tif (errno != ENOENT && errno != ENOTDIR)\n-\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\tdie_errno(\"failed to stat '%s'\", arg);\n }\n \n const char **get_pathspec(const char *prefix, const char **pathspec)\n@@ -257,7 +257,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\treturn NULL;\n \tfd = open(path, O_RDONLY);\n \tif (fd < 0)\n-\t\tdie(\"Error opening %s: %s\", path, strerror(errno));\n+\t\tdie_errno(\"Error opening '%s'\", path);\n \tbuf = xmalloc(st.st_size + 1);\n \tlen = read_in_full(fd, buf, st.st_size);\n \tclose(fd);\n@@ -389,7 +389,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\t\tdie(\"Not a git repository (or any of the parent directories): %s\", DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\t}\n \t\tif (chdir(\"..\"))\n-\t\t\tdie(\"Cannot change to %s/..: %s\", cwd, strerror(errno));\n+\t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n \t}\n \n \tinside_git_dir = 0;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 8f5fe62..4576ff7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2286,7 +2286,7 @@ static void close_sha1_file(int fd)\n \tif (fsync_object_files)\n \t\tfsync_or_die(fd, \"sha1 file\");\n \tif (close(fd) != 0)\n-\t\tdie(\"error when closing sha1 file (%s)\", strerror(errno));\n+\t\tdie_errno(\"error when closing sha1 file\");\n }\n \n /* Size of directory component, including the ending '/' */\ndiff --git a/shell.c b/shell.c\nindex b968be7..e4864e0 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -60,7 +60,7 @@ int main(int argc, char **argv)\n \twhile (devnull_fd >= 0 && devnull_fd <= 2)\n \t\tdevnull_fd = dup(devnull_fd);\n \tif (devnull_fd == -1)\n-\t\tdie(\"opening /dev/null failed (%s)\", strerror(errno));\n+\t\tdie_errno(\"opening /dev/null failed\");\n \tclose (devnull_fd);\n \n \t/*\ndiff --git a/test-sha1.c b/test-sha1.c\nindex 9b98d07..80daba9 100644\n--- a/test-sha1.c\n+++ b/test-sha1.c\n@@ -32,7 +32,7 @@ int main(int ac, char **av)\n \t\t\tif (sz == 0)\n \t\t\t\tbreak;\n \t\t\tif (sz < 0)\n-\t\t\t\tdie(\"test-sha1: %s\", strerror(errno));\n+\t\t\t\tdie_errno(\"test-sha1\");\n \t\t\tthis_sz += sz;\n \t\t\tcp += sz;\n \t\t\troom -= sz;\ndiff --git a/wrapper.c b/wrapper.c\nindex 7eb3218..c9be140 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -96,7 +96,7 @@\n \t\trelease_pack_memory(length, fd);\n \t\tret = mmap(start, length, prot, flags, fd, offset);\n \t\tif (ret == MAP_FAILED)\n-\t\t\tdie(\"Out of memory? mmap failed: %s\", strerror(errno));\n+\t\t\tdie_errno(\"Out of memory? mmap failed\");\n \t}\n \treturn ret;\n }\n@@ -175,7 +175,7 @@ int xdup(int fd)\n {\n \tint ret = dup(fd);\n \tif (ret < 0)\n-\t\tdie(\"dup failed: %s\", strerror(errno));\n+\t\tdie_errno(\"dup failed\");\n \treturn ret;\n }\n \n@@ -183,7 +183,7 @@ int xdup(int fd)\n {\n \tFILE *stream = fdopen(fd, mode);\n \tif (stream == NULL)\n-\t\tdie(\"Out of memory? fdopen failed: %s\", strerror(errno));\n+\t\tdie_errno(\"Out of memory? fdopen failed\");\n \treturn stream;\n }\n \n@@ -193,7 +193,7 @@ int xmkstemp(char *template)\n \n \tfd = mkstemp(template);\n \tif (fd < 0)\n-\t\tdie(\"Unable to create temporary file: %s\", strerror(errno));\n+\t\tdie_errno(\"Unable to create temporary file\");\n \treturn fd;\n }\n \ndiff --git a/write_or_die.c b/write_or_die.c\nindex 4c29255..d45b536 100644\n--- a/write_or_die.c\n+++ b/write_or_die.c\n@@ -41,14 +41,14 @@ void maybe_flush_or_die(FILE *f, const char *desc)\n \t\t */\n \t\tif (errno == EPIPE || errno == EINVAL)\n \t\t\texit(0);\n-\t\tdie(\"write failure on %s: %s\", desc, strerror(errno));\n+\t\tdie_errno(\"write failure on '%s'\", desc);\n \t}\n }\n \n void fsync_or_die(int fd, const char *msg)\n {\n \tif (fsync(fd) < 0) {\n-\t\tdie(\"%s: fsync error (%s)\", msg, strerror(errno));\n+\t\tdie_errno(\"fsync error on '%s'\", msg);\n \t}\n }\n \n@@ -57,7 +57,7 @@ void write_or_die(int fd, const void *buf, size_t count)\n \tif (write_in_full(fd, buf, count) < 0) {\n \t\tif (errno == EPIPE)\n \t\t\texit(0);\n-\t\tdie(\"write error (%s)\", strerror(errno));\n+\t\tdie_errno(\"write error\");\n \t}\n }\n \n-- \n1.6.3.3.433.gc91b\n"},{"id":"117094","messageId":"872dc06da0f72fc1f73f3d14e303ccc922504863.1246115205.git.trast@student.ethz.ch","threadId":"19751","inReplyTo":"cover.1246115204.git.trast@student.ethz.ch","subject":"[PATCH v4 4/4] Use die_errno() instead of die() when checking syscalls","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-06-27T15:58:47Z","receivedAt":"2009-06-27T15:58:47Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Lots of die() calls did not actually report the kind of error, which\ncan leave the user confused as to the real problem.  Use die_errno()\nwhere we check a system/library call that sets errno on failure, or\none of the following that wrap such calls:\n\n  Function              Passes on error from\n  --------              --------------------\n  odb_pack_keep         open\n  read_ancestry         fopen\n  read_in_full          xread\n  strbuf_read           xread\n  strbuf_read_file      open or strbuf_read_file\n  strbuf_readlink       readlink\n  write_in_full         xwrite\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n abspath.c               |   12 ++++++------\n builtin-add.c           |    2 +-\n builtin-apply.c         |    6 +++---\n builtin-archive.c       |    4 ++--\n builtin-blame.c         |    8 ++++----\n builtin-clone.c         |   10 +++++-----\n builtin-commit.c        |    5 +++--\n builtin-fast-export.c   |    2 +-\n builtin-fmt-merge-msg.c |    2 +-\n builtin-fsck.c          |    2 +-\n builtin-init-db.c       |   21 +++++++++++----------\n builtin-log.c           |    4 ++--\n builtin-mailsplit.c     |    6 +++---\n builtin-merge.c         |   21 ++++++++++++---------\n builtin-rev-parse.c     |    2 +-\n builtin-revert.c        |    2 +-\n builtin-stripspace.c    |    2 +-\n builtin-tag.c           |    2 +-\n builtin-tar-tree.c      |    2 +-\n combine-diff.c          |    2 +-\n diff.c                  |    6 +++---\n entry.c                 |    2 +-\n fast-import.c           |    4 ++--\n hash-object.c           |    2 +-\n ll-merge.c              |    2 +-\n mktag.c                 |    2 +-\n read-cache.c            |    2 +-\n setup.c                 |   10 +++++-----\n transport.c             |    4 ++--\n unpack-file.c           |    2 +-\n 30 files changed, 79 insertions(+), 74 deletions(-)\n\ndiff --git a/abspath.c b/abspath.c\nindex 649f34f..4bee0ba 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -41,13 +41,13 @@ int is_directory(const char *path)\n \n \t\tif (*buf) {\n \t\t\tif (!*cwd && !getcwd(cwd, sizeof(cwd)))\n-\t\t\t\tdie (\"Could not get current working directory\");\n+\t\t\t\tdie_errno (\"Could not get current working directory\");\n \n \t\t\tif (chdir(buf))\n-\t\t\t\tdie (\"Could not switch to '%s'\", buf);\n+\t\t\t\tdie_errno (\"Could not switch to '%s'\", buf);\n \t\t}\n \t\tif (!getcwd(buf, PATH_MAX))\n-\t\t\tdie (\"Could not get current working directory\");\n+\t\t\tdie_errno (\"Could not get current working directory\");\n \n \t\tif (last_elem) {\n \t\t\tint len = strlen(buf);\n@@ -63,7 +63,7 @@ int is_directory(const char *path)\n \t\tif (!lstat(buf, &st) && S_ISLNK(st.st_mode)) {\n \t\t\tlen = readlink(buf, next_buf, PATH_MAX);\n \t\t\tif (len < 0)\n-\t\t\t\tdie (\"Invalid symlink: %s\", buf);\n+\t\t\t\tdie_errno (\"Invalid symlink '%s'\", buf);\n \t\t\tif (PATH_MAX <= len)\n \t\t\t\tdie(\"symbolic link too long: %s\", buf);\n \t\t\tnext_buf[len] = '\\0';\n@@ -75,7 +75,7 @@ int is_directory(const char *path)\n \t}\n \n \tif (*cwd && chdir(cwd))\n-\t\tdie (\"Could not change back to '%s'\", cwd);\n+\t\tdie_errno (\"Could not change back to '%s'\", cwd);\n \n \treturn buf;\n }\n@@ -109,7 +109,7 @@ int is_directory(const char *path)\n \t} else {\n \t\tconst char *cwd = get_pwd_cwd();\n \t\tif (!cwd)\n-\t\t\tdie(\"Cannot determine the current working directory\");\n+\t\t\tdie_errno(\"Cannot determine the current working directory\");\n \t\tif (snprintf(buf, PATH_MAX, \"%s/%s\", cwd, path) >= PATH_MAX)\n \t\t\tdie(\"Too long path: %.*s\", 60, path);\n \t}\ndiff --git a/builtin-add.c b/builtin-add.c\nindex 4e44148..78989da 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -220,7 +220,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \tlaunch_editor(file, NULL, NULL);\n \n \tif (stat(file, &st))\n-\t\tdie(\"Could not stat '%s'\", file);\n+\t\tdie_errno(\"Could not stat '%s'\", file);\n \tif (!st.st_size)\n \t\tdie(\"Empty patch. Aborted.\");\n \ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 2df2cb9..dc0ff5e 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2823,8 +2823,8 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned \n \t} else {\n \t\tif (!cached) {\n \t\t\tif (lstat(path, &st) < 0)\n-\t\t\t\tdie(\"unable to stat newly created file %s\",\n-\t\t\t\t    path);\n+\t\t\t\tdie_errno(\"unable to stat newly created file '%s'\",\n+\t\t\t\t\t  path);\n \t\t\tfill_stat_cache_info(ce, &st);\n \t\t}\n \t\tif (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)\n@@ -2913,7 +2913,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned\n \t\t\t++nr;\n \t\t}\n \t}\n-\tdie(\"unable to write file %s mode %o\", path, mode);\n+\tdie_errno(\"unable to write file '%s' mode %o\", path, mode);\n }\n \n static void create_file(struct patch *patch)\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 3c5a5a7..f9a4bea 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -13,10 +13,10 @@ static void create_output_file(const char *output_file)\n {\n \tint output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);\n \tif (output_fd < 0)\n-\t\tdie(\"could not create archive file: %s \", output_file);\n+\t\tdie_errno(\"could not create archive file '%s'\", output_file);\n \tif (output_fd != 1) {\n \t\tif (dup2(output_fd, 1) < 0)\n-\t\t\tdie(\"could not redirect output\");\n+\t\t\tdie_errno(\"could not redirect output\");\n \t\telse\n \t\t\tclose(output_fd);\n \t}\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 7d8fbd5..fd6ca51 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2008,23 +2008,23 @@ static int git_blame_config(const char *var, const char *value, void *cb)\n \n \t\tif (contents_from) {\n \t\t\tif (stat(contents_from, &st) < 0)\n-\t\t\t\tdie(\"Cannot stat %s\", contents_from);\n+\t\t\t\tdie_errno(\"Cannot stat '%s'\", contents_from);\n \t\t\tread_from = contents_from;\n \t\t}\n \t\telse {\n \t\t\tif (lstat(path, &st) < 0)\n-\t\t\t\tdie(\"Cannot lstat %s\", path);\n+\t\t\t\tdie_errno(\"Cannot lstat '%s'\", path);\n \t\t\tread_from = path;\n \t\t}\n \t\tmode = canon_mode(st.st_mode);\n \t\tswitch (st.st_mode & S_IFMT) {\n \t\tcase S_IFREG:\n \t\t\tif (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)\n-\t\t\t\tdie(\"cannot open or read %s\", read_from);\n+\t\t\t\tdie_errno(\"cannot open or read '%s'\", read_from);\n \t\t\tbreak;\n \t\tcase S_IFLNK:\n \t\t\tif (strbuf_readlink(&buf, read_from, st.st_size) < 0)\n-\t\t\t\tdie(\"cannot readlink %s\", read_from);\n+\t\t\t\tdie_errno(\"cannot readlink '%s'\", read_from);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tdie(\"unsupported file type %s\", read_from);\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex ccb0480..32dea74 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -220,13 +220,13 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \n \tdir = opendir(src->buf);\n \tif (!dir)\n-\t\tdie(\"failed to open %s\", src->buf);\n+\t\tdie_errno(\"failed to open '%s'\", src->buf);\n \n \tif (mkdir(dest->buf, 0777)) {\n \t\tif (errno != EEXIST)\n-\t\t\tdie(\"failed to create directory %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to create directory '%s'\", dest->buf);\n \t\telse if (stat(dest->buf, &buf))\n-\t\t\tdie(\"failed to stat %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to stat '%s'\", dest->buf);\n \t\telse if (!S_ISDIR(buf.st_mode))\n \t\t\tdie(\"%s exists and is not a directory\", dest->buf);\n \t}\n@@ -257,11 +257,11 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)\n \t\t\tif (!link(src->buf, dest->buf))\n \t\t\t\tcontinue;\n \t\t\tif (option_local)\n-\t\t\t\tdie(\"failed to create link %s\", dest->buf);\n+\t\t\t\tdie_errno(\"failed to create link '%s'\", dest->buf);\n \t\t\toption_no_hardlinks = 1;\n \t\t}\n \t\tif (copy_file(dest->buf, src->buf, 0666))\n-\t\t\tdie(\"failed to copy file to %s\", dest->buf);\n+\t\t\tdie_errno(\"failed to copy file to '%s'\", dest->buf);\n \t}\n \tclosedir(dir);\n }\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 88c51bd..4bcce06 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -434,7 +434,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)\n \t\tif (isatty(0))\n \t\t\tfprintf(stderr, \"(reading log message from standard input)\\n\");\n \t\tif (strbuf_read(&sb, 0, 0) < 0)\n-\t\t\tdie(\"could not read log from standard input\");\n+\t\t\tdie_errno(\"could not read log from standard input\");\n \t\thook_arg1 = \"message\";\n \t} else if (logfile) {\n \t\tif (strbuf_read_file(&sb, logfile, 0) < 0)\n@@ -964,8 +964,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t/* Finally, get the commit message */\n \tstrbuf_reset(&sb);\n \tif (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n+\t\tint saved_errno = errno;\n \t\trollback_index_files();\n-\t\tdie(\"could not read commit message\");\n+\t\tdie(\"could not read commit message: %s\", strerror(saved_errno));\n \t}\n \n \t/* Truncate the message just before the diff, if any. */\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 333d438..9a8a6fc 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -119,7 +119,7 @@ static void handle_object(const unsigned char *sha1)\n \n \tprintf(\"blob\\nmark :%\"PRIu32\"\\ndata %lu\\n\", last_idnum, size);\n \tif (size && fwrite(buf, size, 1, stdout) != 1)\n-\t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n+\t\tdie_errno (\"Could not write blob '%s'\", sha1_to_hex(sha1));\n \tprintf(\"\\n\");\n \n \tshow_progress();\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 1248d5e..9d52400 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -368,7 +368,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tif (inpath && strcmp(inpath, \"-\")) {\n \t\tin = fopen(inpath, \"r\");\n \t\tif (!in)\n-\t\t\tdie(\"cannot open %s\", inpath);\n+\t\t\tdie_errno(\"cannot open '%s'\", inpath);\n \t}\n \n \tif (strbuf_read(&input, fileno(in), 0) < 0)\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 32a1e41..b3d38fa 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -217,7 +217,7 @@ static void check_unreachable_object(struct object *obj)\n \t\t\t\treturn;\n \t\t\t}\n \t\t\tif (!(f = fopen(filename, \"w\")))\n-\t\t\t\tdie(\"Could not open %s\", filename);\n+\t\t\t\tdie_errno(\"Could not open '%s'\", filename);\n \t\t\tif (obj->type == OBJ_BLOB) {\n \t\t\t\tenum object_type type;\n \t\t\t\tunsigned long size;\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex d1fa12a..4a56006 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -61,20 +61,20 @@ static void copy_templates_1(char *path, int baselen,\n \t\tmemcpy(template + template_baselen, de->d_name, namelen+1);\n \t\tif (lstat(path, &st_git)) {\n \t\t\tif (errno != ENOENT)\n-\t\t\t\tdie(\"cannot stat %s\", path);\n+\t\t\t\tdie_errno(\"cannot stat '%s'\", path);\n \t\t}\n \t\telse\n \t\t\texists = 1;\n \n \t\tif (lstat(template, &st_template))\n-\t\t\tdie(\"cannot stat template %s\", template);\n+\t\t\tdie_errno(\"cannot stat template '%s'\", template);\n \n \t\tif (S_ISDIR(st_template.st_mode)) {\n \t\t\tDIR *subdir = opendir(template);\n \t\t\tint baselen_sub = baselen + namelen;\n \t\t\tint template_baselen_sub = template_baselen + namelen;\n \t\t\tif (!subdir)\n-\t\t\t\tdie(\"cannot opendir %s\", template);\n+\t\t\t\tdie_errno(\"cannot opendir '%s'\", template);\n \t\t\tpath[baselen_sub++] =\n \t\t\t\ttemplate[template_baselen_sub++] = '/';\n \t\t\tpath[baselen_sub] =\n@@ -91,16 +91,17 @@ static void copy_templates_1(char *path, int baselen,\n \t\t\tint len;\n \t\t\tlen = readlink(template, lnk, sizeof(lnk));\n \t\t\tif (len < 0)\n-\t\t\t\tdie(\"cannot readlink %s\", template);\n+\t\t\t\tdie_errno(\"cannot readlink '%s'\", template);\n \t\t\tif (sizeof(lnk) <= len)\n \t\t\t\tdie(\"insanely long symlink %s\", template);\n \t\t\tlnk[len] = 0;\n \t\t\tif (symlink(lnk, path))\n-\t\t\t\tdie(\"cannot symlink %s %s\", lnk, path);\n+\t\t\t\tdie_errno(\"cannot symlink '%s' '%s'\", lnk, path);\n \t\t}\n \t\telse if (S_ISREG(st_template.st_mode)) {\n \t\t\tif (copy_file(path, template, st_template.st_mode))\n-\t\t\t\tdie(\"cannot copy %s to %s\", template, path);\n+\t\t\t\tdie_errno(\"cannot copy '%s' to '%s'\", template,\n+\t\t\t\t\t  path);\n \t\t}\n \t\telse\n \t\t\terror(\"ignoring template %s\", template);\n@@ -350,7 +351,7 @@ static int guess_repository_type(const char *git_dir)\n \tif (!strcmp(\".\", git_dir))\n \t\treturn 1;\n \tif (!getcwd(cwd, sizeof(cwd)))\n-\t\tdie(\"cannot tell cwd\");\n+\t\tdie_errno(\"cannot tell cwd\");\n \tif (!strcmp(git_dir, cwd))\n \t\treturn 1;\n \t/*\n@@ -440,11 +441,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tif (!git_work_tree_cfg) {\n \t\t\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n \t\t\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n-\t\t\t\tdie (\"Cannot access current working directory.\");\n+\t\t\t\tdie_errno (\"Cannot access current working directory\");\n \t\t}\n \t\tif (access(get_git_work_tree(), X_OK))\n-\t\t\tdie (\"Cannot access work tree '%s'\",\n-\t\t\t     get_git_work_tree());\n+\t\t\tdie_errno (\"Cannot access work tree '%s'\",\n+\t\t\t\t   get_git_work_tree());\n \t}\n \n \tset_git_dir(make_absolute_path(git_dir));\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 44f9a27..0c2fa0a 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -1013,8 +1013,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tif (use_stdout)\n \t\t\tdie(\"standard output, or directory, which one?\");\n \t\tif (mkdir(output_directory, 0777) < 0 && errno != EEXIST)\n-\t\t\tdie(\"Could not create directory %s\",\n-\t\t\t    output_directory);\n+\t\t\tdie_errno(\"Could not create directory '%s'\",\n+\t\t\t\t  output_directory);\n \t}\n \n \tif (rev.pending.nr == 1) {\ndiff --git a/builtin-mailsplit.c b/builtin-mailsplit.c\nindex 71f3b3b..ad5f6b5 100644\n--- a/builtin-mailsplit.c\n+++ b/builtin-mailsplit.c\n@@ -81,7 +81,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \n \tfd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);\n \tif (fd < 0)\n-\t\tdie(\"cannot open output file %s\", name);\n+\t\tdie_errno(\"cannot open output file '%s'\", name);\n \toutput = fdopen(fd, \"w\");\n \n \t/* Copy it out, while searching for a line that begins with\n@@ -91,7 +91,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \t\tint is_partial = len && buf[len-1] != '\\n';\n \n \t\tif (fwrite(buf, 1, len, output) != len)\n-\t\t\tdie(\"cannot write output\");\n+\t\t\tdie_errno(\"cannot write output\");\n \n \t\tlen = read_line_with_nul(buf, sizeof(buf), mbox);\n \t\tif (len == 0) {\n@@ -99,7 +99,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \t\t\t\tstatus = 1;\n \t\t\t\tbreak;\n \t\t\t}\n-\t\t\tdie(\"cannot read mbox\");\n+\t\t\tdie_errno(\"cannot read mbox\");\n \t\t}\n \t\tif (!is_partial && !is_bare && is_from_line(buf, len))\n \t\t\tbreak; /* done with one message */\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 5ad2188..82b5466 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -268,7 +268,7 @@ static void squash_message(void)\n \tprintf(\"Squash commit -- not updating HEAD\\n\");\n \tfd = open(git_path(\"SQUASH_MSG\"), O_WRONLY | O_CREAT, 0666);\n \tif (fd < 0)\n-\t\tdie(\"Could not write to %s\", git_path(\"SQUASH_MSG\"));\n+\t\tdie_errno(\"Could not write to '%s'\", git_path(\"SQUASH_MSG\"));\n \n \tinit_revisions(&rev, NULL);\n \trev.ignore_merges = 1;\n@@ -764,7 +764,8 @@ static int suggest_conflicts(void)\n \n \tfp = fopen(git_path(\"MERGE_MSG\"), \"a\");\n \tif (!fp)\n-\t\tdie(\"Could not open %s for writing\", git_path(\"MERGE_MSG\"));\n+\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t  git_path(\"MERGE_MSG\"));\n \tfprintf(fp, \"\\nConflicts:\\n\");\n \tfor (pos = 0; pos < active_nr; pos++) {\n \t\tstruct cache_entry *ce = active_cache[pos];\n@@ -1189,27 +1190,29 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t\tsha1_to_hex(j->item->object.sha1));\n \t\tfd = open(git_path(\"MERGE_HEAD\"), O_WRONLY | O_CREAT, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\",\n-\t\t\t\tgit_path(\"MERGE_HEAD\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_HEAD\"));\n \t\tif (write_in_full(fd, buf.buf, buf.len) != buf.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_HEAD\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_HEAD\"));\n \t\tclose(fd);\n \t\tstrbuf_addch(&merge_msg, '\\n');\n \t\tfd = open(git_path(\"MERGE_MSG\"), O_WRONLY | O_CREAT, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\", git_path(\"MERGE_MSG\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_MSG\"));\n \t\tif (write_in_full(fd, merge_msg.buf, merge_msg.len) !=\n \t\t\tmerge_msg.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_MSG\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_MSG\"));\n \t\tclose(fd);\n \t\tfd = open(git_path(\"MERGE_MODE\"), O_WRONLY | O_CREAT | O_TRUNC, 0666);\n \t\tif (fd < 0)\n-\t\t\tdie(\"Could open %s for writing\", git_path(\"MERGE_MODE\"));\n+\t\t\tdie_errno(\"Could not open '%s' for writing\",\n+\t\t\t\t  git_path(\"MERGE_MODE\"));\n \t\tstrbuf_reset(&buf);\n \t\tif (!allow_fast_forward)\n \t\t\tstrbuf_addf(&buf, \"no-ff\");\n \t\tif (write_in_full(fd, buf.buf, buf.len) != buf.len)\n-\t\t\tdie(\"Could not write to %s\", git_path(\"MERGE_MODE\"));\n+\t\t\tdie_errno(\"Could not write to '%s'\", git_path(\"MERGE_MODE\"));\n \t\tclose(fd);\n \t}\n \ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 112d622..da26dbc 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -592,7 +592,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n \t\t\t\tif (!getcwd(cwd, PATH_MAX))\n-\t\t\t\t\tdie(\"unable to get current working directory\");\n+\t\t\t\t\tdie_errno(\"unable to get current working directory\");\n \t\t\t\tprintf(\"%s/.git\\n\", cwd);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin-revert.c b/builtin-revert.c\nindex c87115a..151aa6a 100644\n--- a/builtin-revert.c\n+++ b/builtin-revert.c\n@@ -135,7 +135,7 @@ static void add_to_msg(const char *string)\n {\n \tint len = strlen(string);\n \tif (write_in_full(msg_fd, string, len) < 0)\n-\t\tdie (\"Could not write to MERGE_MSG\");\n+\t\tdie_errno (\"Could not write to MERGE_MSG\");\n }\n \n static void add_message_to_msg(const char *message)\ndiff --git a/builtin-stripspace.c b/builtin-stripspace.c\nindex d6e3896..1fd2205 100644\n--- a/builtin-stripspace.c\n+++ b/builtin-stripspace.c\n@@ -78,7 +78,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)\n \t\tstrip_comments = 1;\n \n \tif (strbuf_read(&buf, 0, 1024) < 0)\n-\t\tdie(\"could not read the input\");\n+\t\tdie_errno(\"could not read the input\");\n \n \tstripspace(&buf, strip_comments);\n \ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex 4f6e414..a51a6d1 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -442,7 +442,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\telse {\n \t\t\tif (!strcmp(msgfile, \"-\")) {\n \t\t\t\tif (strbuf_read(&buf, 0, 1024) < 0)\n-\t\t\t\t\tdie(\"cannot read %s\", msgfile);\n+\t\t\t\t\tdie_errno(\"cannot read '%s'\", msgfile);\n \t\t\t} else {\n \t\t\t\tif (strbuf_read_file(&buf, msgfile, 1024) < 0)\n \t\t\t\t\tdie_errno(\"could not open or read '%s'\",\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f88e721..8b3a35e 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -91,7 +91,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)\n \n \tn = write_in_full(1, content + 11, 41);\n \tif (n < 41)\n-\t\tdie(\"git get-tar-commit-id: write error\");\n+\t\tdie_errno(\"git get-tar-commit-id: write error\");\n \n \treturn 0;\n }\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 60d0367..bbf74fc 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -746,7 +746,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \t\t\tdone = read_in_full(fd, result, len);\n \t\t\tif (done < 0)\n-\t\t\t\tdie(\"read error '%s'\", elem->path);\n+\t\t\t\tdie_errno(\"read error '%s'\", elem->path);\n \t\t\telse if (done < len)\n \t\t\t\tdie(\"early EOF '%s'\", elem->path);\n \ndiff --git a/diff.c b/diff.c\nindex 79aea7f..0a020ff 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1982,7 +1982,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tsize = buf.len;\n \t}\n \tif (write_in_full(fd, blob, size) != size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n \ttemp->name = temp->tmp_path;\n \tstrcpy(temp->hex, sha1_to_hex(sha1));\n@@ -2026,7 +2026,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,\n \t\tif (S_ISLNK(st.st_mode)) {\n \t\t\tstruct strbuf sb = STRBUF_INIT;\n \t\t\tif (strbuf_readlink(&sb, name, st.st_size) < 0)\n-\t\t\t\tdie(\"readlink(%s)\", name);\n+\t\t\t\tdie_errno(\"readlink(%s)\", name);\n \t\t\tprep_temp_blob(name, temp, sb.buf, sb.len,\n \t\t\t\t       (one->sha1_valid ?\n \t\t\t\t\tone->sha1 : null_sha1),\n@@ -2219,7 +2219,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)\n \t\t\t\treturn;\n \t\t\t}\n \t\t\tif (lstat(one->path, &st) < 0)\n-\t\t\t\tdie(\"stat %s\", one->path);\n+\t\t\t\tdie_errno(\"stat '%s'\", one->path);\n \t\t\tif (index_path(one->sha1, one->path, &st, 0))\n \t\t\t\tdie(\"cannot hash %s\", one->path);\n \t\t}\ndiff --git a/entry.c b/entry.c\nindex 8ec880b..d3e86c7 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -37,7 +37,7 @@ static void create_directories(const char *path, int path_len,\n \t\t\tif (errno == EEXIST && state->force &&\n \t\t\t    !unlink_or_warn(buf) && !mkdir(buf, 0777))\n \t\t\t\tcontinue;\n-\t\t\tdie(\"cannot create directory at %s\", buf);\n+\t\t\tdie_errno(\"cannot create directory at '%s'\", buf);\n \t\t}\n \t}\n \tfree(buf);\ndiff --git a/fast-import.c b/fast-import.c\nindex d31a4e8..7ef9865 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -905,10 +905,10 @@ static int oecmp (const void *a_, const void *b_)\n \n \tkeep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);\n \tif (keep_fd < 0)\n-\t\tdie(\"cannot create keep file\");\n+\t\tdie_errno(\"cannot create keep file\");\n \twrite_or_die(keep_fd, keep_msg, strlen(keep_msg));\n \tif (close(keep_fd))\n-\t\tdie(\"failed to write keep file\");\n+\t\tdie_errno(\"failed to write keep file\");\n \n \tsnprintf(name, sizeof(name), \"%s/pack/pack-%s.pack\",\n \t\t get_object_directory(), sha1_to_hex(pack_data->sha1));\ndiff --git a/hash-object.c b/hash-object.c\nindex 47cf43c..9455dd0 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -29,7 +29,7 @@ static void hash_object(const char *path, const char *type, int write_object,\n \tint fd;\n \tfd = open(path, O_RDONLY);\n \tif (fd < 0)\n-\t\tdie(\"Cannot open %s\", path);\n+\t\tdie_errno(\"Cannot open '%s'\", path);\n \thash_fd(fd, type, write_object, vpath);\n }\n \ndiff --git a/ll-merge.c b/ll-merge.c\nindex 9168958..dad795a 100644\n--- a/ll-merge.c\n+++ b/ll-merge.c\n@@ -152,7 +152,7 @@ static void create_temp(mmfile_t *src, char *path)\n \tstrcpy(path, \".merge_file_XXXXXX\");\n \tfd = xmkstemp(path);\n \tif (write_in_full(fd, src->ptr, src->size) != src->size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n }\n \ndiff --git a/mktag.c b/mktag.c\nindex 99a356e..a609e3e 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -165,7 +165,7 @@ int main(int argc, char **argv)\n \tsetup_git_directory();\n \n \tif (strbuf_read(&buf, 0, 4096) < 0) {\n-\t\tdie(\"could not read from stdin\");\n+\t\tdie_errno(\"could not read from stdin\");\n \t}\n \n \t/* Verify it for some basic sanity: it needs to start with\ndiff --git a/read-cache.c b/read-cache.c\nindex f76b5bb..4e3e272 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1265,7 +1265,7 @@ int read_index_from(struct index_state *istate, const char *path)\n \tmmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n \tclose(fd);\n \tif (mmap == MAP_FAILED)\n-\t\tdie(\"unable to map index file\");\n+\t\tdie_errno(\"unable to map index file\");\n \n \thdr = mmap;\n \tif (verify_hdr(hdr, mmap_size) < 0)\ndiff --git a/setup.c b/setup.c\nindex 4d27f28..e3781b6 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -327,7 +327,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\t\t\treturn NULL;\n \t\t\tset_git_dir(make_absolute_path(gitdirenv));\n \t\t\tif (chdir(work_tree_env) < 0)\n-\t\t\t\tdie (\"Could not chdir to %s\", work_tree_env);\n+\t\t\t\tdie_errno (\"Could not chdir to '%s'\", work_tree_env);\n \t\t\tstrcat(buffer, \"/\");\n \t\t\treturn retval;\n \t\t}\n@@ -339,7 +339,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t}\n \n \tif (!getcwd(cwd, sizeof(cwd)-1))\n-\t\tdie(\"Unable to read current working directory\");\n+\t\tdie_errno(\"Unable to read current working directory\");\n \n \tceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);\n \tif (ceil_offset < 0 && has_dos_drive_prefix(cwd))\n@@ -382,7 +382,7 @@ static int check_repository_format_gently(int *nongit_ok)\n \t\tif (offset <= ceil_offset) {\n \t\t\tif (nongit_ok) {\n \t\t\t\tif (chdir(cwd))\n-\t\t\t\t\tdie(\"Cannot come back to cwd\");\n+\t\t\t\t\tdie_errno(\"Cannot come back to cwd\");\n \t\t\t\t*nongit_ok = 1;\n \t\t\t\treturn NULL;\n \t\t\t}\n@@ -493,10 +493,10 @@ int check_repository_format(void)\n \t\tstatic char buffer[PATH_MAX + 1];\n \t\tchar *rel;\n \t\tif (retval && chdir(retval))\n-\t\t\tdie (\"Could not jump back into original cwd\");\n+\t\t\tdie_errno (\"Could not jump back into original cwd\");\n \t\trel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());\n \t\tif (rel && *rel && chdir(get_git_work_tree()))\n-\t\t\tdie (\"Could not jump to working directory\");\n+\t\t\tdie_errno (\"Could not jump to working directory\");\n \t\treturn rel && *rel ? strcat(rel, \"/\") : NULL;\n \t}\n \ndiff --git a/transport.c b/transport.c\nindex 501a77b..ccf788d 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -158,7 +158,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)\n \n \tstrbuf_addstr(&temp_dir, git_path(\"rsync-refs-XXXXXX\"));\n \tif (!mkdtemp(temp_dir.buf))\n-\t\tdie (\"Could not make temporary directory\");\n+\t\tdie_errno (\"Could not make temporary directory\");\n \ttemp_dir_len = temp_dir.len;\n \n \tstrbuf_addstr(&buf, rsync_url(transport->url));\n@@ -321,7 +321,7 @@ static int rsync_transport_push(struct transport *transport,\n \n \tstrbuf_addstr(&temp_dir, git_path(\"rsync-refs-XXXXXX\"));\n \tif (!mkdtemp(temp_dir.buf))\n-\t\tdie (\"Could not make temporary directory\");\n+\t\tdie_errno (\"Could not make temporary directory\");\n \tstrbuf_addch(&temp_dir, '/');\n \n \tif (flags & TRANSPORT_PUSH_ALL) {\ndiff --git a/unpack-file.c b/unpack-file.c\nindex 75cd2f1..ac9cbf7 100644\n--- a/unpack-file.c\n+++ b/unpack-file.c\n@@ -17,7 +17,7 @@\n \tstrcpy(path, \".merge_file_XXXXXX\");\n \tfd = xmkstemp(path);\n \tif (write_in_full(fd, buf, size) != size)\n-\t\tdie(\"unable to write temp-file\");\n+\t\tdie_errno(\"unable to write temp-file\");\n \tclose(fd);\n \treturn path;\n }\n-- \n1.6.3.3.433.gc91b\n"},{"id":"117101","messageId":"7vhby1iksv.fsf@alter.siamese.dyndns.org","threadId":"19751","inReplyTo":"cover.1246115204.git.trast@student.ethz.ch","subject":"Re: [PATCH v4 0/4] die_errno()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-27T18:38:40Z","receivedAt":"2009-06-27T18:38:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> This just picks up Junio's %-doubling patch from pu, with the extra\n> change I suggested in <200906121204.37752.trast@student.ethz.ch> to\n> handle the border case where a lone % would end up at the end of the\n> buffer.  The rest is the same as v3.\n\nThanks.  Will queue.\n"}]}