xref: /dflybsd-src/lib/libc/gen/sysctlbyname.c (revision 00f0918d338a0f863b786ed4565f12971eaecdc8)
1984263bcSMatthew Dillon /*
2984263bcSMatthew Dillon  * ----------------------------------------------------------------------------
3984263bcSMatthew Dillon  * "THE BEER-WARE LICENSE" (Revision 42):
4984263bcSMatthew Dillon  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5984263bcSMatthew Dillon  * can do whatever you want with this stuff. If we meet some day, and you think
6984263bcSMatthew Dillon  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7984263bcSMatthew Dillon  * ----------------------------------------------------------------------------
8984263bcSMatthew Dillon  *
9*00f0918dSAlexandre Perrin  * $FreeBSD: head/lib/libc/gen/sysctlbyname.c 244153 2012-12-12 15:27:33Z pjd $
10984263bcSMatthew Dillon  *
11984263bcSMatthew Dillon  */
12984263bcSMatthew Dillon #include <sys/types.h>
13984263bcSMatthew Dillon #include <sys/sysctl.h>
14984263bcSMatthew Dillon 
15984263bcSMatthew Dillon int
sysctlbyname(const char * name,void * oldp,size_t * oldlenp,const void * newp,size_t newlen)16*00f0918dSAlexandre Perrin sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
17*00f0918dSAlexandre Perrin     const void *newp, size_t newlen)
18984263bcSMatthew Dillon {
19984263bcSMatthew Dillon 	int real_oid[CTL_MAXNAME+2];
20984263bcSMatthew Dillon 	size_t oidlen;
21984263bcSMatthew Dillon 
22*00f0918dSAlexandre Perrin 	oidlen = sizeof(real_oid) / sizeof(int);
23*00f0918dSAlexandre Perrin 	if (sysctlnametomib(name, real_oid, &oidlen) < 0)
24*00f0918dSAlexandre Perrin 		return (-1);
25*00f0918dSAlexandre Perrin 	return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
26984263bcSMatthew Dillon }
27