Browse Source

Merge branch 'tr/die_errno'

* tr/die_errno:
  Use die_errno() instead of die() when checking syscalls
  Convert existing die(..., strerror(errno)) to die_errno()
  die_errno(): double % in strerror() output just in case
  Introduce die_errno() that appends strerror(errno) to die()
maint
Junio C Hamano 16 years ago
parent
commit
dd787c19c4
  1. 12
      abspath.c
  2. 5
      bisect.c
  3. 4
      branch.c
  4. 2
      builtin-add.c
  5. 12
      builtin-apply.c
  6. 4
      builtin-archive.c
  7. 15
      builtin-blame.c
  8. 21
      builtin-clone.c
  9. 2
      builtin-commit-tree.c
  10. 28
      builtin-commit.c
  11. 4
      builtin-config.c
  12. 2
      builtin-diff.c
  13. 4
      builtin-fast-export.c
  14. 2
      builtin-fetch--tool.c
  15. 5
      builtin-fmt-merge-msg.c
  16. 10
      builtin-fsck.c
  17. 2
      builtin-grep.c
  18. 21
      builtin-init-db.c
  19. 4
      builtin-log.c
  20. 6
      builtin-mailsplit.c
  21. 29
      builtin-merge.c
  22. 2
      builtin-mv.c
  23. 14
      builtin-pack-objects.c
  24. 2
      builtin-rev-parse.c
  25. 2
      builtin-revert.c
  26. 2
      builtin-rm.c
  27. 2
      builtin-send-pack.c
  28. 2
      builtin-stripspace.c
  29. 9
      builtin-tag.c
  30. 2
      builtin-tar-tree.c
  31. 2
      builtin-unpack-objects.c
  32. 2
      combine-diff.c
  33. 5
      csum-file.c
  34. 15
      daemon.c
  35. 10
      diff.c
  36. 2
      dir.c
  37. 10
      entry.c
  38. 8
      fast-import.c
  39. 1
      git-compat-util.h
  40. 6
      git.c
  41. 2
      hash-object.c
  42. 21
      index-pack.c
  43. 2
      ll-merge.c
  44. 6
      merge-recursive.c
  45. 2
      mktag.c
  46. 7
      pack-refs.c
  47. 10
      pack-write.c
  48. 4
      pkt-line.c
  49. 8
      read-cache.c
  50. 2
      refs.c
  51. 4
      run-command.c
  52. 18
      setup.c
  53. 2
      sha1_file.c
  54. 2
      shell.c
  55. 2
      test-sha1.c
  56. 4
      transport.c
  57. 2
      unpack-file.c
  58. 28
      usage.c
  59. 8
      wrapper.c
  60. 6
      write_or_die.c

12
abspath.c

@ -41,13 +41,13 @@ const char *make_absolute_path(const char *path)


if (*buf) { if (*buf) {
if (!*cwd && !getcwd(cwd, sizeof(cwd))) if (!*cwd && !getcwd(cwd, sizeof(cwd)))
die ("Could not get current working directory"); die_errno ("Could not get current working directory");


if (chdir(buf)) if (chdir(buf))
die ("Could not switch to '%s'", buf); die_errno ("Could not switch to '%s'", buf);
} }
if (!getcwd(buf, PATH_MAX)) if (!getcwd(buf, PATH_MAX))
die ("Could not get current working directory"); die_errno ("Could not get current working directory");


if (last_elem) { if (last_elem) {
int len = strlen(buf); int len = strlen(buf);
@ -63,7 +63,7 @@ const char *make_absolute_path(const char *path)
if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) { if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) {
len = readlink(buf, next_buf, PATH_MAX); len = readlink(buf, next_buf, PATH_MAX);
if (len < 0) if (len < 0)
die ("Invalid symlink: %s", buf); die_errno ("Invalid symlink '%s'", buf);
if (PATH_MAX <= len) if (PATH_MAX <= len)
die("symbolic link too long: %s", buf); die("symbolic link too long: %s", buf);
next_buf[len] = '\0'; next_buf[len] = '\0';
@ -75,7 +75,7 @@ const char *make_absolute_path(const char *path)
} }


if (*cwd && chdir(cwd)) if (*cwd && chdir(cwd))
die ("Could not change back to '%s'", cwd); die_errno ("Could not change back to '%s'", cwd);


return buf; return buf;
} }
@ -109,7 +109,7 @@ const char *make_nonrelative_path(const char *path)
} else { } else {
const char *cwd = get_pwd_cwd(); const char *cwd = get_pwd_cwd();
if (!cwd) if (!cwd)
die("Cannot determine the current working directory"); die_errno("Cannot determine the current working directory");
if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX) if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
die("Too long path: %.*s", 60, path); die("Too long path: %.*s", 60, path);
} }

5
bisect.c

@ -461,7 +461,7 @@ static void read_bisect_paths(struct argv_array *array)
FILE *fp = fopen(filename, "r"); FILE *fp = fopen(filename, "r");


if (!fp) if (!fp)
die("Could not open file '%s': %s", filename, strerror(errno)); die_errno("Could not open file '%s'", filename);


while (strbuf_getline(&str, fp, '\n') != EOF) { while (strbuf_getline(&str, fp, '\n') != EOF) {
char *quoted; char *quoted;
@ -740,8 +740,7 @@ static void mark_expected_rev(char *bisect_rev_hex)
int fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); int fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);


if (fd < 0) if (fd < 0)
die("could not create file '%s': %s", die_errno("could not create file '%s'", filename);
filename, strerror(errno));


bisect_rev_hex[len] = '\n'; bisect_rev_hex[len] = '\n';
write_or_die(fd, bisect_rev_hex, len + 1); write_or_die(fd, bisect_rev_hex, len + 1);

4
branch.c

