add fgetgrent function
authorRich Felker <dalias@aerifal.cx>
Sun, 17 Feb 2013 18:21:56 +0000 (13:21 -0500)
committerRich Felker <dalias@aerifal.cx>
Sun, 17 Feb 2013 18:21:56 +0000 (13:21 -0500)
based on patch by Isaac Dunham, moved to its own file to avoid
increasing bss on static linked programs not using this nonstandard
function but using the standard getgrent function, and vice versa.

include/grp.h
src/passwd/fgetgrent.c [new file with mode: 0644]

index 030d7f8..cb40e07 100644 (file)
@@ -30,6 +30,10 @@ struct group  *getgrent(void);
 void           endgrent(void);
 void           setgrent(void);
 
+#ifdef _GNU_SOURCE
+struct group  *fgetgrent(FILE *stream);
+#endif
+
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int getgrouplist(const char *, gid_t, gid_t *, int *);
 int setgroups(size_t, const gid_t *);
diff --git a/src/passwd/fgetgrent.c b/src/passwd/fgetgrent.c
new file mode 100644 (file)
index 0000000..2f18d92
--- /dev/null
@@ -0,0 +1,9 @@
+#include "pwf.h"
+
+struct group *fgetgrent(FILE *f)
+{
+       static char *line, **mem;
+       static struct group gr;
+       size_t size=0, nmem=0;
+       return __getgrent_a(f, &gr, &line, &size, &mem, &nmem);
+}