Skip to content

Commit da93d12

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
pack-objects: be incredibly anal about stdio semantics
This is the "letter of the law" version of using fgets() properly in the face of incredibly broken stdio implementations. We can work around the Solaris breakage with SA_RESTART, but in case anybody else is ever that stupid, here's the "safe" (read: "insanely anal") way to use fgets. It probably goes without saying that I'm not terribly impressed by Solaris libc. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent fb7a653 commit da93d12

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pack-objects.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,21 @@ int main(int argc, char **argv)
905905
setup_progress_signal();
906906
}
907907

908-
while (fgets(line, sizeof(line), stdin) != NULL) {
908+
for (;;) {
909909
unsigned int hash;
910910
char *p;
911911
unsigned char sha1[20];
912912

913+
if (!fgets(line, sizeof(line), stdin)) {
914+
if (feof(stdin))
915+
break;
916+
if (!ferror(stdin))
917+
die("fgets returned NULL, not EOF, not error!");
918+
if (errno == EINTR)
919+
continue;
920+
die("fgets: %s", strerror(errno));
921+
}
922+
913923
if (progress_update) {
914924
fprintf(stderr, "Counting objects...%d\r", nr_objects);
915925
progress_update = 0;

0 commit comments

Comments
 (0)