@ -172,7 +172,7 @@ void create_branch(const char *head,


lock = lock_any_ref_for_update(ref.buf, NULL, 0); lock = lock_any_ref_for_update(ref.buf, NULL, 0);
if (!lock) if (!lock)
die("Failed to lock ref for update: %s.", strerror(errno)); die_errno("Failed to lock ref for update");


if (reflog) if (reflog)
log_all_ref_updates = 1; log_all_ref_updates = 1;
@ -188,7 +188,7 @@ void create_branch(const char *head,
setup_tracking(name, real_ref, track); setup_tracking(name, real_ref, track);


if (write_ref_sha1(lock, sha1, msg) < 0) if (write_ref_sha1(lock, sha1, msg) < 0)
die("Failed to write ref: %s.", strerror(errno)); die_errno("Failed to write ref");


strbuf_release(&ref); strbuf_release(&ref);
free(real_ref); free(real_ref);

2
builtin-add.c

@ -220,7 +220,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
launch_editor(file, NULL, NULL); launch_editor(file, NULL, NULL);


if (stat(file, &st)) if (stat(file, &st))
die("Could not stat '%s'", file); die_errno("Could not stat '%s'", file);
if (!st.st_size) if (!st.st_size)
die("Empty patch. Aborted."); die("Empty patch. Aborted.");



12
builtin-apply.c

@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,
static void read_patch_file(struct strbuf *sb, int fd) static void read_patch_file(struct strbuf *sb, int fd)
{ {
if (strbuf_read(sb, fd, 0) < 0) if (strbuf_read(sb, fd, 0) < 0)
die("git apply: read returned %s", strerror(errno)); die_errno("git apply: failed to read");


/* /*
* Make sure that we have some slop in the buffer * Make sure that we have some slop in the buffer
@ -2823,8 +2823,8 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
} else { } else {
if (!cached) { if (!cached) {
if (lstat(path, &st) < 0) if (lstat(path, &st) < 0)
die("unable to stat newly created file %s", die_errno("unable to stat newly created file '%s'",
path); path);
fill_stat_cache_info(ce, &st); fill_stat_cache_info(ce, &st);
} }
if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0) if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)
@ -2864,7 +2864,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
strbuf_release(&nbuf); strbuf_release(&nbuf);


if (close(fd) < 0) if (close(fd) < 0)
die("closing file %s: %s", path, strerror(errno)); die_errno("closing file '%s'", path);
return 0; return 0;
} }


@ -2913,7 +2913,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned
++nr; ++nr;
} }
} }
die("unable to write file %s mode %o", path, mode); die_errno("unable to write file '%s' mode %o", path, mode);
} }


static void create_file(struct patch *patch) static void create_file(struct patch *patch)
@ -3356,7 +3356,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)


fd = open(arg, O_RDONLY); fd = open(arg, O_RDONLY);
if (fd < 0) if (fd < 0)
die("can't open patch '%s': %s", arg, strerror(errno)); die_errno("can't open patch '%s'", arg);
read_stdin = 0; read_stdin = 0;
set_default_whitespace_mode(whitespace_option); set_default_whitespace_mode(whitespace_option);
errs |= apply_patch(fd, arg, options); errs |= apply_patch(fd, arg, options);

4
builtin-archive.c

@ -13,10 +13,10 @@ static void create_output_file(const char *output_file)
{ {
int output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666); int output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (output_fd < 0) if (output_fd < 0)
die("could not create archive file: %s ", output_file); die_errno("could not create archive file '%s'", output_file);
if (output_fd != 1) { if (output_fd != 1) {
if (dup2(output_fd, 1) < 0) if (dup2(output_fd, 1) < 0)
die("could not redirect output"); die_errno("could not redirect output");
else else
close(output_fd); close(output_fd);
} }

15
builtin-blame.c

@ -2008,23 +2008,23 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con


if (contents_from) { if (contents_from) {
if (stat(contents_from, &st) < 0) if (stat(contents_from, &st) < 0)
die("Cannot stat %s", contents_from); die_errno("Cannot stat '%s'", contents_from);
read_from = contents_from; read_from = contents_from;
} }
else { else {
if (lstat(path, &st) < 0) if (lstat(path, &st) < 0)
die("Cannot lstat %s", path); die_errno("Cannot lstat '%s'", path);
read_from = path; read_from = path;
} }
mode = canon_mode(st.st_mode); mode = canon_mode(st.st_mode);
switch (st.st_mode & S_IFMT) { switch (st.st_mode & S_IFMT) {
case S_IFREG: case S_IFREG:
if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size) if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
die("cannot open or read %s", read_from); die_errno("cannot open or read '%s'", read_from);
break; break;
case S_IFLNK: case S_IFLNK:
if (strbuf_readlink(&buf, read_from, st.st_size) < 0) if (strbuf_readlink(&buf, read_from, st.st_size) < 0)
die("cannot readlink %s", read_from); die_errno("cannot readlink '%s'", read_from);
break; break;
default: default:
die("unsupported file type %s", read_from); die("unsupported file type %s", read_from);
@ -2035,7 +2035,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
contents_from = "standard input"; contents_from = "standard input";
mode = 0; mode = 0;
if (strbuf_read(&buf, 0, 0) < 0) if (strbuf_read(&buf, 0, 0) < 0)
die("read error %s from stdin", strerror(errno)); die_errno("failed to read from stdin");
} }
convert_to_git(path, buf.buf, buf.len, &buf, 0); convert_to_git(path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf; origin->file.ptr = buf.buf;
@ -2261,8 +2261,7 @@ parse_done:
argc = parse_options_end(&ctx); argc = parse_options_end(&ctx);


if (revs_file && read_ancestry(revs_file)) if (revs_file && read_ancestry(revs_file))
die("reading graft file %s failed: %s", die_errno("reading graft file '%s' failed", revs_file);
revs_file, strerror(errno));


if (cmd_is_annotate) { if (cmd_is_annotate) {
output_option |= OUTPUT_ANNOTATE_COMPAT; output_option |= OUTPUT_ANNOTATE_COMPAT;
@ -2350,7 +2349,7 @@ parse_done:


setup_work_tree(); setup_work_tree();
if (!has_string_in_work_tree(path)) if (!has_string_in_work_tree(path))
die("cannot stat path %s: %s", path, strerror(errno)); die_errno("cannot stat path '%s'", path);
} }


setup_revisions(argc, argv, &revs, NULL); setup_revisions(argc, argv, &revs, NULL);

21
builtin-clone.c

@ -220,13 +220,13 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)


dir = opendir(src->buf); dir = opendir(src->buf);
if (!dir) if (!dir)
die("failed to open %s", src->buf); die_errno("failed to open '%s'", src->buf);


if (mkdir(dest->buf, 0777)) { if (mkdir(dest->buf, 0777)) {
if (errno != EEXIST) if (errno != EEXIST)
die("failed to create directory %s", dest->buf); die_errno("failed to create directory '%s'", dest->buf);
else if (stat(dest->buf, &buf)) else if (stat(dest->buf, &buf))
die("failed to stat %s", dest->buf); die_errno("failed to stat '%s'", dest->buf);
else if (!S_ISDIR(buf.st_mode)) else if (!S_ISDIR(buf.st_mode))
die("%s exists and is not a directory", dest->buf); die("%s exists and is not a directory", dest->buf);
} }
@ -252,17 +252,16 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
} }


if (unlink(dest->buf) && errno != ENOENT) if (unlink(dest->buf) && errno != ENOENT)
die("failed to unlink %s: %s", die_errno("failed to unlink '%s'", dest->buf);
dest->buf, strerror(errno));
if (!option_no_hardlinks) { if (!option_no_hardlinks) {
if (!link(src->buf, dest->buf)) if (!link(src->buf, dest->buf))
continue; continue;
if (option_local) if (option_local)
die("failed to create link %s", dest->buf); die_errno("failed to create link '%s'", dest->buf);
option_no_hardlinks = 1; option_no_hardlinks = 1;
} }
if (copy_file(dest->buf, src->buf, 0666)) if (copy_file(dest->buf, src->buf, 0666))
die("failed to copy file to %s", dest->buf); die_errno("failed to copy file to '%s'", dest->buf);
} }
closedir(dir); closedir(dir);
} }
@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (!option_bare) { if (!option_bare) {
junk_work_tree = work_tree; junk_work_tree = work_tree;
if (safe_create_leading_directories_const(work_tree) < 0) if (safe_create_leading_directories_const(work_tree) < 0)
die("could not create leading directories of '%s': %s", die_errno("could not create leading directories of '%s'",
work_tree, strerror(errno)); work_tree);
if (!dest_exists && mkdir(work_tree, 0755)) if (!dest_exists && mkdir(work_tree, 0755))
die("could not create work tree dir '%s': %s.", die_errno("could not create work tree dir '%s'.",
work_tree, strerror(errno)); work_tree);
set_git_work_tree(work_tree); set_git_work_tree(work_tree);
} }
junk_git_dir = git_dir; junk_git_dir = git_dir;

2
builtin-commit-tree.c

@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
} }


if (strbuf_read(&buffer, 0, 0) < 0) if (strbuf_read(&buffer, 0, 0) < 0)
die("git commit-tree: read returned %s", strerror(errno)); die_errno("git commit-tree: failed to read");


if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) { if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
printf("%s\n", sha1_to_hex(commit_sha1)); printf("%s\n", sha1_to_hex(commit_sha1));

28
builtin-commit.c

@ -434,12 +434,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
if (isatty(0)) if (isatty(0))
fprintf(stderr, "(reading log message from standard input)\n"); fprintf(stderr, "(reading log message from standard input)\n");
if (strbuf_read(&sb, 0, 0) < 0) if (strbuf_read(&sb, 0, 0) < 0)
die("could not read log from standard input"); die_errno("could not read log from standard input");
hook_arg1 = "message"; hook_arg1 = "message";
} else if (logfile) { } else if (logfile) {
if (strbuf_read_file(&sb, logfile, 0) < 0) if (strbuf_read_file(&sb, logfile, 0) < 0)
die("could not read log file '%s': %s", die_errno("could not read log file '%s'",
logfile, strerror(errno)); logfile);
hook_arg1 = "message"; hook_arg1 = "message";
} else if (use_message) { } else if (use_message) {
buffer = strstr(use_message_buffer, "\n\n"); buffer = strstr(use_message_buffer, "\n\n");
@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
hook_arg2 = use_message; hook_arg2 = use_message;
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) { } else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
die("could not read MERGE_MSG: %s", strerror(errno)); die_errno("could not read MERGE_MSG");
hook_arg1 = "merge"; hook_arg1 = "merge";
} else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
die("could not read SQUASH_MSG: %s", strerror(errno)); die_errno("could not read SQUASH_MSG");
hook_arg1 = "squash"; hook_arg1 = "squash";
} else if (template_file && !stat(template_file, &statbuf)) { } else if (template_file && !stat(template_file, &statbuf)) {
if (strbuf_read_file(&sb, template_file, 0) < 0) if (strbuf_read_file(&sb, template_file, 0) < 0)
die("could not read %s: %s", die_errno("could not read '%s'", template_file);
template_file, strerror(errno));
hook_arg1 = "template"; hook_arg1 = "template";
} }


@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)


fp = fopen(git_path(commit_editmsg), "w"); fp = fopen(git_path(commit_editmsg), "w");
if (fp == NULL) if (fp == NULL)
die("could not open %s: %s", die_errno("could not open '%s'", git_path(commit_editmsg));
git_path(commit_editmsg), strerror(errno));


if (cleanup_mode != CLEANUP_NONE) if (cleanup_mode != CLEANUP_NONE)
stripspace(&sb, 0); stripspace(&sb, 0);
@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
} }


if (fwrite(sb.buf, 1, sb.len, fp) < sb.len) if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
die("could not write commit template: %s", strerror(errno)); die_errno("could not write commit template");


strbuf_release(&sb); strbuf_release(&sb);


@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next; pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
fp = fopen(git_path("MERGE_HEAD"), "r"); fp = fopen(git_path("MERGE_HEAD"), "r");
if (fp == NULL) if (fp == NULL)
die("could not open %s for reading: %s", die_errno("could not open '%s' for reading",
git_path("MERGE_HEAD"), strerror(errno)); git_path("MERGE_HEAD"));
while (strbuf_getline(&m, fp, '\n') != EOF) { while (strbuf_getline(&m, fp, '\n') != EOF) {
unsigned char sha1[20]; unsigned char sha1[20];
if (get_sha1_hex(m.buf, sha1) < 0) if (get_sha1_hex(m.buf, sha1) < 0)
@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
strbuf_release(&m); strbuf_release(&m);
if (!stat(git_path("MERGE_MODE"), &statbuf)) { if (!stat(git_path("MERGE_MODE"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0) if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
die("could not read MERGE_MODE: %s", die_errno("could not read MERGE_MODE");
strerror(errno));
if (!strcmp(sb.buf, "no-ff")) if (!strcmp(sb.buf, "no-ff"))
allow_fast_forward = 0; allow_fast_forward = 0;
} }
@ -967,8 +964,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
/* Finally, get the commit message */ /* Finally, get the commit message */
strbuf_reset(&sb); strbuf_reset(&sb);
if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
int saved_errno = errno;
rollback_index_files(); rollback_index_files();
die("could not read commit message"); die("could not read commit message: %s", strerror(saved_errno));
} }


/* Truncate the message just before the diff, if any. */ /* Truncate the message just before the diff, if any. */

4
builtin-config.c

@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
check_argc(argc, 0, 0); check_argc(argc, 0, 0);
if (git_config(show_all_config, NULL) < 0) { if (git_config(show_all_config, NULL) < 0) {
if (config_exclusive_filename) if (config_exclusive_filename)
die("unable to read config file %s: %s", die_errno("unable to read config file '%s'",
config_exclusive_filename, strerror(errno)); config_exclusive_filename);
else else
die("error processing config file(s)"); die("error processing config file(s)");
} }

2
builtin-diff.c

@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
usage(builtin_diff_usage); usage(builtin_diff_usage);


if (lstat(path, &st)) if (lstat(path, &st))
die("'%s': %s", path, strerror(errno)); die_errno("failed to stat '%s'", path);
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
die("'%s': not a regular file or symlink", path); die("'%s': not a regular file or symlink", path);



4
builtin-fast-export.c

@ -119,7 +119,7 @@ static void handle_object(const unsigned char *sha1)


printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size); printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
if (size && fwrite(buf, size, 1, stdout) != 1) if (size && fwrite(buf, size, 1, stdout) != 1)
die ("Could not write blob %s", sha1_to_hex(sha1)); die_errno ("Could not write blob '%s'", sha1_to_hex(sha1));
printf("\n"); printf("\n");


show_progress(); show_progress();
@ -451,7 +451,7 @@ static void import_marks(char *input_file)
char line[512]; char line[512];
FILE *f = fopen(input_file, "r"); FILE *f = fopen(input_file, "r");
if (!f) if (!f)
die("cannot read %s: %s", input_file, strerror(errno)); die_errno("cannot read '%s'", input_file);


while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
uint32_t mark; uint32_t mark;

2
builtin-fetch--tool.c

@ -8,7 +8,7 @@ static char *get_stdin(void)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
if (strbuf_read(&buf, 0, 1024) < 0) { if (strbuf_read(&buf, 0, 1024) < 0) {
die("error reading standard input: %s", strerror(errno)); die_errno("error reading standard input");
} }
return strbuf_detach(&buf, NULL); return strbuf_detach(&buf, NULL);
} }

