summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/getspuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp/getspuid.c')
-rw-r--r--libc/pwd_grp/getspuid.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/pwd_grp/getspuid.c b/libc/pwd_grp/getspuid.c
index f06eb1ad0..d57b2aa0b 100644
--- a/libc/pwd_grp/getspuid.c
+++ b/libc/pwd_grp/getspuid.c
@@ -17,11 +17,22 @@
*
*/
+#include <features.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.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 getspuid_r (uid_t uid, struct spwd *spwd,
char *buff, size_t buflen, struct spwd **crap)
{
@@ -39,9 +50,12 @@ struct spwd *getspuid(uid_t uid)
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
+ LOCK;
if (getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ UNLOCK;
return &spwd;
}
+ UNLOCK;
return NULL;
}