xref: /netbsd-src/lib/libc/gen/sysctlbyname.c (revision 0c0346ae4894710158fc5de26c0574cb5571d112)
1*0c0346aeSpooka /*	$NetBSD: sysctlbyname.c,v 1.7 2010/12/13 23:10:13 pooka Exp $ */
229e15c79Satatat 
329e15c79Satatat /*-
429e15c79Satatat  * Copyright (c) 2003,2004 The NetBSD Foundation, Inc.
529e15c79Satatat  *	All rights reserved.
629e15c79Satatat  *
729e15c79Satatat  * This code is derived from software contributed to The NetBSD Foundation
829e15c79Satatat  * by Andrew Brown.
929e15c79Satatat  *
1029e15c79Satatat  * Redistribution and use in source and binary forms, with or without
1129e15c79Satatat  * modification, are permitted provided that the following conditions
1229e15c79Satatat  * are met:
1329e15c79Satatat  * 1. Redistributions of source code must retain the above copyright
1429e15c79Satatat  *    notice, this list of conditions and the following disclaimer.
1529e15c79Satatat  * 2. Redistributions in binary form must reproduce the above copyright
1629e15c79Satatat  *    notice, this list of conditions and the following disclaimer in the
1729e15c79Satatat  *    documentation and/or other materials provided with the distribution.
1829e15c79Satatat  *
1929e15c79Satatat  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2029e15c79Satatat  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2129e15c79Satatat  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2229e15c79Satatat  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2329e15c79Satatat  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2429e15c79Satatat  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2529e15c79Satatat  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2629e15c79Satatat  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2729e15c79Satatat  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2829e15c79Satatat  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929e15c79Satatat  * POSSIBILITY OF SUCH DAMAGE.
3029e15c79Satatat  */
3129e15c79Satatat 
3288c3eadbSlukem #include <sys/cdefs.h>
3388c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
34*0c0346aeSpooka __RCSID("$NetBSD: sysctlbyname.c,v 1.7 2010/12/13 23:10:13 pooka Exp $");
3588c3eadbSlukem #endif /* LIBC_SCCS and not lint */
3688c3eadbSlukem 
372f36209cSpooka #ifndef RUMP_ACTION
388d5507a1Satatat #include "namespace.h"
392f36209cSpooka #endif
4029e15c79Satatat #include <sys/param.h>
4129e15c79Satatat #include <sys/sysctl.h>
4229e15c79Satatat 
432f36209cSpooka #ifdef RUMP_ACTION
442f36209cSpooka #include <rump/rump_syscalls.h>
452f36209cSpooka #define sysctl(a,b,c,d,e,f) rump_sys___sysctl(a,b,c,d,e,f)
46*0c0346aeSpooka #else
47*0c0346aeSpooka #ifdef __weak_alias
__weak_alias(sysctlbyname,_sysctlbyname)48*0c0346aeSpooka __weak_alias(sysctlbyname,_sysctlbyname)
49*0c0346aeSpooka #endif
502f36209cSpooka #endif
512f36209cSpooka 
5229e15c79Satatat /*
5329e15c79Satatat  * trivial sysctlbyname() function for the "lazy".
5429e15c79Satatat  */
5529e15c79Satatat int
562f42139cSalc sysctlbyname(const char *gname, void *oldp, size_t *oldlenp,
572f42139cSalc 	     const void *newp, size_t newlen)
5829e15c79Satatat {
5929e15c79Satatat 	int name[CTL_MAXNAME], rc;
6029e15c79Satatat 	u_int namelen;
6129e15c79Satatat 
6229e15c79Satatat 	rc = sysctlgetmibinfo(gname, &name[0], &namelen, NULL, NULL, NULL,
6329e15c79Satatat 			      SYSCTL_VERSION);
6429e15c79Satatat 	if (rc == 0)
6529e15c79Satatat 		rc = sysctl(&name[0], namelen, oldp, oldlenp, newp, newlen);
6629e15c79Satatat 	return (rc);
6729e15c79Satatat }
68