5
builtin-fmt-merge-msg.c

@ -368,12 +368,11 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
if (inpath && strcmp(inpath, "-")) { if (inpath && strcmp(inpath, "-")) {
in = fopen(inpath, "r"); in = fopen(inpath, "r");
if (!in) if (!in)
die("cannot open %s", inpath); die_errno("cannot open '%s'", inpath);
} }


if (strbuf_read(&input, fileno(in), 0) < 0) if (strbuf_read(&input, fileno(in), 0) < 0)
die("could not read input file %s", strerror(errno)); die_errno("could not read input file");

ret = fmt_merge_msg(merge_summary, &input, &output); ret = fmt_merge_msg(merge_summary, &input, &output);
if (ret) if (ret)
return ret; return ret;

10
builtin-fsck.c

@ -217,7 +217,7 @@ static void check_unreachable_object(struct object *obj)
return; return;
} }
if (!(f = fopen(filename, "w"))) if (!(f = fopen(filename, "w")))
die("Could not open %s", filename); die_errno("Could not open '%s'", filename);
if (obj->type == OBJ_BLOB) { if (obj->type == OBJ_BLOB) {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)
&type, &size); &type, &size);
if (buf) { if (buf) {
if (fwrite(buf, size, 1, f) != 1) if (fwrite(buf, size, 1, f) != 1)
die("Could not write %s: %s", die_errno("Could not write '%s'",
filename, strerror(errno)); filename);
free(buf); free(buf);
} }
} else } else
fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
if (fclose(f)) if (fclose(f))
die("Could not finish %s: %s", die_errno("Could not finish '%s'",
filename, strerror(errno)); filename);
} }
return; return;
} }

2
builtin-grep.c

@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)


patterns = fopen(arg, "r"); patterns = fopen(arg, "r");
if (!patterns) if (!patterns)
die("'%s': %s", arg, strerror(errno)); die_errno("cannot open '%s'", arg);
while (strbuf_getline(&sb, patterns, '\n') == 0) { while (strbuf_getline(&sb, patterns, '\n') == 0) {
/* ignore empty line like grep does */ /* ignore empty line like grep does */
if (sb.len == 0) if (sb.len == 0)

21
builtin-init-db.c

@ -61,20 +61,20 @@ static void copy_templates_1(char *path, int baselen,
memcpy(template + template_baselen, de->d_name, namelen+1); memcpy(template + template_baselen, de->d_name, namelen+1);
if (lstat(path, &st_git)) { if (lstat(path, &st_git)) {
if (errno != ENOENT) if (errno != ENOENT)
die("cannot stat %s", path); die_errno("cannot stat '%s'", path);
} }
else else
exists = 1; exists = 1;


if (lstat(template, &st_template)) if (lstat(template, &st_template))
die("cannot stat template %s", template); die_errno("cannot stat template '%s'", template);


if (S_ISDIR(st_template.st_mode)) { if (S_ISDIR(st_template.st_mode)) {
DIR *subdir = opendir(template); DIR *subdir = opendir(template);
int baselen_sub = baselen + namelen; int baselen_sub = baselen + namelen;
int template_baselen_sub = template_baselen + namelen; int template_baselen_sub = template_baselen + namelen;
if (!subdir) if (!subdir)
die("cannot opendir %s", template); die_errno("cannot opendir '%s'", template);
path[baselen_sub++] = path[baselen_sub++] =
template[template_baselen_sub++] = '/'; template[template_baselen_sub++] = '/';
path[baselen_sub] = path[baselen_sub] =
@ -91,16 +91,17 @@ static void copy_templates_1(char *path, int baselen,
int len; int len;
len = readlink(template, lnk, sizeof(lnk)); len = readlink(template, lnk, sizeof(lnk));
if (len < 0) if (len < 0)
die("cannot readlink %s", template); die_errno("cannot readlink '%s'", template);
if (sizeof(lnk) <= len) if (sizeof(lnk) <= len)
die("insanely long symlink %s", template); die("insanely long symlink %s", template);
lnk[len] = 0; lnk[len] = 0;
if (symlink(lnk, path)) if (symlink(lnk, path))
die("cannot symlink %s %s", lnk, path); die_errno("cannot symlink '%s' '%s'", lnk, path);
} }
else if (S_ISREG(st_template.st_mode)) { else if (S_ISREG(st_template.st_mode)) {
if (copy_file(path, template, st_template.st_mode)) if (copy_file(path, template, st_template.st_mode))
die("cannot copy %s to %s", template, path); die_errno("cannot copy '%s' to '%s'", template,
path);
} }
else else
error("ignoring template %s", template); error("ignoring template %s", template);
@ -350,7 +351,7 @@ static int guess_repository_type(const char *git_dir)
if (!strcmp(".", git_dir)) if (!strcmp(".", git_dir))
return 1; return 1;
if (!getcwd(cwd, sizeof(cwd))) if (!getcwd(cwd, sizeof(cwd)))
die("cannot tell cwd"); die_errno("cannot tell cwd");
if (!strcmp(git_dir, cwd)) if (!strcmp(git_dir, cwd))
return 1; return 1;
/* /*
@ -440,11 +441,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (!git_work_tree_cfg) { if (!git_work_tree_cfg) {
git_work_tree_cfg = xcalloc(PATH_MAX, 1); git_work_tree_cfg = xcalloc(PATH_MAX, 1);
if (!getcwd(git_work_tree_cfg, PATH_MAX)) if (!getcwd(git_work_tree_cfg, PATH_MAX))
die ("Cannot access current working directory."); die_errno ("Cannot access current working directory");
} }
if (access(get_git_work_tree(), X_OK)) if (access(get_git_work_tree(), X_OK))
die ("Cannot access work tree '%s'", die_errno ("Cannot access work tree '%s'",
get_git_work_tree()); get_git_work_tree());
} }


set_git_dir(make_absolute_path(git_dir)); set_git_dir(make_absolute_path(git_dir));

4
builtin-log.c

@ -1013,8 +1013,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (use_stdout) if (use_stdout)
die("standard output, or directory, which one?"); die("standard output, or directory, which one?");
if (mkdir(output_directory, 0777) < 0 && errno != EEXIST) if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
die("Could not create directory %s", die_errno("Could not create directory '%s'",
output_directory); output_directory);
} }


if (rev.pending.nr == 1) { if (rev.pending.nr == 1) {

6
builtin-mailsplit.c

@ -81,7 +81,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)


fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666); fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0) if (fd < 0)
die("cannot open output file %s", name); die_errno("cannot open output file '%s'", name);
output = fdopen(fd, "w"); output = fdopen(fd, "w");


/* Copy it out, while searching for a line that begins with /* Copy it out, while searching for a line that begins with
@ -91,7 +91,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
int is_partial = len && buf[len-1] != '\n'; int is_partial = len && buf[len-1] != '\n';


if (fwrite(buf, 1, len, output) != len) if (fwrite(buf, 1, len, output) != len)
die("cannot write output"); die_errno("cannot write output");


len = read_line_with_nul(buf, sizeof(buf), mbox); len = read_line_with_nul(buf, sizeof(buf), mbox);
if (len == 0) { if (len == 0) {
@ -99,7 +99,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
status = 1; status = 1;
break; break;
} }
die("cannot read mbox"); die_errno("cannot read mbox");
} }
if (!is_partial && !is_bare && is_from_line(buf, len)) if (!is_partial && !is_bare && is_from_line(buf, len))
break; /* done with one message */ break; /* done with one message */

29
builtin-merge.c

@ -268,7 +268,7 @@ static void squash_message(void)
printf("Squash commit -- not updating HEAD\n"); printf("Squash commit -- not updating HEAD\n");
fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666); fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
if (fd < 0) 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); init_revisions(&rev, NULL);
rev.ignore_merges = 1; rev.ignore_merges = 1;
@ -294,9 +294,9 @@ static void squash_message(void)
NULL, NULL, rev.date_mode, 0); NULL, NULL, rev.date_mode, 0);
} }
if (write(fd, out.buf, out.len) < 0) if (write(fd, out.buf, out.len) < 0)
die("Writing SQUASH_MSG: %s", strerror(errno)); die_errno("Writing SQUASH_MSG");
if (close(fd)) if (close(fd))
die("Finishing SQUASH_MSG: %s", strerror(errno)); die_errno("Finishing SQUASH_MSG");
strbuf_release(&out); strbuf_release(&out);
} }


