about summary refs log tree commit diff
path: root/src/passwd/getgrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwd/getgrent.c')
-rw-r--r--src/passwd/getgrent.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/passwd/getgrent.c b/src/passwd/getgrent.c
index 429a3e58..835b9ab5 100644
--- a/src/passwd/getgrent.c
+++ b/src/passwd/getgrent.c
@@ -1,6 +1,8 @@
 #include "pwf.h"
 
 static FILE *f;
+static char *line, **mem;
+static struct group gr;
 
 void setgrent()
 {
@@ -12,34 +14,26 @@ weak_alias(setgrent, endgrent);
 
 struct group *getgrent()
 {
-	static char *line, **mem;
-	static struct group gr;
+	struct group *res;
 	size_t size=0, nmem=0;
 	if (!f) f = fopen("/etc/group", "rbe");
 	if (!f) return 0;
-	return __getgrent_a(f, &gr, &line, &size, &mem, &nmem);
+	__getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res);
+	return res;
 }
 
 struct group *getgrgid(gid_t gid)
 {
-	struct group *gr;
-	int errno_saved;
-	setgrent();
-	while ((gr=getgrent()) && gr->gr_gid != gid);
-	errno_saved = errno;
-	endgrent();
-	errno = errno_saved;
-	return gr;
+	struct group *res;
+	size_t size=0, nmem=0;
+	__getgr_a(0, gid, &gr, &line, &size, &mem, &nmem, &res);
+	return res;
 }
 
 struct group *getgrnam(const char *name)
 {
-	struct group *gr;
-	int errno_saved;
-	setgrent();
-	while ((gr=getgrent()) && strcmp(gr->gr_name, name));
-	errno_saved = errno;
-	endgrent();
-	errno = errno_saved;
-	return gr;
+	struct group *res;
+	size_t size=0, nmem=0;
+	__getgr_a(name, 0, &gr, &line, &size, &mem, &nmem, &res);
+	return res;
 }