summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/getpwnam.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp/getpwnam.c')
-rw-r--r--libc/pwd_grp/getpwnam.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
index b0674b15d..00adb57ca 100644
--- a/libc/pwd_grp/getpwnam.c
+++ b/libc/pwd_grp/getpwnam.c
@@ -18,6 +18,7 @@
*
*/
+#include <features.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -25,6 +26,16 @@
#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
+
int getpwnam_r (const char *name, struct passwd *password,
char *buff, size_t buflen, struct passwd **crap)
{
@@ -53,9 +64,12 @@ struct passwd *getpwnam(const char *name)
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
+ LOCK;
if (getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ UNLOCK;
return &pwd;
}
+ UNLOCK;
return NULL;
}