@ -428,8 +428,8 @@ static void merge_name(const char *remote, struct strbuf *msg)


fp = fopen(git_path("FETCH_HEAD"), "r"); fp = fopen(git_path("FETCH_HEAD"), "r");
if (!fp) if (!fp)
die("could not open %s for reading: %s", die_errno("could not open '%s' for reading",
git_path("FETCH_HEAD"), strerror(errno)); git_path("FETCH_HEAD"));
strbuf_getline(&line, fp, '\n'); strbuf_getline(&line, fp, '\n');
fclose(fp); fclose(fp);
ptr = strstr(line.buf, "\tnot-for-merge\t"); ptr = strstr(line.buf, "\tnot-for-merge\t");
@ -764,7 +764,8 @@ static int suggest_conflicts(void)


fp = fopen(git_path("MERGE_MSG"), "a"); fp = fopen(git_path("MERGE_MSG"), "a");
if (!fp) 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"); fprintf(fp, "\nConflicts:\n");
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos]; struct cache_entry *ce = active_cache[pos];
@ -1189,27 +1190,29 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
sha1_to_hex(j->item->object.sha1)); sha1_to_hex(j->item->object.sha1));
fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666); fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666);
if (fd < 0) if (fd < 0)
die("Could open %s for writing", die_errno("Could not open '%s' for writing",
git_path("MERGE_HEAD")); git_path("MERGE_HEAD"));
if (write_in_full(fd, buf.buf, buf.len) != buf.len) 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); close(fd);
strbuf_addch(&merge_msg, '\n'); strbuf_addch(&merge_msg, '\n');
fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666); fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666);
if (fd < 0) 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) != if (write_in_full(fd, merge_msg.buf, merge_msg.len) !=
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); close(fd);
fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666); fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) 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); strbuf_reset(&buf);
if (!allow_fast_forward) if (!allow_fast_forward)
strbuf_addf(&buf, "no-ff"); strbuf_addf(&buf, "no-ff");
if (write_in_full(fd, buf.buf, buf.len) != buf.len) 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); close(fd);
} }



2
builtin-mv.c

@ -205,7 +205,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
printf("Renaming %s to %s\n", src, dst); printf("Renaming %s to %s\n", src, dst);
if (!show_only && mode != INDEX && if (!show_only && mode != INDEX &&
rename(src, dst) < 0 && !ignore_errors) rename(src, dst) < 0 && !ignore_errors)
die ("renaming %s failed: %s", src, strerror(errno)); die_errno ("renaming '%s' failed", src);


if (mode == WORKING_DIRECTORY) if (mode == WORKING_DIRECTORY)
continue; continue;

14
builtin-pack-objects.c

@ -536,11 +536,9 @@ static void write_pack_file(void)
base_name, sha1_to_hex(sha1)); base_name, sha1_to_hex(sha1));
free_pack_by_name(tmpname); free_pack_by_name(tmpname);
if (adjust_perm(pack_tmp_name, mode)) if (adjust_perm(pack_tmp_name, mode))
die("unable to make temporary pack file readable: %s", die_errno("unable to make temporary pack file readable");
strerror(errno));
if (rename(pack_tmp_name, tmpname)) if (rename(pack_tmp_name, tmpname))
die("unable to rename temporary pack file: %s", die_errno("unable to rename temporary pack file");
strerror(errno));


