diff options
author | ed <ed@FreeBSD.org> | 2010-02-21 13:57:02 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2010-02-21 13:57:02 +0000 |
commit | 1fdea921e1450bf99dc432803cd6c88e08540a21 (patch) | |
tree | fcb4fe1d12f11b6cab916731649d8e0d8c2645b0 /lib | |
parent | 24f8e6df2531b9453d13e5fc72bb019b22e630a8 (diff) | |
download | FreeBSD-src-1fdea921e1450bf99dc432803cd6c88e08540a21.zip FreeBSD-src-1fdea921e1450bf99dc432803cd6c88e08540a21.tar.gz |
Add proper const keywords to sysctl(3) parameters.
The `name' and `newp' arguments can be marked const, because the buffers
they refer to are never changed. While there, perform some other
cleanups:
- Remove K&R from sysctl.c.
- Implement sysctlbyname() using sysctlnametomib() to prevent
duplication of an undocumented kernel interface.
- Fix some whitespace nits.
It seems the prototypes are now in sync with NetBSD as well.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/sysctl.3 | 6 | ||||
-rw-r--r-- | lib/libc/gen/sysctl.c | 11 | ||||
-rw-r--r-- | lib/libc/gen/sysctlbyname.c | 17 | ||||
-rw-r--r-- | lib/libc/gen/sysctlnametomib.c | 6 |
4 files changed, 15 insertions, 25 deletions
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index 75f8668..143be16 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -28,7 +28,7 @@ .\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95 .\" $FreeBSD$ .\" -.Dd January 28, 2009 +.Dd February 21, 2010 .Dt SYSCTL 3 .Os .Sh NAME @@ -42,9 +42,9 @@ .In sys/types.h .In sys/sysctl.h .Ft int -.Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" +.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen" .Ft int -.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" +.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen" .Ft int .Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep" .Sh DESCRIPTION diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index eb6418e..fbc2c0c 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -43,15 +43,12 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <string.h> -extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen); +extern int __sysctl(const int *name, u_int namelen, void *oldp, + size_t *oldlenp, const void *newp, size_t newlen); int -sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp, *newp; - size_t *oldlenp, newlen; +sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) { if (name[0] != CTL_USER) return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c index 4510fe0..0288d87 100644 --- a/lib/libc/gen/sysctlbyname.c +++ b/lib/libc/gen/sysctlbyname.c @@ -13,26 +13,19 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/sysctl.h> -#include <string.h> int -sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, - size_t newlen) +sysctlbyname(const char *name, void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) { - int name2oid_oid[2]; int real_oid[CTL_MAXNAME+2]; int error; size_t 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, (void *)name, - strlen(name)); + oidlen = sizeof(real_oid) / sizeof(int); + error = sysctlnametomib(name, real_oid, &oidlen); if (error < 0) - return error; - oidlen /= sizeof (int); + return (error); error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); return (error); } diff --git a/lib/libc/gen/sysctlnametomib.c b/lib/libc/gen/sysctlnametomib.c index 1515784..afca95d 100644 --- a/lib/libc/gen/sysctlnametomib.c +++ b/lib/libc/gen/sysctlnametomib.c @@ -48,8 +48,8 @@ sysctlnametomib(const char *name, int *mibp, size_t *sizep) oid[0] = 0; oid[1] = 3; - *sizep *= sizeof (int); - error = sysctl(oid, 2, mibp, sizep, (void *)name, strlen(name)); - *sizep /= sizeof (int); + *sizep *= sizeof(int); + error = sysctl(oid, 2, mibp, sizep, name, strlen(name)); + *sizep /= sizeof(int); return (error); } |