From 160212fe2d074af5bdc25b219e2276576f52b6e3 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sun, 18 Aug 2002 18:50:52 +0000 Subject: Yet more rework to make __getgrent and the functions that use it reentrant... -Erik --- libc/pwd_grp/getgrnam.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libc/pwd_grp/getgrnam.c') diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c index f33462498..10302aab2 100644 --- a/libc/pwd_grp/getgrnam.c +++ b/libc/pwd_grp/getgrnam.c @@ -25,6 +25,19 @@ #include #include "config.h" +#ifdef __UCLIBC_HAS_THREADS__ +#include +static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; +# define LOCK pthread_mutex_lock(&mylock) +# define UNLOCK pthread_mutex_unlock(&mylock); +#else +# define LOCK +# define UNLOCK +#endif +static char *line_buff = NULL; +static char **members = NULL; + + struct group *getgrnam(const char *name) { int grp_fd; @@ -38,12 +51,15 @@ struct group *getgrnam(const char *name) if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0) return NULL; - while ((group = __getgrent(grp_fd)) != NULL) + LOCK; + while ((group = __getgrent(grp_fd, line_buff, members)) != NULL) if (!strcmp(group->gr_name, name)) { close(grp_fd); + UNLOCK; return group; } close(grp_fd); + UNLOCK; return NULL; } -- cgit v1.2.3