summaryrefslogtreecommitdiff
path: root/pack-objects.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2006-04-02 20:31:54 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-04-02 20:46:27 (GMT)
commitda93d12b00425a37e81e227671f13130efcfe93f (patch)
tree84aba76a2bdd6dfa786438de0d7b3beb2462f1ba /pack-objects.c
parentfb7a6531e67333b22967bf5b96ef22a28f3b2552 (diff)
downloadgit-da93d12b00425a37e81e227671f13130efcfe93f.zip
git-da93d12b00425a37e81e227671f13130efcfe93f.tar.gz
git-da93d12b00425a37e81e227671f13130efcfe93f.tar.bz2
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>
Diffstat (limited to 'pack-objects.c')
-rw-r--r--pack-objects.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/pack-objects.c b/pack-objects.c
index cde4afa..084c200 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -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;