Author: ed
Date: Sun Feb 21 13:57:02 2010
New Revision: 204170
URL: http://svn.freebsd.org/changeset/base/204170

Log:
  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.

Modified:
  head/lib/libc/gen/sysctl.3
  head/lib/libc/gen/sysctl.c
  head/lib/libc/gen/sysctlbyname.c
  head/lib/libc/gen/sysctlnametomib.c
  head/sys/sys/sysctl.h

Modified: head/lib/libc/gen/sysctl.3
==============================================================================
--- head/lib/libc/gen/sysctl.3  Sun Feb 21 13:17:35 2010        (r204169)
+++ head/lib/libc/gen/sysctl.3  Sun Feb 21 13:57:02 2010        (r204170)
@@ -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

Modified: head/lib/libc/gen/sysctl.c
==============================================================================
--- head/lib/libc/gen/sysctl.c  Sun Feb 21 13:17:35 2010        (r204169)
+++ head/lib/libc/gen/sysctl.c  Sun Feb 21 13:57:02 2010        (r204170)
@@ -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));

Modified: head/lib/libc/gen/sysctlbyname.c
==============================================================================
--- head/lib/libc/gen/sysctlbyname.c    Sun Feb 21 13:17:35 2010        
(r204169)
+++ head/lib/libc/gen/sysctlbyname.c    Sun Feb 21 13:57:02 2010        
(r204170)
@@ -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);
 }

Modified: head/lib/libc/gen/sysctlnametomib.c
==============================================================================
--- head/lib/libc/gen/sysctlnametomib.c Sun Feb 21 13:17:35 2010        
(r204169)
+++ head/lib/libc/gen/sysctlnametomib.c Sun Feb 21 13:57:02 2010        
(r204170)
@@ -48,8 +48,8 @@ sysctlnametomib(const char *name, int *m
        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);
 }

Modified: head/sys/sys/sysctl.h
==============================================================================
--- head/sys/sys/sysctl.h       Sun Feb 21 13:17:35 2010        (r204169)
+++ head/sys/sys/sysctl.h       Sun Feb 21 13:57:02 2010        (r204170)
@@ -714,8 +714,8 @@ int sysctl_wire_old_buffer(struct sysctl
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-int    sysctl(int *, u_int, void *, size_t *, void *, size_t);
-int    sysctlbyname(const char *, void *, size_t *, void *, size_t);
+int    sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
+int    sysctlbyname(const char *, void *, size_t *, const void *, size_t);
 int    sysctlnametomib(const char *, int *, size_t *);
 __END_DECLS
 #endif /* _KERNEL */
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to