xref: /netbsd-src/lib/libc/net/getprotoent.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: getprotoent.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  */
318d36d340Schristos #include <sys/cdefs.h>
32ec210d4aSchristos 
3361f28255Scgd #if defined(LIBC_SCCS) && !defined(lint)
34*ce099b40Smartin __RCSID("$NetBSD: getprotoent.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 "protoent.h"
434e3cae58Skleink 
4443fa6fe3Sjtc #ifdef __weak_alias
4560549036Smycroft __weak_alias(endprotoent,_endprotoent)
4660549036Smycroft __weak_alias(getprotoent,_getprotoent)
4760549036Smycroft __weak_alias(setprotoent,_setprotoent)
4843fa6fe3Sjtc #endif
4943fa6fe3Sjtc 
50f38bfebbSmycroft #ifdef _REENTRANT
51f38bfebbSmycroft mutex_t _protoent_mutex = MUTEX_INITIALIZER;
52f38bfebbSmycroft #endif
53ec210d4aSchristos struct protoent_data _protoent_data;
5461f28255Scgd 
5561f28255Scgd void
setprotoent(int f)56ec210d4aSchristos setprotoent(int f)
5761f28255Scgd {
58f38bfebbSmycroft 	mutex_lock(&_protoent_mutex);
59ec210d4aSchristos 	setprotoent_r(f, &_protoent_data);
60f38bfebbSmycroft 	mutex_unlock(&_protoent_mutex);
6161f28255Scgd }
6261f28255Scgd 
6361f28255Scgd void
endprotoent(void)64ec210d4aSchristos endprotoent(void)
6561f28255Scgd {
66f38bfebbSmycroft 	mutex_lock(&_protoent_mutex);
67ec210d4aSchristos 	endprotoent_r(&_protoent_data);
68f38bfebbSmycroft 	mutex_unlock(&_protoent_mutex);
6961f28255Scgd }
7061f28255Scgd 
7161f28255Scgd struct protoent *
getprotoent(void)72ec210d4aSchristos getprotoent(void)
7361f28255Scgd {
74f38bfebbSmycroft 	struct protoent *p;
75f38bfebbSmycroft 
76f38bfebbSmycroft 	mutex_lock(&_protoent_mutex);
77f38bfebbSmycroft 	p = getprotoent_r(&_protoent_data.proto, &_protoent_data);
78f38bfebbSmycroft 	mutex_unlock(&_protoent_mutex);
79f38bfebbSmycroft 	return (p);
8061f28255Scgd }
81