import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / inet / getservent.c
blobe08a05b844e8bfc2831f5c84dddb555aff198202
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1986-1994,2001 by Sun Microsystems, Inc.
24 * All rights reserved.
26 * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
28 * lib/libsocket/inet/getservent.c
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <netdb.h>
34 #include <nss_dbdefs.h>
37 * Don't free this, even on an endservent(), because bitter experience shows
38 * that there's production code that does getXXXbyYYY(), then endXXXent(),
39 * and then continues to use the pointer it got back.
41 static nss_XbyY_buf_t *buffer;
42 #define GETBUF() \
43 NSS_XbyY_ALLOC(&buffer, (int)sizeof (struct servent), NSS_BUFLEN_SERVICES)
44 /* === ?? set ENOMEM on failure? */
46 struct servent *
47 getservbyname(const char *nam, const char *proto)
49 nss_XbyY_buf_t *b;
50 struct servent *res = 0;
52 if ((b = GETBUF()) != 0) {
53 res = getservbyname_r(nam, proto,
54 b->result, b->buffer, b->buflen);
56 return (res);
59 struct servent *
60 getservbyport(int port, const char *proto)
62 nss_XbyY_buf_t *b;
63 struct servent *res = 0;
65 if ((b = GETBUF()) != 0) {
66 res = getservbyport_r(port, proto,
67 b->result, b->buffer, b->buflen);
69 return (res);
72 struct servent *
73 getservent(void)
75 nss_XbyY_buf_t *b;
76 struct servent *res = 0;
78 if ((b = GETBUF()) != 0) {
79 res = getservent_r(b->result, b->buffer, b->buflen);
81 return (res);