Use die_errno() instead of die() when checking syscalls

Lots of die() calls did not actually report the kind of error, which
can leave the user confused as to the real problem.  Use die_errno()
where we check a system/library call that sets errno on failure, or
one of the following that wrap such calls:

  Function              Passes on error from
  --------              --------------------
  odb_pack_keep         open
  read_ancestry         fopen
  read_in_full          xread
  strbuf_read           xread
  strbuf_read_file      open or strbuf_read_file
  strbuf_readlink       readlink
  write_in_full         xwrite

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Thomas Rast
2009-06-27 17:58:47 +02:00
committed by Junio C Hamano
parent d824cbba02
commit 0721c314a5
30 changed files with 79 additions and 74 deletions

View File

@ -268,7 +268,7 @@ static void squash_message(void)
printf("Squash commit -- not updating HEAD\n");
fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
if (fd < 0)
die("Could not write to %s", git_path("SQUASH_MSG"));
die_errno("Could not write to '%s'", git_path("SQUASH_MSG"));
init_revisions(&rev, NULL);
rev.ignore_merges = 1;
@ -764,7 +764,8 @@ static int suggest_conflicts(void)
fp = fopen(git_path("MERGE_MSG"), "a");
if (!fp)
die("Could not open %s for writing", git_path("MERGE_MSG"));
die_errno("Could not open '%s' for writing",
git_path("MERGE_MSG"));
fprintf(fp, "\nConflicts:\n");
for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos];
@ -1186,27 +1187,29 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
sha1_to_hex(j->item->object.sha1));
fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666);
if (fd < 0)
die("Could open %s for writing",
git_path("MERGE_HEAD"));
die_errno("Could not open '%s' for writing",
git_path("MERGE_HEAD"));
if (write_in_full(fd, buf.buf, buf.len) != buf.len)
die("Could not write to %s", git_path("MERGE_HEAD"));
die_errno("Could not write to '%s'", git_path("MERGE_HEAD"));
close(fd);
strbuf_addch(&merge_msg, '\n');
fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666);
if (fd < 0)
die("Could open %s for writing", git_path("MERGE_MSG"));
die_errno("Could not open '%s' for writing",
git_path("MERGE_MSG"));
if (write_in_full(fd, merge_msg.buf, merge_msg.len) !=
merge_msg.len)
die("Could not write to %s", git_path("MERGE_MSG"));
die_errno("Could not write to '%s'", git_path("MERGE_MSG"));
close(fd);
fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
die("Could open %s for writing", git_path("MERGE_MODE"));
die_errno("Could not open '%s' for writing",
git_path("MERGE_MODE"));
strbuf_reset(&buf);
if (!allow_fast_forward)
strbuf_addf(&buf, "no-ff");
if (write_in_full(fd, buf.buf, buf.len) != buf.len)
die("Could not write to %s", git_path("MERGE_MODE"));
die_errno("Could not write to '%s'", git_path("MERGE_MODE"));
close(fd);
}