summaryrefslogtreecommitdiff
path: root/lib/libc/net/getservbyname.c
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:19:02 +0000
committerDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:19:02 +0000
commitf547068f88348f54941dc06da46491f99701933e (patch)
tree8548a6b78719cba1de575b7f49e5f8ac4e6f1683 /lib/libc/net/getservbyname.c
parent394c7a9821726b84f284c0c4385b1a9198afa0b0 (diff)
Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10) (more md stuff is needed for other libc/arch/*) (setlogin is no longer a special syscall) Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS). Doc some re-entrant routines Add libc_r to intro(3) dig() uses some libc srcs and an extra -I was needed there. Add more md stuff to libc_r. Update includes for the pthreads api Update libc_r TODO
Diffstat (limited to 'lib/libc/net/getservbyname.c')
-rw-r--r--lib/libc/net/getservbyname.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/libc/net/getservbyname.c b/lib/libc/net/getservbyname.c
index 25f0e27d06a..7375c894042 100644
--- a/lib/libc/net/getservbyname.c
+++ b/lib/libc/net/getservbyname.c
@@ -32,21 +32,28 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.3 1997/07/09 01:08:34 millert Exp $";
+static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.4 1998/11/20 11:18:44 d Exp $";
#endif /* LIBC_SCCS and not lint */
#include <netdb.h>
#include <string.h>
+#include "thread_private.h"
extern int _serv_stayopen;
+_THREAD_PRIVATE_MUTEX(getservbyname_r)
+
struct servent *
-getservbyname(name, proto)
+getservbyname_r(name, proto, se, buf, buflen)
const char *name, *proto;
+ struct servent *se;
+ char *buf;
+ int buflen;
{
register struct servent *p;
register char **cp;
+ _THREAD_PRIVATE_MUTEX_LOCK(getservbyname_r);
setservent(_serv_stayopen);
while ((p = getservent())) {
if (strcmp(name, p->s_name) == 0)
@@ -61,5 +68,20 @@ gotname:
}
if (!_serv_stayopen)
endservent();
+ _THREAD_PRIVATE_MUTEX_UNLOCK(getservbyname_r);
return (p);
}
+
+struct servent *getservbyname(name, proto)
+ const char *name, *proto;
+{
+ _THREAD_PRIVATE_KEY(getservbyname)
+ static char buf[4096];
+ char *bufp = (char*)_THREAD_PRIVATE(getservbyname, buf, NULL);
+
+ if (bufp == NULL)
+ return (NULL);
+ return getservbyname_r(name, proto, (struct servent*) bufp,
+ bufp + sizeof(struct servent),
+ sizeof buf - sizeof(struct servent) );
+}