Skip to content

Commit

Permalink
pack-objects: be incredibly anal about stdio semantics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Apr 2, 2006
1 parent fb7a653 commit da93d12
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,11 +905,21 @@ int main(int argc, char **argv)
setup_progress_signal();
}

while (fgets(line, sizeof(line), stdin) != NULL) {
for (;;) {
unsigned int hash;
char *p;
unsigned char sha1[20];

if (!fgets(line, sizeof(line), stdin)) {
if (feof(stdin))
break;
if (!ferror(stdin))
die("fgets returned NULL, not EOF, not error!");
if (errno == EINTR)
continue;
die("fgets: %s", strerror(errno));
}

if (progress_update) {
fprintf(stderr, "Counting objects...%d\r", nr_objects);
progress_update = 0;
Expand Down

0 comments on commit da93d12

Please sign in to comment.