0001-Add-proper-const-keywords-to-sysctl-3-parameters.patch

kAworu, 11/22/2013 11:06 AM

Download (6.98 KB)

View differences:

lib/libc/gen/sysctl.3
26 26
.\" SUCH DAMAGE.
27 27
.\"
28 28
.\"	@(#)sysctl.3	8.4 (Berkeley) 5/9/95
29
.\" $FreeBSD: src/lib/libc/gen/sysctl.3,v 1.33.2.13 2002/04/07 04:57:14 dd Exp $
29
.\" $FreeBSD: head/lib/libc/gen/sysctl.3 204170 2010-02-21 13:57:02Z ed $
30 30
.\" $DragonFly: src/lib/libc/gen/sysctl.3,v 1.10 2008/05/02 02:05:03 swildner Exp $
31 31
.\"
32
.Dd January 23, 2001
32
.Dd November 21, 2013
33 33
.Dt SYSCTL 3
34 34
.Os
35 35
.Sh NAME
......
43 43
.In sys/types.h
44 44
.In sys/sysctl.h
45 45
.Ft int
46
.Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen"
46
.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
47 47
.Ft int
48
.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen"
48
.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
49 49
.Ft int
50 50
.Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep"
51 51
.Sh DESCRIPTION
lib/libc/gen/sysctl.c
27 27
 * SUCH DAMAGE.
28 28
 *
29 29
 * @(#)sysctl.c	8.2 (Berkeley) 1/4/94
30
 * $FreeBSD: src/lib/libc/gen/sysctl.c,v 1.6 2007/01/09 00:27:55 imp Exp $
30
 * $FreeBSD: head/lib/libc/gen/sysctl.c 240176 2012-09-06 20:15:44Z trhodes $
31 31
 * $DragonFly: src/lib/libc/gen/sysctl.c,v 1.3 2005/11/13 00:07:42 swildner Exp $
32 32
 */
33 33

  
......
41 41
#include <unistd.h>
42 42
#include <string.h>
43 43

  
44
extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
45
		    void *newp, size_t newlen);
44
extern int __sysctl(const int *name, u_int namelen, void *oldp,
45
    size_t *oldlenp, const void *newp, size_t newlen);
46 46

  
47 47
int
48
sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
49
       size_t newlen)
48
sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
49
    const void *newp, size_t newlen)
50 50
{
51
	if (name[0] != CTL_USER)
52
		return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
51
	int retval;
52

  
53
	retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
54
	if (retval != -1 || errno != ENOENT || name[0] != CTL_USER)
55
		return (retval);
53 56

  
54 57
	if (newp != NULL) {
55 58
		errno = EPERM;
lib/libc/gen/sysctlbyname.c
6 6
 * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7 7
 * ----------------------------------------------------------------------------
8 8
 *
9
 * $FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.4 1999/08/27 23:59:01 peter Exp $
9
 * $FreeBSD: head/lib/libc/gen/sysctlbyname.c 244153 2012-12-12 15:27:33Z pjd $
10 10
 * $DragonFly: src/lib/libc/gen/sysctlbyname.c,v 1.2 2003/06/17 04:26:42 dillon Exp $
11 11
 *
12 12
 */
13 13
#include <sys/types.h>
14 14
#include <sys/sysctl.h>
15
#include <string.h>
16 15

  
17 16
int
18
sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
19
	     size_t newlen)
17
sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
18
    const void *newp, size_t newlen)
20 19
{
21
	int name2oid_oid[2];
22 20
	int real_oid[CTL_MAXNAME+2];
23
	int error;
24 21
	size_t oidlen;
25 22

  
26
	name2oid_oid[0] = 0;	/* This is magic & undocumented! */
27
	name2oid_oid[1] = 3;
28

  
29
	oidlen = sizeof(real_oid);
30
	error = sysctl(name2oid_oid, 2, real_oid, &oidlen, (void *)name,
31
		       strlen(name));
32
	if (error < 0) 
33
		return error;
34
	oidlen /= sizeof (int);
35
	error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
36
	return (error);
23
	oidlen = sizeof(real_oid) / sizeof(int);
24
	if (sysctlnametomib(name, real_oid, &oidlen) < 0)
25
		return (-1);
26
	return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
37 27
}
38

  
lib/libc/gen/sysctlnametomib.c
23 23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 24
 * SUCH DAMAGE.
25 25
 *
26
 * $FreeBSD: src/lib/libc/gen/sysctlnametomib.c,v 1.4 2003/01/04 00:11:11 tjr Exp $
26
 * $FreeBSD: head/lib/libc/gen/sysctlnametomib.c 204170 2010-02-21 13:57:02Z ed $
27 27
 * $DragonFly: src/lib/libc/gen/sysctlnametomib.c,v 1.3 2005/11/19 22:32:53 swildner Exp $
28 28
 */
29 29

  
......
48 48
	oid[0] = 0;
49 49
	oid[1] = 3;
50 50

  
51
	*sizep *= sizeof (int);
52
	error = sysctl(oid, 2, mibp, sizep, (void *)name, strlen(name));
53
	*sizep /= sizeof (int);
51
	*sizep *= sizeof(int);
52
	error = sysctl(oid, 2, mibp, sizep, name, strlen(name));
53
	*sizep /= sizeof(int);
54 54
	return (error);
55 55
}
sys/sys/sysctl.h
34 34
 * SUCH DAMAGE.
35 35
 *
36 36
 *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
37
 * $FreeBSD: src/sys/sys/sysctl.h,v 1.81.2.10 2003/05/01 22:48:09 trhodes Exp $
37
 * $FreeBSD: head/sys/sys/sysctl.h 204170 2010-02-21 13:57:02Z ed $
38 38
 * $DragonFly: src/sys/sys/sysctl.h,v 1.29 2008/09/30 12:20:29 hasso Exp $
39 39
 */
40 40

  
......
660 660
#include <sys/cdefs.h>
661 661

  
662 662
__BEGIN_DECLS
663
int	sysctl (int *, u_int, void *, size_t *, void *, size_t);
664
int	sysctlbyname (const char *, void *, size_t *, void *, size_t);
663
int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
664
int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
665 665
int	sysctlnametomib (const char *, int *, size_t *);
666 666
__END_DECLS
667 667

  
668
-