make passwd/group functions safe against cancellation in stdio

these changes are a prerequisite to making stdio cancellable.
diff --git a/src/passwd/getpw_r.c b/src/passwd/getpw_r.c
index 7b331e8..3974495 100644
--- a/src/passwd/getpw_r.c
+++ b/src/passwd/getpw_r.c
@@ -1,4 +1,5 @@
 #include "pwf.h"
+#include <pthread.h>
 
 #define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf)
 
@@ -8,9 +9,15 @@
 	char *line = 0;
 	size_t len = 0;
 	int rv = 0;
+	int cs;
+
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
 
 	f = fopen("/etc/passwd", "rb");
-	if (!f) return errno;
+	if (!f) {
+		rv = errno;
+		goto done;
+	}
 
 	*res = 0;
 	while (__getpwent_a(f, pw, &line, &len)) {
@@ -32,6 +39,8 @@
 	}
  	free(line);
 	fclose(f);
+done:
+	pthread_setcancelstate(cs, 0);
 	return rv;
 }