summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/fgetpwent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-08-08 07:28:33 +0000
committerEric Andersen <andersen@codepoet.org>2002-08-08 07:28:33 +0000
commitf6cfb61578920a2aba19afbf320e007efd863730 (patch)
treeccb2c728bbc974843bcdcad15be710ca0fdc432c /libc/pwd_grp/fgetpwent.c
parent82dc33223c219e05fe2637f675e11cd85438f7be (diff)
Fix locking
-Erik
Diffstat (limited to 'libc/pwd_grp/fgetpwent.c')
-rw-r--r--libc/pwd_grp/fgetpwent.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c
index e025cf6cc..5ca08d3b0 100644
--- a/libc/pwd_grp/fgetpwent.c
+++ b/libc/pwd_grp/fgetpwent.c
@@ -18,10 +18,21 @@
*
*/
+#include <features.h>
#include <errno.h>
#include <stdio.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
+
int fgetpwent_r (FILE *file, struct passwd *password,
char *buff, size_t buflen, struct passwd **crap)
{
@@ -37,8 +48,11 @@ struct passwd *fgetpwent(FILE * file)
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
+ LOCK;
if (fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ UNLOCK;
return &pwd;
}
+ UNLOCK;
return NULL;
}