summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getprotoname.c
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2005-04-19 14:41:13 +0000
committerume <ume@FreeBSD.org>2005-04-19 14:41:13 +0000
commit9af2b4271232977fe523e77ee8fd7b200a23e98f (patch)
tree0e2d39bbb214743f8707b7ef40ff135b1ee0fa32 /lib/libc/net/getprotoname.c
parent6c9d475a3bb8332173bada9cd081a2aa96c32b1a (diff)
downloadFreeBSD-src-9af2b4271232977fe523e77ee8fd7b200a23e98f.zip
FreeBSD-src-9af2b4271232977fe523e77ee8fd7b200a23e98f.tar.gz
- add getproto{byname,bynumber,ent}_r for internal use within libc.
- make getproto{byname,bynumber,ent} thread-safe.
Diffstat (limited to 'lib/libc/net/getprotoname.c')
-rw-r--r--lib/libc/net/getprotoname.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/libc/net/getprotoname.c b/lib/libc/net/getprotoname.c
index 7039b0a..99232a2 100644
--- a/lib/libc/net/getprotoname.c
+++ b/lib/libc/net/getprotoname.c
@@ -39,26 +39,37 @@ __FBSDID("$FreeBSD$");
#include <netdb.h>
#include <string.h>
+#include "netdb_private.h"
-extern int _proto_stayopen;
-
-struct protoent *
-getprotobyname(name)
- const char *name;
+int
+getprotobyname_r(const char *name, struct protoent *pe,
+ struct protoent_data *ped)
{
- struct protoent *p;
char **cp;
+ int error;
- setprotoent(_proto_stayopen);
- while ( (p = getprotoent()) ) {
- if (strcmp(p->p_name, name) == 0)
+ setprotoent_r(ped->stayopen, ped);
+ while ((error = getprotoent_r(pe, ped)) == 0) {
+ if (strcmp(pe->p_name, name) == 0)
break;
- for (cp = p->p_aliases; *cp != 0; cp++)
+ for (cp = pe->p_aliases; *cp != 0; cp++)
if (strcmp(*cp, name) == 0)
goto found;
}
found:
- if (!_proto_stayopen)
- endprotoent();
- return (p);
+ if (!ped->stayopen)
+ endprotoent_r(ped);
+ return (error);
+}
+
+struct protoent *
+getprotobyname(const char *name)
+{
+ struct protodata *pd;
+
+ if ((pd = __protodata_init()) == NULL)
+ return (NULL);
+ if (getprotobyname_r(name, &pd->proto, &pd->data) != 0)
+ return (NULL);
+ return (&pd->proto);
}
OpenPOWER on IntegriCloud