summaryrefslogtreecommitdiff
path: root/libc/inet/getnetent.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/getnetent.c')
-rw-r--r--libc/inet/getnetent.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c
index d3fdb988a..d5c25034c 100644
--- a/libc/inet/getnetent.c
+++ b/libc/inet/getnetent.c
@@ -29,12 +29,8 @@ libc_hidden_proto(rewind)
libc_hidden_proto(fgets)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
@@ -50,13 +46,13 @@ int _net_stayopen attribute_hidden;
libc_hidden_proto(setnetent)
void setnetent(int f)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf == NULL)
netf = fopen(NETDB, "r" );
else
rewind(netf);
_net_stayopen |= f;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return;
}
libc_hidden_def(setnetent)
@@ -64,13 +60,13 @@ libc_hidden_def(setnetent)
libc_hidden_proto(endnetent)
void endnetent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf) {
fclose(netf);
netf = NULL;
}
_net_stayopen = 0;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(endnetent)
@@ -92,11 +88,11 @@ struct netent *getnetent(void)
{
char *p;
register char *cp, **q;
+ struct netent *rv = NULL;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
- UNLOCK;
- return (NULL);
+ goto DONE;
}
again:
@@ -108,8 +104,7 @@ again:
p = fgets(line, BUFSIZ, netf);
if (p == NULL) {
- UNLOCK;
- return (NULL);
+ goto DONE;
}
if (*p == '#')
goto again;
@@ -144,7 +139,9 @@ again:
*cp++ = '\0';
}
*q = NULL;
- UNLOCK;
- return (&net);
+ rv = &net;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return rv;
}
libc_hidden_def(getnetent)