--- a/strbuf.c
+++ b/strbuf.c
@@ -472,6 +472,7 @@ int strbuf_getwholeline(struct strbuf *s
 	/* Translate slopbuf to NULL, as we cannot call realloc on it */
 	if (!sb->alloc)
 		sb->buf = NULL;
+	errno = 0;  /* reset since could have been set by some prev syscall */
 	r = getdelim(&sb->buf, &sb->alloc, term, fp);
 
 	if (r > 0) {
