diff options
author | phk <phk@FreeBSD.org> | 1997-05-30 20:53:13 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1997-05-30 20:53:13 +0000 |
commit | 452665122f83327067d7bc2e9a2534f441170acf (patch) | |
tree | cf07565918b931095fa2c0fd2bed51f9abe831ec /lib/libc/gen/sysctlbyname.c | |
parent | 51cf1d5bbcad7d42aa7e5c3e2585826a5c49b4d1 (diff) | |
download | FreeBSD-src-452665122f83327067d7bc2e9a2534f441170acf.zip FreeBSD-src-452665122f83327067d7bc2e9a2534f441170acf.tar.gz |
sysctlbyname allows acces to sysctl variables by name.
The manpage has been sent to linquistic decontamination and will arrive
when released from the quarantine
Reviewed by: peter
Diffstat (limited to 'lib/libc/gen/sysctlbyname.c')
-rw-r--r-- | lib/libc/gen/sysctlbyname.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c new file mode 100644 index 0000000..a3133af --- /dev/null +++ b/lib/libc/gen/sysctlbyname.c @@ -0,0 +1,33 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $Id$ + * + */ +#include <sys/types.h> +#include <sys/sysctl.h> + +int +sysctlbyname(char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) +{ + int name2oid_oid[2]; + int real_oid[CTL_MAXNAME+2]; + int error, oidlen; + + name2oid_oid[0] = 0; /* This is magic & undocumented! */ + name2oid_oid[1] = 3; + + oidlen = sizeof(real_oid); + error = sysctl(name2oid_oid, 2, real_oid, &oidlen, name, strlen(name)); + if (error < 0) + return error; + oidlen /= sizeof (int); + error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); + return (error); +} + |