summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/getgrgid.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-08-18 18:50:52 +0000
committerEric Andersen <andersen@codepoet.org>2002-08-18 18:50:52 +0000
commit160212fe2d074af5bdc25b219e2276576f52b6e3 (patch)
treea18295e8f38e392f16191e4e8480a8caf25a66dc /libc/pwd_grp/getgrgid.c
parented43cbaf96c89d13675d2afeb8c73109982c64d9 (diff)
Yet more rework to make __getgrent and the functions that use it
reentrant... -Erik
Diffstat (limited to 'libc/pwd_grp/getgrgid.c')
-rw-r--r--libc/pwd_grp/getgrgid.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
index dc9176d39..5efca964a 100644
--- a/libc/pwd_grp/getgrgid.c
+++ b/libc/pwd_grp/getgrgid.c
@@ -24,6 +24,20 @@
#include <paths.h>
#include "config.h"
+
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+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 *getgrgid(const gid_t gid)
{
struct group *group;
@@ -32,13 +46,16 @@ struct group *getgrgid(const gid_t gid)
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 (group->gr_gid == gid) {
close(grp_fd);
+ UNLOCK;
return group;
}
close(grp_fd);
+ UNLOCK;
return NULL;
}