getservbyport_r: fix wrong result if getnameinfo fails with EAI_OVERFLOW
[musl] / src / passwd / fgetspent.c
index a9a3c97..47473bd 100644 (file)
@@ -1,11 +1,15 @@
 #include "pwf.h"
+#include <pthread.h>
 
 struct spwd *fgetspent(FILE *f)
 {
-       return 0;
-}
-
-int putspent(const struct spwd *sp, FILE *f)
-{
-       return -1;
+       static char *line;
+       static struct spwd sp;
+       size_t size = 0;
+       struct spwd *res = 0;
+       int cs;
+       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+       if (getline(&line, &size, f) >= 0 && __parsespent(line, &sp) >= 0) res = &sp;
+       pthread_setcancelstate(cs, 0);
+       return res;
 }