Convert existing die(..., strerror(errno)) to die_errno()
Change calls to die(..., strerror(errno)) to use the new die_errno(). In the process, also make slight style adjustments: at least state _something_ about the function that failed (instead of just printing the pathname), and put paths in single quotes. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Jun 27, 2009 at 17:58 UTC
d824cbba02a4061400a0e382f9bd241fbbff34f0
42 files changed
+117
-133
bisect.c
+2
-3
@@ -461,7 +461,7 @@ void read_bisect_paths(struct argv_array *array)
461
FILE *fp = fopen(filename, "r");
462
463
if (!fp)
464
- die("Could not open file '%s': %s", filename, strerror(errno));
464
+ die_errno("Could not open file '%s'", filename);
465
466
while (strbuf_getline(&str, fp, '\n') != EOF) {
467
char *quoted;
@@ -632,8 +632,7 @@ static void mark_expected_rev(char *bisect_rev_hex)
632
int fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
633
634
if (fd < 0)
635
- die("could not create file '%s': %s",
636
- filename, strerror(errno));
635
+ die_errno("could not create file '%s'", filename);
636
637
bisect_rev_hex[len] = '\n';
638
write_or_die(fd, bisect_rev_hex, len + 1);
branch.c
+2
-2
@@ -172,7 +172,7 @@ void create_branch(const char *head,
172
173
lock = lock_any_ref_for_update(ref.buf, NULL, 0);
174
if (!lock)
175
- die("Failed to lock ref for update: %s.", strerror(errno));
175
+ die_errno("Failed to lock ref for update");
176
177
if (reflog)
178
log_all_ref_updates = 1;
@@ -188,7 +188,7 @@ void create_branch(const char *head,
188
setup_tracking(name, real_ref, track);
189
190
if (write_ref_sha1(lock, sha1, msg) < 0)
191
- die("Failed to write ref: %s.", strerror(errno));
191
+ die_errno("Failed to write ref");
192
193
strbuf_release(&ref);
194
free(real_ref);
builtin-apply.c
+3
-3
@@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,
280
static void read_patch_file(struct strbuf *sb, int fd)
281
{
282
if (strbuf_read(sb, fd, 0) < 0)
283
- die("git apply: read returned %s", strerror(errno));
283
+ die_errno("git apply: failed to read");
284
285
/*
286
* Make sure that we have some slop in the buffer
@@ -2864,7 +2864,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
2864
strbuf_release(&nbuf);
2865
2866
if (close(fd) < 0)
2867
- die("closing file %s: %s", path, strerror(errno));
2867
+ die_errno("closing file '%s'", path);
2868
return 0;
2869
}
2870
@@ -3354,7 +3354,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3354
3355
fd = open(arg, O_RDONLY);
3356
if (fd < 0)
3357
- die("can't open patch '%s': %s", arg, strerror(errno));
3357
+ die_errno("can't open patch '%s'", arg);
3358
read_stdin = 0;
3359
set_default_whitespace_mode(whitespace_option);
3360
errs |= apply_patch(fd, arg, options);
builtin-blame.c
+3
-4
@@ -2035,7 +2035,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2035
contents_from = "standard input";
2036
mode = 0;
2037
if (strbuf_read(&buf, 0, 0) < 0)
2038
- die("read error %s from stdin", strerror(errno));
2038
+ die_errno("failed to read from stdin");
2039
}
2040
convert_to_git(path, buf.buf, buf.len, &buf, 0);
2041
origin->file.ptr = buf.buf;
@@ -2261,8 +2261,7 @@ parse_done:
2261
argc = parse_options_end(&ctx);
2262
2263
if (revs_file && read_ancestry(revs_file))
2264
- die("reading graft file %s failed: %s",
2265
- revs_file, strerror(errno));
2264
+ die_errno("reading graft file '%s' failed", revs_file);
2265
2266
if (cmd_is_annotate) {
2267
output_option |= OUTPUT_ANNOTATE_COMPAT;
@@ -2350,7 +2349,7 @@ parse_done:
2349
2350
setup_work_tree();
2351
if (!has_string_in_work_tree(path))
2353
- die("cannot stat path %s: %s", path, strerror(errno));
2352
+ die_errno("cannot stat path '%s'", path);
2353
}
2354
2355
setup_revisions(argc, argv, &revs, NULL);
builtin-clone.c
+5
-6
@@ -252,8 +252,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
252
}
253
254
if (unlink(dest->buf) && errno != ENOENT)
255
- die("failed to unlink %s: %s",
256
- dest->buf, strerror(errno));
255
+ die_errno("failed to unlink '%s'", dest->buf);
256
if (!option_no_hardlinks) {
257
if (!link(src->buf, dest->buf))
258
continue;
@@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
419
if (!option_bare) {
420
junk_work_tree = work_tree;
421
if (safe_create_leading_directories_const(work_tree) < 0)
423
- die("could not create leading directories of '%s': %s",
424
- work_tree, strerror(errno));
422
+ die_errno("could not create leading directories of '%s'",
423
+ work_tree);
424
if (!dest_exists && mkdir(work_tree, 0755))
426
- die("could not create work tree dir '%s': %s.",
427
- work_tree, strerror(errno));
425
+ die_errno("could not create work tree dir '%s'.",
426
+ work_tree);
427
set_git_work_tree(work_tree);
428
}
429
junk_git_dir = git_dir;
builtin-commit-tree.c
+1
-1
@@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
124
}
125
126
if (strbuf_read(&buffer, 0, 0) < 0)
127
- die("git commit-tree: read returned %s", strerror(errno));
127
+ die_errno("git commit-tree: failed to read");
128
129
if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
130
printf("%s\n", sha1_to_hex(commit_sha1));
builtin-commit.c
+10
-13
@@ -438,8 +438,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
438
hook_arg1 = "message";
439
} else if (logfile) {
440
if (strbuf_read_file(&sb, logfile, 0) < 0)
441
- die("could not read log file '%s': %s",
442
- logfile, strerror(errno));
441
+ die_errno("could not read log file '%s'",
442
+ logfile);
443
hook_arg1 = "message";
444
} else if (use_message) {
445
buffer = strstr(use_message_buffer, "\n\n");
@@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
450
hook_arg2 = use_message;
451
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
452
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
453
- die("could not read MERGE_MSG: %s", strerror(errno));
453
+ die_errno("could not read MERGE_MSG");
454
hook_arg1 = "merge";
455
} else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
456
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
457
- die("could not read SQUASH_MSG: %s", strerror(errno));
457
+ die_errno("could not read SQUASH_MSG");
458
hook_arg1 = "squash";
459
} else if (template_file && !stat(template_file, &statbuf)) {
460
if (strbuf_read_file(&sb, template_file, 0) < 0)
461
- die("could not read %s: %s",
462
- template_file, strerror(errno));
461
+ die_errno("could not read '%s'", template_file);
462
hook_arg1 = "template";
463
}
464
@@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
471
472
fp = fopen(git_path(commit_editmsg), "w");
473
if (fp == NULL)
475
- die("could not open %s: %s",
476
- git_path(commit_editmsg), strerror(errno));
474
+ die_errno("could not open '%s'", git_path(commit_editmsg));
475
476
if (cleanup_mode != CLEANUP_NONE)
477
stripspace(&sb, 0);
@@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
495
}
496
497
if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
500
- die("could not write commit template: %s", strerror(errno));
498
+ die_errno("could not write commit template");
499
500
strbuf_release(&sb);
501
@@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
938
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
939
fp = fopen(git_path("MERGE_HEAD"), "r");
940
if (fp == NULL)
943
- die("could not open %s for reading: %s",
944
- git_path("MERGE_HEAD"), strerror(errno));
941
+ die_errno("could not open '%s' for reading",
942
+ git_path("MERGE_HEAD"));
943
while (strbuf_getline(&m, fp, '\n') != EOF) {
944
unsigned char sha1[20];
945
if (get_sha1_hex(m.buf, sha1) < 0)
@@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
950
strbuf_release(&m);
951
if (!stat(git_path("MERGE_MODE"), &statbuf)) {
952
if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
955
- die("could not read MERGE_MODE: %s",
956
- strerror(errno));
953
+ die_errno("could not read MERGE_MODE");
954
if (!strcmp(sb.buf, "no-ff"))
955
allow_fast_forward = 0;
956
}
builtin-config.c
+2
-2
@@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
383
check_argc(argc, 0, 0);
384
if (git_config(show_all_config, NULL) < 0) {
385
if (config_exclusive_filename)
386
- die("unable to read config file %s: %s",
387
- config_exclusive_filename, strerror(errno));
386
+ die_errno("unable to read config file '%s'",
387
+ config_exclusive_filename);
388
else
389
die("error processing config file(s)");
390
}
builtin-diff.c
+1
-1
@@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
70
usage(builtin_diff_usage);
71
72
if (lstat(path, &st))
73
- die("'%s': %s", path, strerror(errno));
73
+ die_errno("failed to stat '%s'", path);
74
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
75
die("'%s': not a regular file or symlink", path);
76
builtin-fast-export.c
+1
-1
@@ -451,7 +451,7 @@ static void import_marks(char *input_file)
451
char line[512];
452
FILE *f = fopen(input_file, "r");
453
if (!f)
454
- die("cannot read %s: %s", input_file, strerror(errno));
454
+ die_errno("cannot read '%s'", input_file);
455
456
while (fgets(line, sizeof(line), f)) {
457
uint32_t mark;
builtin-fetch--tool.c
+1
-1
@@ -8,7 +8,7 @@ static char *get_stdin(void)
8
{
9
struct strbuf buf = STRBUF_INIT;
10
if (strbuf_read(&buf, 0, 1024) < 0) {
11
- die("error reading standard input: %s", strerror(errno));
11
+ die_errno("error reading standard input");
12
}
13
return strbuf_detach(&buf, NULL);
14
}
builtin-fmt-merge-msg.c
+1
-2
@@ -372,8 +372,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
372
}
373
374
if (strbuf_read(&input, fileno(in), 0) < 0)
375
- die("could not read input file %s", strerror(errno));
376
-
375
+ die_errno("could not read input file");
376
ret = fmt_merge_msg(merge_summary, &input, &output);
377
if (ret)
378
return ret;
builtin-fsck.c
+4
-4
@@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)
225
&type, &size);
226
if (buf) {
227
if (fwrite(buf, size, 1, f) != 1)
228
- die("Could not write %s: %s",
229
- filename, strerror(errno));
228
+ die_errno("Could not write '%s'",
229
+ filename);
230
free(buf);
231
}
232
} else
233
fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
234
if (fclose(f))
235
- die("Could not finish %s: %s",
236
- filename, strerror(errno));
235
+ die_errno("Could not finish '%s'",
236
+ filename);
237
}
238
return;
239
}
builtin-grep.c
+1
-1
@@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
594
595
patterns = fopen(arg, "r");
596
if (!patterns)
597
- die("'%s': %s", arg, strerror(errno));
597
+ die_errno("cannot open '%s'", arg);
598
while (strbuf_getline(&sb, patterns, '\n') == 0) {
599
/* ignore empty line like grep does */
600
if (sb.len == 0)
builtin-merge.c
+4
-4
@@ -294,9 +294,9 @@ static void squash_message(void)
294
NULL, NULL, rev.date_mode, 0);
295
}
296
if (write(fd, out.buf, out.len) < 0)
297
- die("Writing SQUASH_MSG: %s", strerror(errno));
297
+ die_errno("Writing SQUASH_MSG");
298
if (close(fd))
299
- die("Finishing SQUASH_MSG: %s", strerror(errno));
299
+ die_errno("Finishing SQUASH_MSG");
300
strbuf_release(&out);
301
}
302
@@ -428,8 +428,8 @@ static void merge_name(const char *remote, struct strbuf *msg)
428
429
fp = fopen(git_path("FETCH_HEAD"), "r");
430
if (!fp)
431
- die("could not open %s for reading: %s",
432
- git_path("FETCH_HEAD"), strerror(errno));
431
+ die_errno("could not open '%s' for reading",
432
+ git_path("FETCH_HEAD"));
433
strbuf_getline(&line, fp, '\n');
434
fclose(fp);
435
ptr = strstr(line.buf, "\tnot-for-merge\t");
builtin-mv.c
+1
-1
@@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
209
printf("Renaming %s to %s\n", src, dst);
210
if (!show_only && mode != INDEX &&
211
rename(src, dst) < 0 && !ignore_errors)
212
- die ("renaming %s failed: %s", src, strerror(errno));
212
+ die_errno ("renaming '%s' failed", src);
213
214
if (mode == WORKING_DIRECTORY)
215
continue;
builtin-pack-objects.c
+5
-9
@@ -536,11 +536,9 @@ static void write_pack_file(void)
536
base_name, sha1_to_hex(sha1));
537
free_pack_by_name(tmpname);
538
if (adjust_perm(pack_tmp_name, mode))
539
- die("unable to make temporary pack file readable: %s",
540
- strerror(errno));
539
+ die_errno("unable to make temporary pack file readable");
540
if (rename(pack_tmp_name, tmpname))
542
- die("unable to rename temporary pack file: %s",
543
- strerror(errno));
541
+ die_errno("unable to rename temporary pack file");
542
543
/*
544
* Packs are runtime accessed in their mtime
@@ -566,11 +564,9 @@ static void write_pack_file(void)
564
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
565
base_name, sha1_to_hex(sha1));
566
if (adjust_perm(idx_tmp_name, mode))
569
- die("unable to make temporary index file readable: %s",
570
- strerror(errno));
567
+ die_errno("unable to make temporary index file readable");
568
if (rename(idx_tmp_name, tmpname))
572
- die("unable to rename temporary index file: %s",
573
- strerror(errno));
569
+ die_errno("unable to rename temporary index file");
570
571
free(idx_tmp_name);
572
free(pack_tmp_name);
@@ -1880,7 +1876,7 @@ static void read_object_list_from_stdin(void)
1876
if (!ferror(stdin))
1877
die("fgets returned NULL, not EOF, not error!");
1878
if (errno != EINTR)
1883
- die("fgets: %s", strerror(errno));
1879
+ die_errno("fgets");
1880
clearerr(stdin);
1881
continue;
1882
}
builtin-rm.c
+1
-1
@@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
257
continue;
258
}
259
if (!removed)
260
- die("git rm: %s: %s", path, strerror(errno));
260
+ die_errno("git rm: '%s'", path);
261
}
262
}
263
builtin-send-pack.c
+1
-1
@@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
59
po.out = fd;
60
po.git_cmd = 1;
61
if (start_command(&po))
62
- die("git pack-objects failed (%s)", strerror(errno));
62
+ die_errno("git pack-objects failed");
63
64
/*
65
* We feed the pack-objects we just spawned with revision
builtin-tag.c
+3
-4
@@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,
308
path = git_pathdup("TAG_EDITMSG");
309
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
310
if (fd < 0)
311
- die("could not create file '%s': %s",
312
- path, strerror(errno));
311
+ die_errno("could not create file '%s'", path);
312
313
if (!is_null_sha1(prev))
314
write_tag_body(fd, prev);
@@ -446,8 +445,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
445
die("cannot read %s", msgfile);
446
} else {
447
if (strbuf_read_file(&buf, msgfile, 1024) < 0)
449
- die("could not open or read '%s': %s",
450
- msgfile, strerror(errno));
448
+ die_errno("could not open or read '%s'",
449
+ msgfile);
450
}
451
}
452
}
builtin-unpack-objects.c
+1
-1
@@ -68,7 +68,7 @@ static void *fill(int min)
68
if (ret <= 0) {
69
if (!ret)
70
die("early EOF");
71
- die("read error on input: %s", strerror(errno));
71
+ die_errno("read error on input");
72
}
73
len += ret;
74
} while (len < min);
csum-file.c
+2
-3
@@ -26,7 +26,7 @@ static void flush(struct sha1file *f, void * buf, unsigned int count)
26
}
27
if (!ret)
28
die("sha1 file '%s' write error. Out of diskspace", f->name);
29
- die("sha1 file '%s' write error (%s)", f->name, strerror(errno));
29
+ die_errno("sha1 file '%s' write error", f->name);
30
}
31
}
32
@@ -55,8 +55,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
55
if (flags & CSUM_FSYNC)
56
fsync_or_die(f->fd, f->name);
57
if (close(f->fd))
58
- die("%s: sha1 file error on close (%s)",
59
- f->name, strerror(errno));
58
+ die_errno("%s: sha1 file error on close", f->name);
59
fd = 0;
60
} else
61
fd = f->fd;
daemon.c
+7
-8
@@ -862,7 +862,7 @@ static int service_loop(int socknum, int *socklist)
862
case ECONNABORTED:
863
continue;
864
default:
865
- die("accept returned %s", strerror(errno));
865
+ die_errno("accept returned");
866
}
867
}
868
handle(incoming, (struct sockaddr *)&ss, sslen);
@@ -878,7 +878,7 @@ static void sanitize_stdfds(void)
878
while (fd != -1 && fd < 2)
879
fd = dup(fd);
880
if (fd == -1)
881
- die("open /dev/null or dup failed: %s", strerror(errno));
881
+ die_errno("open /dev/null or dup failed");
882
if (fd > 2)
883
close(fd);
884
}
@@ -889,12 +889,12 @@ static void daemonize(void)
889
case 0:
890
break;
891
case -1:
892
- die("fork failed: %s", strerror(errno));
892
+ die_errno("fork failed");
893
default:
894
exit(0);
895
}
896
if (setsid() == -1)
897
- die("setsid failed: %s", strerror(errno));
897
+ die_errno("setsid failed");
898
close(0);
899
close(1);
900
close(2);
@@ -905,9 +905,9 @@ static void store_pid(const char *path)
905
{
906
FILE *f = fopen(path, "w");
907
if (!f)
908
- die("cannot open pid file %s: %s", path, strerror(errno));
908
+ die_errno("cannot open pid file '%s'", path);
909
if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0)
910
- die("failed to write pid file %s: %s", path, strerror(errno));
910
+ die_errno("failed to write pid file '%s'", path);
911
}
912
913
static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
@@ -1107,8 +1107,7 @@ int main(int argc, char **argv)
1107
socklen_t slen = sizeof(ss);
1108
1109
if (!freopen("/dev/null", "w", stderr))
1110
- die("failed to redirect stderr to /dev/null: %s",
1111
- strerror(errno));
1110
+ die_errno("failed to redirect stderr to /dev/null");
1111
1112
if (getpeername(0, peer, &slen))
1113
peer = NULL;
diff.c
+2
-2
@@ -1975,7 +1975,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
1975
fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,
1976
strlen(base) + 1);
1977
if (fd < 0)
1978
- die("unable to create temp-file: %s", strerror(errno));
1978
+ die_errno("unable to create temp-file");
1979
if (convert_to_working_tree(path,
1980
(const char *)blob, (size_t)size, &buf)) {
1981
blob = buf.buf;
@@ -2021,7 +2021,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2021
if (lstat(name, &st) < 0) {
2022
if (errno == ENOENT)
2023
goto not_a_valid_file;
2024
- die("stat(%s): %s", name, strerror(errno));
2024
+ die_errno("stat(%s)", name);
2025
}
2026
if (S_ISLNK(st.st_mode)) {
2027
struct strbuf sb = STRBUF_INIT;
dir.c
+1
-1
@@ -759,7 +759,7 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
759
if (!dir)
760
return NULL;
761
if (!getcwd(buffer, size))
762
- die("can't find the current directory: %s", strerror(errno));
762
+ die_errno("can't find the current directory");
763
764
if (!is_absolute_path(dir))
765
dir = make_absolute_path(dir);
entry.c
+4
-4
@@ -51,7 +51,7 @@ static void remove_subtree(const char *path)
51
char *name;
52
53
if (!dir)
54
- die("cannot opendir %s (%s)", path, strerror(errno));
54
+ die_errno("cannot opendir '%s'", path);
55
strcpy(pathbuf, path);
56
name = pathbuf + strlen(path);
57
*name++ = '/';
@@ -61,15 +61,15 @@ static void remove_subtree(const char *path)
61
continue;
62
strcpy(name, de->d_name);
63
if (lstat(pathbuf, &st))
64
- die("cannot lstat %s (%s)", pathbuf, strerror(errno));
64
+ die_errno("cannot lstat '%s'", pathbuf);
65
if (S_ISDIR(st.st_mode))
66
remove_subtree(pathbuf);
67
else if (unlink(pathbuf))
68
- die("cannot unlink %s (%s)", pathbuf, strerror(errno));
68
+ die_errno("cannot unlink '%s'", pathbuf);
69
}
70
closedir(dir);
71
if (rmdir(path))
72
- die("cannot rmdir %s (%s)", path, strerror(errno));
72
+ die_errno("cannot rmdir '%s'", path);
73
}
74
75
static int create_file(const char *path, unsigned int mode)
fast-import.c
+2
-2
@@ -2342,7 +2342,7 @@ static void import_marks(const char *input_file)
2342
char line[512];
2343
FILE *f = fopen(input_file, "r");
2344
if (!f)
2345
- die("cannot read %s: %s", input_file, strerror(errno));
2345
+ die_errno("cannot read '%s'", input_file);
2346
while (fgets(line, sizeof(line), f)) {
2347
uintmax_t mark;
2348
char *end;
@@ -2448,7 +2448,7 @@ int main(int argc, const char **argv)
2448
fclose(pack_edges);
2449
pack_edges = fopen(a + 20, "a");
2450
if (!pack_edges)
2451
- die("Cannot open %s: %s", a + 20, strerror(errno));
2451
+ die_errno("Cannot open '%s'", a + 20);
2452
} else if (!strcmp(a, "--force"))
2453
force_update = 1;
2454
else if (!strcmp(a, "--quiet"))
git.c
+3
-3
@@ -200,7 +200,7 @@ static int handle_alias(int *argcp, const char ***argv)
200
}
201
202
if (subdir && chdir(subdir))
203
- die("Cannot change to %s: %s", subdir, strerror(errno));
203
+ die_errno("Cannot change to '%s'", subdir);
204
205
errno = saved_errno;
206
@@ -257,11 +257,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
257
258
/* Check for ENOSPC and EIO errors.. */
259
if (fflush(stdout))
260
- die("write failure on standard output: %s", strerror(errno));
260
+ die_errno("write failure on standard output");
261
if (ferror(stdout))
262
die("unknown write failure on standard output");
263
if (fclose(stdout))
264
- die("close failed on standard output: %s", strerror(errno));
264
+ die_errno("close failed on standard output");
265
return 0;
266
}
267
index-pack.c
+10
-11
@@ -143,7 +143,7 @@ static void *fill(int min)
143
if (ret <= 0) {
144
if (!ret)
145
die("early EOF");
146
- die("read error on input: %s", strerror(errno));
146
+ die_errno("read error on input");
147
}
148
input_len += ret;
149
if (from_stdin)
@@ -178,13 +178,12 @@ static char *open_pack_file(char *pack_name)
178
} else
179
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
180
if (output_fd < 0)
181
- die("unable to create %s: %s", pack_name, strerror(errno));
181
+ die_errno("unable to create '%s'", pack_name);
182
pack_fd = output_fd;
183
} else {
184
input_fd = open(pack_name, O_RDONLY);
185
if (input_fd < 0)
186
- die("cannot open packfile '%s': %s",
187
- pack_name, strerror(errno));
186
+ die_errno("cannot open packfile '%s'", pack_name);
187
output_fd = -1;
188
pack_fd = input_fd;
189
}
@@ -370,7 +369,7 @@ static void *get_data_from_pack(struct object_entry *obj)
369
do {
370
ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
371
if (n < 0)
373
- die("cannot pread pack file: %s", strerror(errno));
372
+ die_errno("cannot pread pack file");
373
if (!n)
374
die("premature end of pack file, %lu bytes missing",
375
len - rdy);
@@ -631,7 +630,7 @@ static void parse_pack_objects(unsigned char *sha1)
630
631
/* If input_fd is a file, we should have reached its end now. */
632
if (fstat(input_fd, &st))
634
- die("cannot fstat packfile: %s", strerror(errno));
633
+ die_errno("cannot fstat packfile");
634
if (S_ISREG(st.st_mode) &&
635
lseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size)
636
die("pack has junk at the end");
@@ -788,7 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
787
fsync_or_die(output_fd, curr_pack_name);
788
err = close(output_fd);
789
if (err)
791
- die("error while closing pack file: %s", strerror(errno));
790
+ die_errno("error while closing pack file");
791
}
792
793
if (keep_msg) {
@@ -801,16 +800,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
800
801
if (keep_fd < 0) {
802
if (errno != EEXIST)
804
- die("cannot write keep file '%s' (%s)",
805
- keep_name, strerror(errno));
803
+ die_errno("cannot write keep file '%s'",
804
+ keep_name);
805
} else {
806
if (keep_msg_len > 0) {
807
write_or_die(keep_fd, keep_msg, keep_msg_len);
808
write_or_die(keep_fd, "\n", 1);
809
}
810
if (close(keep_fd) != 0)
812
- die("cannot close written keep file '%s' (%s)",
813
- keep_name, strerror(errno));
811
+ die_errno("cannot close written keep file '%s'",
812
+ keep_name);
813
report = "keep";
814
}
815
}
merge-recursive.c
+3
-3
@@ -438,7 +438,7 @@ static void flush_buffer(int fd, const char *buf, unsigned long size)
438
/* Ignore epipe */
439
if (errno == EPIPE)
440
break;
441
- die("merge-recursive: %s", strerror(errno));
441
+ die_errno("merge-recursive");
442
} else if (!ret) {
443
die("merge-recursive: disk full?");
444
}
@@ -554,7 +554,7 @@ static void update_file_flags(struct merge_options *o,
554
mode = 0666;
555
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
556
if (fd < 0)
557
- die("failed to open %s: %s", path, strerror(errno));
557
+ die_errno("failed to open '%s'", path);
558
flush_buffer(fd, buf, size);
559
close(fd);
560
} else if (S_ISLNK(mode)) {
@@ -562,7 +562,7 @@ static void update_file_flags(struct merge_options *o,
562
safe_create_leading_directories_const(path);
563
unlink(path);
564
if (symlink(lnk, path))
565
- die("failed to symlink %s: %s", path, strerror(errno));
565
+ die_errno("failed to symlink '%s'", path);
566
free(lnk);
567
} else
568
die("do not know what to do with %06o %s '%s'",
pack-refs.c
+3
-4
@@ -93,8 +93,7 @@ int pack_refs(unsigned int flags)
93
LOCK_DIE_ON_ERROR);
94
cbdata.refs_file = fdopen(fd, "w");
95
if (!cbdata.refs_file)
96
- die("unable to create ref-pack file structure (%s)",
97
- strerror(errno));
96
+ die_errno("unable to create ref-pack file structure");
97
98
/* perhaps other traits later as well */
99
fprintf(cbdata.refs_file, "# pack-refs with: peeled \n");
@@ -103,7 +102,7 @@ int pack_refs(unsigned int flags)
102
if (ferror(cbdata.refs_file))
103
die("failed to write ref-pack file");
104
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))
106
- die("failed to write ref-pack file (%s)", strerror(errno));
105
+ die_errno("failed to write ref-pack file");
106
/*
107
* Since the lock file was fdopen()'ed and then fclose()'ed above,
108
* assign -1 to the lock file descriptor so that commit_lock_file()
@@ -111,7 +110,7 @@ int pack_refs(unsigned int flags)
110
*/
111
packed.fd = -1;
112
if (commit_lock_file(&packed) < 0)
114
- die("unable to overwrite old ref-pack file (%s)", strerror(errno));
113
+ die_errno("unable to overwrite old ref-pack file");
114
if (cbdata.flags & PACK_REFS_PRUNE)
115
prune_refs(cbdata.ref_to_prune);
116
return 0;
pack-write.c
+5
-5
@@ -51,7 +51,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
51
fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
52
}
53
if (fd < 0)
54
- die("unable to create %s: %s", index_name, strerror(errno));
54
+ die_errno("unable to create '%s'", index_name);
55
f = sha1fd(fd, index_name);
56
57
/* 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,
174
git_SHA1_Init(&new_sha1_ctx);
175
176
if (lseek(pack_fd, 0, SEEK_SET) != 0)
177
- die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
177
+ die_errno("Failed seeking to start of '%s'", pack_name);
178
if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
179
- die("Unable to reread header of %s: %s", pack_name, strerror(errno));
179
+ die_errno("Unable to reread header of '%s'", pack_name);
180
if (lseek(pack_fd, 0, SEEK_SET) != 0)
181
- die("Failed seeking to start of %s: %s", pack_name, strerror(errno));
181
+ die_errno("Failed seeking to start of '%s'", pack_name);
182
git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));
183
hdr.hdr_entries = htonl(object_count);
184
git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));
@@ -195,7 +195,7 @@ void fixup_pack_header_footer(int pack_fd,
195
if (!n)
196
break;
197
if (n < 0)
198
- die("Failed to checksum %s: %s", pack_name, strerror(errno));
198
+ die_errno("Failed to checksum '%s'", pack_name);
199
git_SHA1_Update(&new_sha1_ctx, buf, n);
200
201
aligned_sz -= n;
pkt-line.c
+2
-2
@@ -28,7 +28,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
28
}
29
if (!ret)
30
die("write error (disk full?)");
31
- die("write error (%s)", strerror(errno));
31
+ die_errno("write error");
32
}
33
return nn;
34
}
@@ -67,7 +67,7 @@ static void safe_read(int fd, void *buffer, unsigned size)
67
{
68
ssize_t ret = read_in_full(fd, buffer, size);
69
if (ret < 0)
70
- die("read error (%s)", strerror(errno));
70
+ die_errno("read error");
71
else if (ret < size)
72
die("The remote end hung up unexpectedly");
73
}
read-cache.c
+3
-3
@@ -638,7 +638,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
638
{
639
struct stat st;
640
if (lstat(path, &st))
641
- die("%s: unable to stat (%s)", path, strerror(errno));
641
+ die_errno("unable to stat '%s'", path);
642
return add_to_index(istate, path, &st, flags);
643
}
644
@@ -1251,11 +1251,11 @@ int read_index_from(struct index_state *istate, const char *path)
1251
if (fd < 0) {
1252
if (errno == ENOENT)
1253
return 0;
1254
- die("index file open failed (%s)", strerror(errno));
1254
+ die_errno("index file open failed");
1255
}
1256
1257
if (fstat(fd, &st))
1258
- die("cannot stat the open index (%s)", strerror(errno));
1258
+ die_errno("cannot stat the open index");
1259
1260
errno = EINVAL;
1261
mmap_size = xsize_t(st.st_size);
refs.c
+1
-1
@@ -1418,7 +1418,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1418
logfile = git_path("logs/%s", ref);
1419
logfd = open(logfile, O_RDONLY, 0);
1420
if (logfd < 0)
1421
- die("Unable to read log %s: %s", logfile, strerror(errno));
1421
+ die_errno("Unable to read log '%s'", logfile);
1422
fstat(logfd, &st);
1423
if (!st.st_size)
1424
die("Log %s is empty.", logfile);
run-command.c
+2
-2
@@ -101,8 +101,8 @@ int start_command(struct child_process *cmd)
101
}
102
103
if (cmd->dir && chdir(cmd->dir))
104
- die("exec %s: cd to %s failed (%s)", cmd->argv[0],
105
- cmd->dir, strerror(errno));
104
+ die_errno("exec '%s': cd to '%s' failed", cmd->argv[0],
105
+ cmd->dir);
106
if (cmd->env) {
107
for (; *cmd->env; cmd->env++) {
108
if (strchr(*cmd->env, '='))
setup.c
+4
-4
@@ -81,7 +81,7 @@ void verify_filename(const char *prefix, const char *arg)
81
if (errno == ENOENT)
82
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
83
"Use '--' to separate paths from revisions", arg);
84
- die("'%s': %s", arg, strerror(errno));
84
+ die_errno("failed to stat '%s'", arg);
85
}
86
87
/*
@@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg)
103
die("ambiguous argument '%s': both revision and filename\n"
104
"Use '--' to separate filenames from revisions", arg);
105
if (errno != ENOENT && errno != ENOTDIR)
106
- die("'%s': %s", arg, strerror(errno));
106
+ die_errno("failed to stat '%s'", arg);
107
}
108
109
const char **get_pathspec(const char *prefix, const char **pathspec)
@@ -257,7 +257,7 @@ const char *read_gitfile_gently(const char *path)
257
return NULL;
258
fd = open(path, O_RDONLY);
259
if (fd < 0)
260
- die("Error opening %s: %s", path, strerror(errno));
260
+ die_errno("Error opening '%s'", path);
261
buf = xmalloc(st.st_size + 1);
262
len = read_in_full(fd, buf, st.st_size);
263
close(fd);
@@ -389,7 +389,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
389
die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
390
}
391
if (chdir(".."))
392
- die("Cannot change to %s/..: %s", cwd, strerror(errno));
392
+ die_errno("Cannot change to '%s/..'", cwd);
393
}
394
395
inside_git_dir = 0;
sha1_file.c
+1
-1
@@ -2287,7 +2287,7 @@ static void close_sha1_file(int fd)
2287
if (fsync_object_files)
2288
fsync_or_die(fd, "sha1 file");
2289
if (close(fd) != 0)
2290
- die("error when closing sha1 file (%s)", strerror(errno));
2290
+ die_errno("error when closing sha1 file");
2291
}
2292
2293
/* Size of directory component, including the ending '/' */
shell.c
+1
-1
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
60
while (devnull_fd >= 0 && devnull_fd <= 2)
61
devnull_fd = dup(devnull_fd);
62
if (devnull_fd == -1)
63
- die("opening /dev/null failed (%s)", strerror(errno));
63
+ die_errno("opening /dev/null failed");
64
close (devnull_fd);
65
66
/*
test-sha1.c
+1
-1
@@ -32,7 +32,7 @@ int main(int ac, char **av)
32
if (sz == 0)
33
break;
34
if (sz < 0)
35
- die("test-sha1: %s", strerror(errno));
35
+ die_errno("test-sha1");
36
this_sz += sz;
37
cp += sz;
38
room -= sz;
wrapper.c
+4
-4
@@ -96,7 +96,7 @@ void *xmmap(void *start, size_t length,
96
release_pack_memory(length, fd);
97
ret = mmap(start, length, prot, flags, fd, offset);
98
if (ret == MAP_FAILED)
99
- die("Out of memory? mmap failed: %s", strerror(errno));
99
+ die_errno("Out of memory? mmap failed");
100
}
101
return ret;
102
}
@@ -175,7 +175,7 @@ int xdup(int fd)
175
{
176
int ret = dup(fd);
177
if (ret < 0)
178
- die("dup failed: %s", strerror(errno));
178
+ die_errno("dup failed");
179
return ret;
180
}
181
@@ -183,7 +183,7 @@ FILE *xfdopen(int fd, const char *mode)
183
{
184
FILE *stream = fdopen(fd, mode);
185
if (stream == NULL)
186
- die("Out of memory? fdopen failed: %s", strerror(errno));
186
+ die_errno("Out of memory? fdopen failed");
187
return stream;
188
}
189
@@ -193,7 +193,7 @@ int xmkstemp(char *template)
193
194
fd = mkstemp(template);
195
if (fd < 0)
196
- die("Unable to create temporary file: %s", strerror(errno));
196
+ die_errno("Unable to create temporary file");
197
return fd;
198
}
199
write_or_die.c
+3
-3
@@ -41,14 +41,14 @@ void maybe_flush_or_die(FILE *f, const char *desc)
41
*/
42
if (errno == EPIPE || errno == EINVAL)
43
exit(0);
44
- die("write failure on %s: %s", desc, strerror(errno));
44
+ die_errno("write failure on '%s'", desc);
45
}
46
}
47
48
void fsync_or_die(int fd, const char *msg)
49
{
50
if (fsync(fd) < 0) {
51
- die("%s: fsync error (%s)", msg, strerror(errno));
51
+ die_errno("fsync error on '%s'", msg);
52
}
53
}
54
@@ -57,7 +57,7 @@ void write_or_die(int fd, const void *buf, size_t count)
57
if (write_in_full(fd, buf, count) < 0) {
58
if (errno == EPIPE)
59
exit(0);
60
- die("write error (%s)", strerror(errno));
60
+ die_errno("write error");
61
}
62
}
63