diff options
Diffstat (limited to 'libc/pwd_grp/getpwuid.c')
-rw-r--r-- | libc/pwd_grp/getpwuid.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c index ff3637abe..48ee6123d 100644 --- a/libc/pwd_grp/getpwuid.c +++ b/libc/pwd_grp/getpwuid.c @@ -18,12 +18,23 @@ * */ +#include <features.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #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 getpwuid_r (uid_t uid, struct passwd *password, char *buff, size_t buflen, struct passwd **crap) { @@ -48,9 +59,12 @@ struct passwd *getpwuid(uid_t uid) static char line_buff[PWD_BUFFER_SIZE]; static struct passwd pwd; + LOCK; if (getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL) != -1) { + UNLOCK; return &pwd; } + UNLOCK; return NULL; } |