xref: /netbsd-src/lib/libc/net/getservent.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: getservent.c,v 1.12 2008/04/28 20:23:00 martin Exp $	*/
2ef0582f1Scgd 
3ec210d4aSchristos /*-
4ec210d4aSchristos  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5ec210d4aSchristos  * All rights reserved.
6ec210d4aSchristos  *
7ec210d4aSchristos  * This code is derived from software contributed to The NetBSD Foundation
8ec210d4aSchristos  * by Christos Zoulas.
961f28255Scgd  *
1061f28255Scgd  * Redistribution and use in source and binary forms, with or without
1161f28255Scgd  * modification, are permitted provided that the following conditions
1261f28255Scgd  * are met:
1361f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1461f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1561f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1661f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1761f28255Scgd  *    documentation and/or other materials provided with the distribution.
1861f28255Scgd  *
19ec210d4aSchristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ec210d4aSchristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ec210d4aSchristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ec210d4aSchristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ec210d4aSchristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ec210d4aSchristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ec210d4aSchristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ec210d4aSchristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ec210d4aSchristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ec210d4aSchristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ec210d4aSchristos  * POSSIBILITY OF SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
328d36d340Schristos #include <sys/cdefs.h>
3361f28255Scgd #if defined(LIBC_SCCS) && !defined(lint)
34*ce099b40Smartin __RCSID("$NetBSD: getservent.c,v 1.12 2008/04/28 20:23:00 martin Exp $");
3561f28255Scgd #endif /* LIBC_SCCS and not lint */
3661f28255Scgd 
3743fa6fe3Sjtc #include "namespace.h"
38f38bfebbSmycroft #include "reentrant.h"
39f38bfebbSmycroft 
4061f28255Scgd #include <netdb.h>
4161f28255Scgd 
424e3cae58Skleink #include "servent.h"
434e3cae58Skleink 
4443fa6fe3Sjtc #ifdef __weak_alias
4560549036Smycroft __weak_alias(endservent,_endservent)
4660549036Smycroft __weak_alias(getservent,_getservent)
4760549036Smycroft __weak_alias(setservent,_setservent)
4843fa6fe3Sjtc #endif
4943fa6fe3Sjtc 
50f38bfebbSmycroft #ifdef _REENTRANT
51f38bfebbSmycroft mutex_t _servent_mutex = MUTEX_INITIALIZER;
52f38bfebbSmycroft #endif
53ec210d4aSchristos struct servent_data _servent_data;
5461f28255Scgd 
5561f28255Scgd void
setservent(int f)56ec210d4aSchristos setservent(int f)
5761f28255Scgd {
58f38bfebbSmycroft 	mutex_lock(&_servent_mutex);
59ec210d4aSchristos 	setservent_r(f, &_servent_data);
60f38bfebbSmycroft 	mutex_unlock(&_servent_mutex);
6161f28255Scgd }
6261f28255Scgd 
6361f28255Scgd void
endservent(void)64ec210d4aSchristos endservent(void)
6561f28255Scgd {
66f38bfebbSmycroft 	mutex_lock(&_servent_mutex);
67ec210d4aSchristos 	endservent_r(&_servent_data);
68f38bfebbSmycroft 	mutex_unlock(&_servent_mutex);
6961f28255Scgd }
7061f28255Scgd 
7161f28255Scgd struct servent *
getservent(void)72ec210d4aSchristos getservent(void)
7361f28255Scgd {
74f38bfebbSmycroft 	struct servent *s;
75f38bfebbSmycroft 
76f38bfebbSmycroft 	mutex_lock(&_servent_mutex);
77f38bfebbSmycroft 	s = getservent_r(&_servent_data.serv, &_servent_data);
78f38bfebbSmycroft 	mutex_unlock(&_servent_mutex);
79f38bfebbSmycroft 	return (s);
8061f28255Scgd }
81