/* /*
* Packs are runtime accessed in their mtime * Packs are runtime accessed in their mtime
@ -566,11 +564,9 @@ static void write_pack_file(void)
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx", snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
base_name, sha1_to_hex(sha1)); base_name, sha1_to_hex(sha1));
if (adjust_perm(idx_tmp_name, mode)) if (adjust_perm(idx_tmp_name, mode))
die("unable to make temporary index file readable: %s", die_errno("unable to make temporary index file readable");
strerror(errno));
if (rename(idx_tmp_name, tmpname)) if (rename(idx_tmp_name, tmpname))
die("unable to rename temporary index file: %s", die_errno("unable to rename temporary index file");
strerror(errno));


free(idx_tmp_name); free(idx_tmp_name);
free(pack_tmp_name); free(pack_tmp_name);
@ -1879,7 +1875,7 @@ static void read_object_list_from_stdin(void)
if (!ferror(stdin)) if (!ferror(stdin))
die("fgets returned NULL, not EOF, not error!"); die("fgets returned NULL, not EOF, not error!");
if (errno != EINTR) if (errno != EINTR)
die("fgets: %s", strerror(errno)); die_errno("fgets");
clearerr(stdin); clearerr(stdin);
continue; continue;
} }

2
builtin-rev-parse.c

@ -596,7 +596,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue; continue;
} }
if (!getcwd(cwd, PATH_MAX)) if (!getcwd(cwd, PATH_MAX))
die("unable to get current working directory"); die_errno("unable to get current working directory");
printf("%s/.git\n", cwd); printf("%s/.git\n", cwd);
continue; continue;
} }

2
builtin-revert.c

@ -135,7 +135,7 @@ static void add_to_msg(const char *string)
{ {
int len = strlen(string); int len = strlen(string);
if (write_in_full(msg_fd, string, len) < 0) if (write_in_full(msg_fd, string, len) < 0)
die ("Could not write to MERGE_MSG"); die_errno ("Could not write to MERGE_MSG");
} }


static void add_message_to_msg(const char *message) static void add_message_to_msg(const char *message)

2
builtin-rm.c

@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
continue; continue;
} }
if (!removed) if (!removed)
die("git rm: %s: %s", path, strerror(errno)); die_errno("git rm: '%s'", path);
} }
} }



2
builtin-send-pack.c

@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
po.out = fd; po.out = fd;
po.git_cmd = 1; po.git_cmd = 1;
if (start_command(&po)) if (start_command(&po))
die("git pack-objects failed (%s)", strerror(errno)); die_errno("git pack-objects failed");


/* /*
* We feed the pack-objects we just spawned with revision * We feed the pack-objects we just spawned with revision

2
builtin-stripspace.c

@ -78,7 +78,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
strip_comments = 1; strip_comments = 1;


if (strbuf_read(&buf, 0, 1024) < 0) if (strbuf_read(&buf, 0, 1024) < 0)
die("could not read the input"); die_errno("could not read the input");


stripspace(&buf, strip_comments); stripspace(&buf, strip_comments);



9
builtin-tag.c

@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,
path = git_pathdup("TAG_EDITMSG"); path = git_pathdup("TAG_EDITMSG");
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (fd < 0) if (fd < 0)
die("could not create file '%s': %s", die_errno("could not create file '%s'", path);
path, strerror(errno));


if (!is_null_sha1(prev)) if (!is_null_sha1(prev))
write_tag_body(fd, prev); write_tag_body(fd, prev);
@ -443,11 +442,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
else { else {
if (!strcmp(msgfile, "-")) { if (!strcmp(msgfile, "-")) {
if (strbuf_read(&buf, 0, 1024) < 0) if (strbuf_read(&buf, 0, 1024) < 0)
die("cannot read %s", msgfile); die_errno("cannot read '%s'", msgfile);
} else { } else {
if (strbuf_read_file(&buf, msgfile, 1024) < 0) if (strbuf_read_file(&buf, msgfile, 1024) < 0)
die("could not open or read '%s': %s", die_errno("could not open or read '%s'",
msgfile, strerror(errno)); msgfile);
} }
} }
} }

2
builtin-tar-tree.c

@ -91,7 +91,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)


n = write_in_full(1, content + 11, 41); n = write_in_full(1, content + 11, 41);
if (n < 41) if (n < 41)
die("git get-tar-commit-id: write error"); die_errno("git get-tar-commit-id: write error");


return 0; return 0;
} }

2
builtin-unpack-objects.c

@ -68,7 +68,7 @@ static void *fill(int min)
if (ret <= 0) { if (ret <= 0) {
if (!ret) if (!ret)
die("early EOF"); die("early EOF");
die("read error on input: %s", strerror(errno)); die_errno("read error on input");
} }
len += ret; len += ret;
} while (len < min); } while (len < min);

2
combine-diff.c

@ -746,7 +746,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,


done = read_in_full(fd, result, len); done = read_in_full(fd, result, len);
if (done < 0) if (done < 0)
die("read error '%s'", elem->path); die_errno("read error '%s'", elem->path);
else if (done < len) else if (done < len)
die("early EOF '%s'", elem->path); die("early EOF '%s'", elem->path);



5
csum-file.c

@ -26,7 +26,7 @@ static void flush(struct sha1file *f, void * buf, unsigned int count)
} }
if (!ret) if (!ret)
die("sha1 file '%s' write error. Out of diskspace", f->name); die("sha1 file '%s' write error. Out of diskspace", f->name);
die("sha1 file '%s' write error (%s)", f->name, strerror(errno)); die_errno("sha1 file '%s' write error", f->name);
} }
} }


@ -55,8 +55,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
if (flags & CSUM_FSYNC) if (flags & CSUM_FSYNC)
fsync_or_die(f->fd, f->name); fsync_or_die(f->fd, f->name);
if (close(f->fd)) if (close(f->fd))
die("%s: sha1 file error on close (%s)", die_errno("%s: sha1 file error on close", f->name);
f->name, strerror(errno));
fd = 0; fd = 0;
} else } else
fd = f->fd; fd = f->fd;

15
daemon.c

@ -902,7 +902,7 @@ static int service_loop(int socknum, int *socklist)
case ECONNABORTED: case ECONNABORTED:
continue; continue;
default: default:
die("accept returned %s", strerror(errno)); die_errno("accept returned");
} }
} }
handle(incoming, (struct sockaddr *)&ss, sslen); handle(incoming, (struct sockaddr *)&ss, sslen);
@ -918,7 +918,7 @@ static void sanitize_stdfds(void)
while (fd != -1 && fd < 2) while (fd != -1 && fd < 2)
fd = dup(fd); fd = dup(fd);
if (fd == -1) if (fd == -1)
die("open /dev/null or dup failed: %s", strerror(errno)); die_errno("open /dev/null or dup failed");
if (fd > 2) if (fd > 2)
close(fd); close(fd);
} }
@ -929,12 +929,12 @@ static void daemonize(void)
case 0: case 0:
break; break;
case -1: case -1:
die("fork failed: %s", strerror(errno)); die_errno("fork failed");
default: default:
exit(0); exit(0);
} }
if (setsid() == -1) if (setsid() == -1)
die("setsid failed: %s", strerror(errno)); die_errno("setsid failed");
close(0); close(0);
close(1); close(1);
close(2); close(2);
@ -945,9 +945,9 @@ static void store_pid(const char *path)
{ {
FILE *f = fopen(path, "w"); FILE *f = fopen(path, "w");
if (!f) if (!f)
die("cannot open pid file %s: %s", path, strerror(errno)); die_errno("cannot open pid file '%s'", path);
if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0) if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0)
die("failed to write pid file %s: %s", path, strerror(errno)); die_errno("failed to write pid file '%s'", path);
} }


static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid) static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
@ -1147,8 +1147,7 @@ int main(int argc, char **argv)
socklen_t slen = sizeof(ss); socklen_t slen = sizeof(ss);


if (!freopen("/dev/null", "w", stderr)) if (!freopen("/dev/null", "w", stderr))
die("failed to redirect stderr to /dev/null: %s", die_errno("failed to redirect stderr to /dev/null");
strerror(errno));


if (getpeername(0, peer, &slen)) if (getpeername(0, peer, &slen))
peer = NULL; peer = NULL;

10
diff.c

@ -1975,14 +1975,14 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf, fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,
strlen(base) + 1); strlen(base) + 1);
if (fd < 0) if (fd < 0)
die("unable to create temp-file: %s", strerror(errno)); die_errno("unable to create temp-file");
if (convert_to_working_tree(path, if (convert_to_working_tree(path,
(const char *)blob, (size_t)size, &buf)) { (const char *)blob, (size_t)size, &buf)) {
blob = buf.buf; blob = buf.buf;
size = buf.len; size = buf.len;
} }
if (write_in_full(fd, blob, size) != size) if (write_in_full(fd, blob, size) != size)
die("unable to write temp-file"); die_errno("unable to write temp-file");
close(fd); close(fd);
temp->name = temp->tmp_path; temp->name = temp->tmp_path;
strcpy(temp->hex, sha1_to_hex(sha1)); strcpy(temp->hex, sha1_to_hex(sha1));
@ -2021,12 +2021,12 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
if (lstat(name, &st) < 0) { if (lstat(name, &st) < 0) {
if (errno == ENOENT) if (errno == ENOENT)
goto not_a_valid_file; goto not_a_valid_file;
die("stat(%s): %s", name, strerror(errno)); die_errno("stat(%s)", name);
} }
if (S_ISLNK(st.st_mode)) { if (S_ISLNK(st.st_mode)) {
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
if (strbuf_readlink(&sb, name, st.st_size) < 0) if (strbuf_readlink(&sb, name, st.st_size) < 0)
die("readlink(%s)", name); die_errno("readlink(%s)", name);
prep_temp_blob(name, temp, sb.buf, sb.len, prep_temp_blob(name, temp, sb.buf, sb.len,
(one->sha1_valid ? (one->sha1_valid ?
one->sha1 : null_sha1), one->sha1 : null_sha1),
@ -2219,7 +2219,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
return; return;
} }
if (lstat(one->path, &st) < 0) if (lstat(one->path, &st) < 0)
die("stat %s", one->path); die_errno("stat '%s'", one->path);
if (index_path(one->sha1, one->path, &st, 0)) if (index_path(one->sha1, one->path, &st, 0))
die("cannot hash %s", one->path); die("cannot hash %s", one->path);
} }

2
dir.c

@ -759,7 +759,7 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
if (!dir) if (!dir)
return NULL; return NULL;
if (!getcwd(buffer, size)) if (!getcwd(buffer, size))
die("can't find the current directory: %s", strerror(errno)); die_errno("can't find the current directory");


if (!is_absolute_path(dir)) if (!is_absolute_path(dir))
dir = make_absolute_path(dir); dir = make_absolute_path(dir);

10
entry.c

@ -37,7 +37,7 @@ static void create_directories(const char *path, int path_len,
if (errno == EEXIST && state->force && if (errno == EEXIST && state->force &&
!unlink_or_warn(buf) && !mkdir(buf, 0777)) !unlink_or_warn(buf) && !mkdir(buf, 0777))
continue; continue;
die("cannot create directory at %s", buf); die_errno("cannot create directory at '%s'", buf);
} }
} }
free(buf); free(buf);
@ -51,7 +51,7 @@ static void remove_subtree(const char *path)
char *name; char *name;


if (!dir) if (!dir)
die("cannot opendir %s (%s)", path, strerror(errno)); die_errno("cannot opendir '%s'", path);
strcpy(pathbuf, path); strcpy(pathbuf, path);
name = pathbuf + strlen(path); name = pathbuf + strlen(path);
*name++ = '/'; *name++ = '/';
@ -61,15 +61,15 @@ static void remove_subtree(const char *path)
continue; continue;
strcpy(name, de->d_name); strcpy(name, de->d_name);
if (lstat(pathbuf, &st)) if (lstat(pathbuf, &st))
die("cannot lstat %s (%s)", pathbuf, strerror(errno)); die_errno("cannot lstat '%s'", pathbuf);
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
remove_subtree(pathbuf); remove_subtree(pathbuf);
else if (unlink(pathbuf)) else if (unlink(pathbuf))
die("cannot unlink %s (%s)", pathbuf, strerror(errno)); die_errno("cannot unlink '%s'", pathbuf);
} }
closedir(dir); closedir(dir);
if (rmdir(path)) if (rmdir(path))
die("cannot rmdir %s (%s)", path, strerror(errno)); die_errno("cannot rmdir '%s'", path);
} }


static int create_file(const char *path, unsigned int mode) static int create_file(const char *path, unsigned int mode)

8
fast-import.c

@ -905,10 +905,10 @@ static char *keep_pack(char *curr_index_name)


keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1); keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);
if (keep_fd < 0) if (keep_fd < 0)
die("cannot create keep file"); die_errno("cannot create keep file");
write_or_die(keep_fd, keep_msg, strlen(keep_msg)); write_or_die(keep_fd, keep_msg, strlen(keep_msg));
if (close(keep_fd)) if (close(keep_fd))
die("failed to write keep file"); die_errno("failed to write keep file");


snprintf(name, sizeof(name), "%s/pack/pack-%s.pack", snprintf(name, sizeof(name), "%s/pack/pack-%s.pack",
get_object_directory(), sha1_to_hex(pack_data->sha1)); get_object_directory(), sha1_to_hex(pack_data->sha1));
@ -2342,7 +2342,7 @@ static void import_marks(const char *input_file)
char line[512]; char line[512];
FILE *f = fopen(input_file, "r"); FILE *f = fopen(input_file, "r");
if (!f) if (!f)
die("cannot read %s: %s", input_file, strerror(errno)); die_errno("cannot read '%s'", input_file);
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
uintmax_t mark; uintmax_t mark;
char *end; char *end;
@ -2448,7 +2448,7 @@ int main(int argc, const char **argv)
fclose(pack_edges); fclose(pack_edges);
pack_edges = fopen(a + 20, "a"); pack_edges = fopen(a + 20, "a");
if (!pack_edges) if (!pack_edges)
die("Cannot open %s: %s", a + 20, strerror(errno)); die_errno("Cannot open '%s'", a + 20);
} else if (!strcmp(a, "--force")) } else if (!strcmp(a, "--force"))
force_update = 1; force_update = 1;
else if (!strcmp(a, "--quiet")) else if (!strcmp(a, "--quiet"))

1
git-compat-util.h

@ -175,6 +175,7 @@ extern char *gitbasename(char *);
/* General helper functions */ /* General helper functions */
extern void usage(const char *err) NORETURN; extern void usage(const char *err) NORETURN;
extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));



