소스 검색

add fgetgrent function

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.
Rich Felker 12 년 전
부모
커밋
cac872957e
2개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      include/grp.h
  2. 9 0
      src/passwd/fgetgrent.c

+ 4 - 0
include/grp.h

@@ -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 *);

+ 9 - 0
src/passwd/fgetgrent.c

@@ -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);
+}