fast-import: Don't use a maybe-clobbered errno value
Without this change, each diagnostic could use an errno value clobbered by the close or unlink in rollback_lock_file. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jim Meyering committed
Jan 18, 2008 at 19:35 UTC
5a7b1b571e2bf59c65f9e5333414d2e0f7df6952
1 file changed
+6
-3
fast-import.c
+6
-3
@@ -1541,9 +1541,10 @@ static void dump_marks(void)
1541
1542
f = fdopen(mark_fd, "w");
1543
if (!f) {
1544
+ int saved_errno = errno;
1545
rollback_lock_file(&mark_lock);
1546
failure |= error("Unable to write marks file %s: %s",
1546
- mark_file, strerror(errno));
1547
+ mark_file, strerror(saved_errno));
1548
return;
1549
}
1550
@@ -1556,16 +1557,18 @@ static void dump_marks(void)
1557
1558
dump_marks_helper(f, 0, marks);
1559
if (ferror(f) || fclose(f)) {
1560
+ int saved_errno = errno;
1561
rollback_lock_file(&mark_lock);
1562
failure |= error("Unable to write marks file %s: %s",
1561
- mark_file, strerror(errno));
1563
+ mark_file, strerror(saved_errno));
1564
return;
1565
}
1566
1567
if (commit_lock_file(&mark_lock)) {
1568
+ int saved_errno = errno;
1569
rollback_lock_file(&mark_lock);
1570
failure |= error("Unable to commit marks file %s: %s",
1568
- mark_file, strerror(errno));
1571
+ mark_file, strerror(saved_errno));
1572
return;
1573
}
1574
}