6
git.c

@ -199,7 +199,7 @@ static int handle_alias(int *argcp, const char ***argv)
} }


if (subdir && chdir(subdir)) if (subdir && chdir(subdir))
die("Cannot change to %s: %s", subdir, strerror(errno)); die_errno("Cannot change to '%s'", subdir);


errno = saved_errno; errno = saved_errno;


@ -256,11 +256,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)


/* Check for ENOSPC and EIO errors.. */ /* Check for ENOSPC and EIO errors.. */
if (fflush(stdout)) if (fflush(stdout))
die("write failure on standard output: %s", strerror(errno)); die_errno("write failure on standard output");
if (ferror(stdout)) if (ferror(stdout))
die("unknown write failure on standard output"); die("unknown write failure on standard output");
if (fclose(stdout)) if (fclose(stdout))
die("close failed on standard output: %s", strerror(errno)); die_errno("close failed on standard output");
return 0; return 0;
} }



2
hash-object.c

@ -29,7 +29,7 @@ static void hash_object(const char *path, const char *type, int write_object,
int fd; int fd;
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) if (fd < 0)
die("Cannot open %s", path); die_errno("Cannot open '%s'", path);
hash_fd(fd, type, write_object, vpath); hash_fd(fd, type, write_object, vpath);
} }



21
index-pack.c

@ -143,7 +143,7 @@ static void *fill(int min)
if (ret <= 0) { if (ret <= 0) {
if (!ret) if (!ret)
die("early EOF"); die("early EOF");
die("read error on input: %s", strerror(errno)); die_errno("read error on input");
} }
input_len += ret; input_len += ret;
if (from_stdin) if (from_stdin)
@ -178,13 +178,12 @@ static char *open_pack_file(char *pack_name)
} else } else
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600); output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd < 0) if (output_fd < 0)
die("unable to create %s: %s", pack_name, strerror(errno)); die_errno("unable to create '%s'", pack_name);
pack_fd = output_fd; pack_fd = output_fd;
} else { } else {
input_fd = open(pack_name, O_RDONLY); input_fd = open(pack_name, O_RDONLY);
if (input_fd < 0) if (input_fd < 0)
die("cannot open packfile '%s': %s", die_errno("cannot open packfile '%s'", pack_name);
pack_name, strerror(errno));
output_fd = -1; output_fd = -1;
pack_fd = input_fd; pack_fd = input_fd;
} }
@ -370,7 +369,7 @@ static void *get_data_from_pack(struct object_entry *obj)
do { do {
ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy); ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
if (n < 0) if (n < 0)
die("cannot pread pack file: %s", strerror(errno)); die_errno("cannot pread pack file");
if (!n) if (!n)
die("premature end of pack file, %lu bytes missing", die("premature end of pack file, %lu bytes missing",
len - rdy); len - rdy);
@ -631,7 +630,7 @@ static void parse_pack_objects(unsigned char *sha1)


/* If input_fd is a file, we should have reached its end now. */ /* If input_fd is a file, we should have reached its end now. */
if (fstat(input_fd, &st)) if (fstat(input_fd, &st))
die("cannot fstat packfile: %s", strerror(errno)); die_errno("cannot fstat packfile");
if (S_ISREG(st.st_mode) && if (S_ISREG(st.st_mode) &&
lseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size) lseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size)
die("pack has junk at the end"); die("pack has junk at the end");
@ -788,7 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
fsync_or_die(output_fd, curr_pack_name); fsync_or_die(output_fd, curr_pack_name);
err = close(output_fd); err = close(output_fd);
if (err) if (err)
die("error while closing pack file: %s", strerror(errno)); die_errno("error while closing pack file");
} }


if (keep_msg) { if (keep_msg) {
@ -801,16 +800,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name,


if (keep_fd < 0) { if (keep_fd < 0) {
if (errno != EEXIST) if (errno != EEXIST)
die("cannot write keep file '%s' (%s)", die_errno("cannot write keep file '%s'",
keep_name, strerror(errno)); keep_name);
} else { } else {
if (keep_msg_len > 0) { if (keep_msg_len > 0) {
write_or_die(keep_fd, keep_msg, keep_msg_len); write_or_die(keep_fd, keep_msg, keep_msg_len);
write_or_die(keep_fd, "\n", 1); write_or_die(keep_fd, "\n", 1);
} }
if (close(keep_fd) != 0) if (close(keep_fd) != 0)
die("cannot close written keep file '%s' (%s)", die_errno("cannot close written keep file '%s'",
keep_name, strerror(errno)); keep_name);
report = "keep"; report = "keep";
} }
} }

2
ll-merge.c

@ -152,7 +152,7 @@ static void create_temp(mmfile_t *src, char *path)
strcpy(path, ".merge_file_XXXXXX"); strcpy(path, ".merge_file_XXXXXX");
fd = xmkstemp(path); fd = xmkstemp(path);
if (write_in_full(fd, src->ptr, src->size) != src->size) if (write_in_full(fd, src->ptr, src->size) != src->size)
die("unable to write temp-file"); die_errno("unable to write temp-file");
close(fd); close(fd);
} }



6
merge-recursive.c

