summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/fgetspent.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp/fgetspent.c')
-rw-r--r--libc/pwd_grp/fgetspent.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c
index 68053b39e..20698da1b 100644
--- a/libc/pwd_grp/fgetspent.c
+++ b/libc/pwd_grp/fgetspent.c
@@ -17,27 +17,41 @@
*
*/
+#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 fgetspent_r (FILE *file, struct spwd *spwd,
char *buff, size_t buflen, struct spwd **crap)
{
- if (file == NULL) {
- __set_errno(EINTR);
- return -1;
- }
- return(__getspent_r(spwd, buff, buflen, fileno(file)));
+ if (file == NULL) {
+ __set_errno(EINTR);
+ return -1;
+ }
+ return(__getspent_r(spwd, buff, buflen, fileno(file)));
}
struct spwd *fgetspent(FILE * file)
{
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
+ static char line_buff[PWD_BUFFER_SIZE];
+ static struct spwd spwd;
- if (fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
- return &spwd;
- }
- return NULL;
+ LOCK;
+ if (fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ UNLOCK;
+ return &spwd;
+ }
+ UNLOCK;
+ return NULL;
}