diff options
Diffstat (limited to 'libc/pwd_grp/getspnam.c')
-rw-r--r-- | libc/pwd_grp/getspnam.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c index d8a29a8a2..9d578f09a 100644 --- a/libc/pwd_grp/getspnam.c +++ b/libc/pwd_grp/getspnam.c @@ -17,12 +17,23 @@ * */ +#include <features.h> #include <unistd.h> #include <string.h> #include <errno.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 getspnam_r (const char *name, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { @@ -51,9 +62,12 @@ struct spwd *getspnam(const char *name) static char line_buff[PWD_BUFFER_SIZE]; static struct spwd spwd; + LOCK; if (getspnam_r(name, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { + UNLOCK; return &spwd; } + UNLOCK; return NULL; } |