@ -438,7 +438,7 @@ static void flush_buffer(int fd, const char *buf, unsigned long size)
/* Ignore epipe */ /* Ignore epipe */
if (errno == EPIPE) if (errno == EPIPE)
break; break;
die("merge-recursive: %s", strerror(errno)); die_errno("merge-recursive");
} else if (!ret) { } else if (!ret) {
die("merge-recursive: disk full?"); die("merge-recursive: disk full?");
} }
@ -554,7 +554,7 @@ static void update_file_flags(struct merge_options *o,
mode = 0666; mode = 0666;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode); fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
if (fd < 0) if (fd < 0)
die("failed to open %s: %s", path, strerror(errno)); die_errno("failed to open '%s'", path);
flush_buffer(fd, buf, size); flush_buffer(fd, buf, size);
close(fd); close(fd);
} else if (S_ISLNK(mode)) { } else if (S_ISLNK(mode)) {
@ -562,7 +562,7 @@ static void update_file_flags(struct merge_options *o,
safe_create_leading_directories_const(path); safe_create_leading_directories_const(path);
unlink(path); unlink(path);
if (symlink(lnk, path)) if (symlink(lnk, path))
die("failed to symlink %s: %s", path, strerror(errno)); die_errno("failed to symlink '%s'", path);
free(lnk); free(lnk);
} else } else
die("do not know what to do with %06o %s '%s'", die("do not know what to do with %06o %s '%s'",

2
mktag.c

@ -165,7 +165,7 @@ int main(int argc, char **argv)
setup_git_directory(); setup_git_directory();


if (strbuf_read(&buf, 0, 4096) < 0) { if (strbuf_read(&buf, 0, 4096) < 0) {
die("could not read from stdin"); die_errno("could not read from stdin");
} }


/* Verify it for some basic sanity: it needs to start with /* Verify it for some basic sanity: it needs to start with

7
pack-refs.c

@ -93,8 +93,7 @@ int pack_refs(unsigned int flags)
LOCK_DIE_ON_ERROR); LOCK_DIE_ON_ERROR);
cbdata.refs_file = fdopen(fd, "w"); cbdata.refs_file = fdopen(fd, "w");
if (!cbdata.refs_file) if (!cbdata.refs_file)
die("unable to create ref-pack file structure (%s)", die_errno("unable to create ref-pack file structure");
strerror(errno));


/* perhaps other traits later as well */ /* perhaps other traits later as well */
fprintf(cbdata.refs_file, "# pack-refs with: peeled \n"); fprintf(cbdata.refs_file, "# pack-refs with: peeled \n");
@ -103,7 +102,7 @@ int pack_refs(unsigned int flags)
if (ferror(cbdata.refs_file)) if (ferror(cbdata.refs_file))
die("failed to write ref-pack file"); die("failed to write ref-pack file");
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file)) if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))
die("failed to write ref-pack file (%s)", strerror(errno)); die_errno("failed to write ref-pack file");
/* /*
* Since the lock file was fdopen()'ed and then fclose()'ed above, * Since the lock file was fdopen()'ed and then fclose()'ed above,
* assign -1 to the lock file descriptor so that commit_lock_file() * assign -1 to the lock file descriptor so that commit_lock_file()
@ -111,7 +110,7 @@ int pack_refs(unsigned int flags)
*/ */
packed.fd = -1; packed.fd = -1;
if (commit_lock_file(&packed) < 0) if (commit_lock_file(&packed) < 0)
die("unable to overwrite old ref-pack file (%s)", strerror(errno)); die_errno("unable to overwrite old ref-pack file");
if (cbdata.flags & PACK_REFS_PRUNE) if (cbdata.flags & PACK_REFS_PRUNE)
prune_refs(cbdata.ref_to_prune); prune_refs(cbdata.ref_to_prune);
return 0; return 0;

10
pack-write.c

@ -51,7 +51,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
} }
if (fd < 0) if (fd < 0)
die("unable to create %s: %s", index_name, strerror(errno)); die_errno("unable to create '%s'", index_name);
f = sha1fd(fd, index_name); f = sha1fd(fd, index_name);


/* if last object's offset is >= 2^31 we should use index V2 */ /* if last object's offset is >= 2^31 we should use index V2 */
@ -174,11 +174,11 @@ void fixup_pack_header_footer(int pack_fd,
git_SHA1_Init(&new_sha1_ctx); git_SHA1_Init(&new_sha1_ctx);


if (lseek(pack_fd, 0, SEEK_SET) != 0) if (lseek(pack_fd, 0, SEEK_SET) != 0)
die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); die_errno("Failed seeking to start of '%s'", pack_name);
if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
die("Unable to reread header of %s: %s", pack_name, strerror(errno)); die_errno("Unable to reread header of '%s'", pack_name);
if (lseek(pack_fd, 0, SEEK_SET) != 0) if (lseek(pack_fd, 0, SEEK_SET) != 0)
die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); die_errno("Failed seeking to start of '%s'", pack_name);
git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr)); git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));
hdr.hdr_entries = htonl(object_count); hdr.hdr_entries = htonl(object_count);
git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr)); git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));
@ -195,7 +195,7 @@ void fixup_pack_header_footer(int pack_fd,
if (!n) if (!n)
break; break;
if (n < 0) if (n < 0)
die("Failed to checksum %s: %s", pack_name, strerror(errno)); die_errno("Failed to checksum '%s'", pack_name);
git_SHA1_Update(&new_sha1_ctx, buf, n); git_SHA1_Update(&new_sha1_ctx, buf, n);


aligned_sz -= n; aligned_sz -= n;

4
pkt-line.c

@ -28,7 +28,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
} }
if (!ret) if (!ret)
die("write error (disk full?)"); die("write error (disk full?)");
die("write error (%s)", strerror(errno)); die_errno("write error");
} }
return nn; return nn;
} }
@ -67,7 +67,7 @@ static void safe_read(int fd, void *buffer, unsigned size)
{ {
ssize_t ret = read_in_full(fd, buffer, size); ssize_t ret = read_in_full(fd, buffer, size);
if (ret < 0) if (ret < 0)
die("read error (%s)", strerror(errno)); die_errno("read error");
else if (ret < size) else if (ret < size)
die("The remote end hung up unexpectedly"); die("The remote end hung up unexpectedly");
} }

8
read-cache.c

@ -638,7 +638,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
{ {
struct stat st; struct stat st;
if (lstat(path, &st)) if (lstat(path, &st))
die("%s: unable to stat (%s)", path, strerror(errno)); die_errno("unable to stat '%s'", path);
return add_to_index(istate, path, &st, flags); return add_to_index(istate, path, &st, flags);
} }


@ -1251,11 +1251,11 @@ int read_index_from(struct index_state *istate, const char *path)
if (fd < 0) { if (fd < 0) {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
die("index file open failed (%s)", strerror(errno)); die_errno("index file open failed");
} }


if (fstat(fd, &st)) if (fstat(fd, &st))
die("cannot stat the open index (%s)", strerror(errno)); die_errno("cannot stat the open index");


errno = EINVAL; errno = EINVAL;
mmap_size = xsize_t(st.st_size); mmap_size = xsize_t(st.st_size);
@ -1265,7 +1265,7 @@ int read_index_from(struct index_state *istate, const char *path)
mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd); close(fd);
if (mmap == MAP_FAILED) if (mmap == MAP_FAILED)
die("unable to map index file"); die_errno("unable to map index file");


hdr = mmap; hdr = mmap;
if (verify_hdr(hdr, mmap_size) < 0) if (verify_hdr(hdr, mmap_size) < 0)

2
refs.c

@ -1418,7 +1418,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
logfile = git_path("logs/%s", ref); logfile = git_path("logs/%s", ref);
logfd = open(logfile, O_RDONLY, 0); logfd = open(logfile, O_RDONLY, 0);
if (logfd < 0) if (logfd < 0)
die("Unable to read log %s: %s", logfile, strerror(errno)); die_errno("Unable to read log '%s'", logfile);
fstat(logfd, &st); fstat(logfd, &st);
if (!st.st_size) if (!st.st_size)
die("Log %s is empty.", logfile); die("Log %s is empty.", logfile);

4
run-command.c

@ -101,8 +101,8 @@ int start_command(struct child_process *cmd)
} }


if (cmd->dir && chdir(cmd->dir)) if (cmd->dir && chdir(cmd->dir))
die("exec %s: cd to %s failed (%s)", cmd->argv[0], die_errno("exec '%s': cd to '%s' failed", cmd->argv[0],
cmd->dir, strerror(errno)); cmd->dir);
if (cmd->env) { if (cmd->env) {
for (; *cmd->env; cmd->env++) { for (; *cmd->env; cmd->env++) {
if (strchr(*cmd->env, '=')) if (strchr(*cmd->env, '='))

18
setup.c

@ -81,7 +81,7 @@ void verify_filename(const char *prefix, const char *arg)
if (errno == ENOENT) if (errno == ENOENT)
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
"Use '--' to separate paths from revisions", arg); "Use '--' to separate paths from revisions", arg);
die("'%s': %s", arg, strerror(errno)); die_errno("failed to stat '%s'", arg);
} }


