@matheusbsbs / matheus-bagliano / commits / da93d12b00
Fork 0

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>

Linus Torvalds committed Apr 2, 2006 at 13:31 UTC da93d12b00425a37e81e227671f13130efcfe93f
1 file changed +11 -1
pack-objects.c
+11 -1
@@ -905,11 +905,21 @@ int main(int argc, char **argv)
905 setup_progress_signal();
906 }
907
908 - while (fgets(line, sizeof(line), stdin) != NULL) {
908 + for (;;) {
909 unsigned int hash;
910 char *p;
911 unsigned char sha1[20];
912
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 +
923 if (progress_update) {
924 fprintf(stderr, "Counting objects...%d\r", nr_objects);
925 progress_update = 0;