summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getservbyname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getservbyname.c')
-rw-r--r--src/lib/libc/net/getservbyname.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c
index b4a6311966..f1c312ea82 100644
--- a/src/lib/libc/net/getservbyname.c
+++ b/src/lib/libc/net/getservbyname.c
@@ -1,5 +1,3 @@
1/* $NetBSD: getservbyname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $ */
2
3/* 1/*
4 * Copyright (c) 1983, 1993 2 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 3 * The Regents of the University of California. All rights reserved.
@@ -12,11 +10,7 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 13 * 3. Neither the name of the University nor the names of its contributors
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software 14 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 15 * without specific prior written permission.
22 * 16 *
@@ -34,27 +28,30 @@
34 */ 28 */
35 29
36#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
37#if 0 31static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.6 2003/06/02 20:18:35 millert Exp $";
38static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93";
39#else
40static char rcsid[] = "$NetBSD: getservbyname.c,v 1.4 1995/02/25 06:20:36 cgd Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
43 33
44#include <netdb.h> 34#include <netdb.h>
45#include <string.h> 35#include <string.h>
36#include "thread_private.h"
46 37
47extern int _serv_stayopen; 38extern int _serv_stayopen;
48 39
40_THREAD_PRIVATE_MUTEX(getservbyname_r);
41
49struct servent * 42struct servent *
50getservbyname(name, proto) 43getservbyname_r(name, proto, se, buf, buflen)
51 const char *name, *proto; 44 const char *name, *proto;
45 struct servent *se;
46 char *buf;
47 int buflen;
52{ 48{
53 register struct servent *p; 49 register struct servent *p;
54 register char **cp; 50 register char **cp;
55 51
52 _THREAD_PRIVATE_MUTEX_LOCK(getservbyname_r);
56 setservent(_serv_stayopen); 53 setservent(_serv_stayopen);
57 while (p = getservent()) { 54 while ((p = getservent())) {
58 if (strcmp(name, p->s_name) == 0) 55 if (strcmp(name, p->s_name) == 0)
59 goto gotname; 56 goto gotname;
60 for (cp = p->s_aliases; *cp; cp++) 57 for (cp = p->s_aliases; *cp; cp++)
@@ -67,5 +64,20 @@ gotname:
67 } 64 }
68 if (!_serv_stayopen) 65 if (!_serv_stayopen)
69 endservent(); 66 endservent();
67 _THREAD_PRIVATE_MUTEX_UNLOCK(getservbyname_r);
70 return (p); 68 return (p);
71} 69}
70
71struct servent *getservbyname(name, proto)
72 const char *name, *proto;
73{
74 _THREAD_PRIVATE_KEY(getservbyname);
75 static char buf[4096];
76 char *bufp = (char*)_THREAD_PRIVATE(getservbyname, buf, NULL);
77
78 if (bufp == NULL)
79 return (NULL);
80 return getservbyname_r(name, proto, (struct servent*) bufp,
81 bufp + sizeof(struct servent),
82 sizeof buf - sizeof(struct servent) );
83}