/* /*
@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg)
die("ambiguous argument '%s': both revision and filename\n" die("ambiguous argument '%s': both revision and filename\n"
"Use '--' to separate filenames from revisions", arg); "Use '--' to separate filenames from revisions", arg);
if (errno != ENOENT && errno != ENOTDIR) if (errno != ENOENT && errno != ENOTDIR)
die("'%s': %s", arg, strerror(errno)); die_errno("failed to stat '%s'", arg);
} }


const char **get_pathspec(const char *prefix, const char **pathspec) const char **get_pathspec(const char *prefix, const char **pathspec)
@ -257,7 +257,7 @@ const char *read_gitfile_gently(const char *path)
return NULL; return NULL;
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) if (fd < 0)
die("Error opening %s: %s", path, strerror(errno)); die_errno("Error opening '%s'", path);
buf = xmalloc(st.st_size + 1); buf = xmalloc(st.st_size + 1);
len = read_in_full(fd, buf, st.st_size); len = read_in_full(fd, buf, st.st_size);
close(fd); close(fd);
@ -327,7 +327,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
return NULL; return NULL;
set_git_dir(make_absolute_path(gitdirenv)); set_git_dir(make_absolute_path(gitdirenv));
if (chdir(work_tree_env) < 0) if (chdir(work_tree_env) < 0)
die ("Could not chdir to %s", work_tree_env); die_errno ("Could not chdir to '%s'", work_tree_env);
strcat(buffer, "/"); strcat(buffer, "/");
return retval; return retval;
} }
@ -339,7 +339,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
} }


if (!getcwd(cwd, sizeof(cwd)-1)) if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory"); die_errno("Unable to read current working directory");


ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs); ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);
if (ceil_offset < 0 && has_dos_drive_prefix(cwd)) if (ceil_offset < 0 && has_dos_drive_prefix(cwd))
@ -382,14 +382,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (offset <= ceil_offset) { if (offset <= ceil_offset) {
if (nongit_ok) { if (nongit_ok) {
if (chdir(cwd)) if (chdir(cwd))
die("Cannot come back to cwd"); die_errno("Cannot come back to cwd");
*nongit_ok = 1; *nongit_ok = 1;
return NULL; return NULL;
} }
die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT); die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
} }
if (chdir("..")) if (chdir(".."))
die("Cannot change to %s/..: %s", cwd, strerror(errno)); die_errno("Cannot change to '%s/..'", cwd);
} }


inside_git_dir = 0; inside_git_dir = 0;
@ -493,10 +493,10 @@ const char *setup_git_directory(void)
static char buffer[PATH_MAX + 1]; static char buffer[PATH_MAX + 1];
char *rel; char *rel;
if (retval && chdir(retval)) if (retval && chdir(retval))
die ("Could not jump back into original cwd"); die_errno ("Could not jump back into original cwd");
rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree()); rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());
if (rel && *rel && chdir(get_git_work_tree())) if (rel && *rel && chdir(get_git_work_tree()))
die ("Could not jump to working directory"); die_errno ("Could not jump to working directory");
return rel && *rel ? strcat(rel, "/") : NULL; return rel && *rel ? strcat(rel, "/") : NULL;
} }



2
sha1_file.c

@ -2286,7 +2286,7 @@ static void close_sha1_file(int fd)
if (fsync_object_files) if (fsync_object_files)
fsync_or_die(fd, "sha1 file"); fsync_or_die(fd, "sha1 file");
if (close(fd) != 0) if (close(fd) != 0)
die("error when closing sha1 file (%s)", strerror(errno)); die_errno("error when closing sha1 file");
} }


/* Size of directory component, including the ending '/' */ /* Size of directory component, including the ending '/' */

2
shell.c

@ -60,7 +60,7 @@ int main(int argc, char **argv)
while (devnull_fd >= 0 && devnull_fd <= 2) while (devnull_fd >= 0 && devnull_fd <= 2)
devnull_fd = dup(devnull_fd); devnull_fd = dup(devnull_fd);
if (devnull_fd == -1) if (devnull_fd == -1)
die("opening /dev/null failed (%s)", strerror(errno)); die_errno("opening /dev/null failed");
close (devnull_fd); close (devnull_fd);


/* /*

2
test-sha1.c

@ -32,7 +32,7 @@ int main(int ac, char **av)
if (sz == 0) if (sz == 0)
break; break;
if (sz < 0) if (sz < 0)
die("test-sha1: %s", strerror(errno)); die_errno("test-sha1");
this_sz += sz; this_sz += sz;
cp += sz; cp += sz;
room -= sz; room -= sz;

4
transport.c

@ -158,7 +158,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)


strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX"));
if (!mkdtemp(temp_dir.buf)) if (!mkdtemp(temp_dir.buf))
die ("Could not make temporary directory"); die_errno ("Could not make temporary directory");
temp_dir_len = temp_dir.len; temp_dir_len = temp_dir.len;


strbuf_addstr(&buf, rsync_url(transport->url)); strbuf_addstr(&buf, rsync_url(transport->url));
@ -321,7 +321,7 @@ static int rsync_transport_push(struct transport *transport,


strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX"));
if (!mkdtemp(temp_dir.buf)) if (!mkdtemp(temp_dir.buf))
die ("Could not make temporary directory"); die_errno ("Could not make temporary directory");
strbuf_addch(&temp_dir, '/'); strbuf_addch(&temp_dir, '/');


if (flags & TRANSPORT_PUSH_ALL) { if (flags & TRANSPORT_PUSH_ALL) {

2
unpack-file.c

@ -17,7 +17,7 @@ static char *create_temp_file(unsigned char *sha1)
strcpy(path, ".merge_file_XXXXXX"); strcpy(path, ".merge_file_XXXXXX");
fd = xmkstemp(path); fd = xmkstemp(path);
if (write_in_full(fd, buf, size) != size) if (write_in_full(fd, buf, size) != size)
die("unable to write temp-file"); die_errno("unable to write temp-file");
close(fd); close(fd);
return path; return path;
} }

28
usage.c

@ -60,6 +60,34 @@ void die(const char *err, ...)
va_end(params); va_end(params);
} }


void die_errno(const char *fmt, ...)
{
va_list params;
char fmt_with_err[1024];
char str_error[256], *err;
int i, j;

err = strerror(errno);
for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
if ((str_error[j++] = err[i++]) != '%')
continue;
if (j < sizeof(str_error) - 1) {
str_error[j++] = '%';
} else {
/* No room to double the '%', so we overwrite it with
* '\0' below */
j--;
break;
}
}
str_error[j] = 0;
snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);

va_start(params, fmt);
die_routine(fmt_with_err, params);
va_end(params);
}

int error(const char *err, ...) int error(const char *err, ...)
{ {
va_list params; va_list params;

8
wrapper.c

@ -96,7 +96,7 @@ void *xmmap(void *start, size_t length,
release_pack_memory(length, fd); release_pack_memory(length, fd);
ret = mmap(start, length, prot, flags, fd, offset); ret = mmap(start, length, prot, flags, fd, offset);
if (ret == MAP_FAILED) if (ret == MAP_FAILED)
die("Out of memory? mmap failed: %s", strerror(errno)); die_errno("Out of memory? mmap failed");
} }
return ret; return ret;
} }
@ -175,7 +175,7 @@ int xdup(int fd)
{ {
int ret = dup(fd); int ret = dup(fd);
if (ret < 0) if (ret < 0)
die("dup failed: %s", strerror(errno)); die_errno("dup failed");
return ret; return ret;
} }


@ -183,7 +183,7 @@ FILE *xfdopen(int fd, const char *mode)
{ {
FILE *stream = fdopen(fd, mode); FILE *stream = fdopen(fd, mode);
if (stream == NULL) if (stream == NULL)
die("Out of memory? fdopen failed: %s", strerror(errno)); die_errno("Out of memory? fdopen failed");
return stream; return stream;
} }


@ -193,7 +193,7 @@ int xmkstemp(char *template)


fd = mkstemp(template); fd = mkstemp(template);
if (fd < 0) if (fd < 0)
die("Unable to create temporary file: %s", strerror(errno)); die_errno("Unable to create temporary file");
return fd; return fd;
} }



6
write_or_die.c

@ -41,14 +41,14 @@ void maybe_flush_or_die(FILE *f, const char *desc)
*/ */
if (errno == EPIPE || errno == EINVAL) if (errno == EPIPE || errno == EINVAL)
exit(0); exit(0);
die("write failure on %s: %s", desc, strerror(errno)); die_errno("write failure on '%s'", desc);
} }
} }


void fsync_or_die(int fd, const char *msg) void fsync_or_die(int fd, const char *msg)
{ {
if (fsync(fd) < 0) { if (fsync(fd) < 0) {
die("%s: fsync error (%s)", msg, strerror(errno)); die_errno("fsync error on '%s'", msg);
} }
} }


@ -57,7 +57,7 @@ void write_or_die(int fd, const void *buf, size_t count)
if (write_in_full(fd, buf, count) < 0) { if (write_in_full(fd, buf, count) < 0) {
if (errno == EPIPE) if (errno == EPIPE)
exit(0); exit(0);
die("write error (%s)", strerror(errno)); die_errno("write error");
} }
} }



Loading…
Cancel
Save