detect close failure on just-written file handles

I audited git for potential undetected write failures.
In the cases fixed below, the diagnostics I add mimic the diagnostics
used in surrounding code, even when that means not reporting
the precise strerror(errno) cause of the error.

Signed-off-by: Jim Meyering <jim@meyering.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/index-pack.c b/index-pack.c
index 82c8da3..8403c36 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -634,7 +634,8 @@
 				write_or_die(keep_fd, keep_msg, keep_msg_len);
 				write_or_die(keep_fd, "\n", 1);
 			}
-			close(keep_fd);
+			if (close(keep_fd) != 0)
+				die("cannot write keep file");
 			report = "keep";
 		}
 	}