Submit #2607 ยป 0001-Add-proper-const-keywords-to-sysctl-3-parameters.patch
lib/libc/gen/sysctl.3 | ||
---|---|---|
.\" SUCH DAMAGE.
|
||
.\"
|
||
.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
|
||
.\" $FreeBSD: src/lib/libc/gen/sysctl.3,v 1.33.2.13 2002/04/07 04:57:14 dd Exp $
|
||
.\" $FreeBSD: head/lib/libc/gen/sysctl.3 204170 2010-02-21 13:57:02Z ed $
|
||
.\" $DragonFly: src/lib/libc/gen/sysctl.3,v 1.10 2008/05/02 02:05:03 swildner Exp $
|
||
.\"
|
||
.Dd January 23, 2001
|
||
.Dd November 21, 2013
|
||
.Dt SYSCTL 3
|
||
.Os
|
||
.Sh NAME
|
||
... | ... | |
.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
|
lib/libc/gen/sysctl.c | ||
---|---|---|
* SUCH DAMAGE.
|
||
*
|
||
* @(#)sysctl.c 8.2 (Berkeley) 1/4/94
|
||
* $FreeBSD: src/lib/libc/gen/sysctl.c,v 1.6 2007/01/09 00:27:55 imp Exp $
|
||
* $FreeBSD: head/lib/libc/gen/sysctl.c 240176 2012-09-06 20:15:44Z trhodes $
|
||
* $DragonFly: src/lib/libc/gen/sysctl.c,v 1.3 2005/11/13 00:07:42 swildner Exp $
|
||
*/
|
||
... | ... | |
#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(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
|
||
size_t 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));
|
||
int retval;
|
||
retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
|
||
if (retval != -1 || errno != ENOENT || name[0] != CTL_USER)
|
||
return (retval);
|
||
if (newp != NULL) {
|
||
errno = EPERM;
|
lib/libc/gen/sysctlbyname.c | ||
---|---|---|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||
* ----------------------------------------------------------------------------
|
||
*
|
||
* $FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.4 1999/08/27 23:59:01 peter Exp $
|
||
* $FreeBSD: head/lib/libc/gen/sysctlbyname.c 244153 2012-12-12 15:27:33Z pjd $
|
||
* $DragonFly: src/lib/libc/gen/sysctlbyname.c,v 1.2 2003/06/17 04:26:42 dillon Exp $
|
||
*
|
||
*/
|
||
#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));
|
||
if (error < 0)
|
||
return error;
|
||
oidlen /= sizeof (int);
|
||
error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
|
||
return (error);
|
||
oidlen = sizeof(real_oid) / sizeof(int);
|
||
if (sysctlnametomib(name, real_oid, &oidlen) < 0)
|
||
return (-1);
|
||
return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
|
||
}
|
||
lib/libc/gen/sysctlnametomib.c | ||
---|---|---|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
* SUCH DAMAGE.
|
||
*
|
||
* $FreeBSD: src/lib/libc/gen/sysctlnametomib.c,v 1.4 2003/01/04 00:11:11 tjr Exp $
|
||
* $FreeBSD: head/lib/libc/gen/sysctlnametomib.c 204170 2010-02-21 13:57:02Z ed $
|
||
* $DragonFly: src/lib/libc/gen/sysctlnametomib.c,v 1.3 2005/11/19 22:32:53 swildner Exp $
|
||
*/
|
||
... | ... | |
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);
|
||
}
|
sys/sys/sysctl.h | ||
---|---|---|
* SUCH DAMAGE.
|
||
*
|
||
* @(#)sysctl.h 8.1 (Berkeley) 6/2/93
|
||
* $FreeBSD: src/sys/sys/sysctl.h,v 1.81.2.10 2003/05/01 22:48:09 trhodes Exp $
|
||
* $FreeBSD: head/sys/sys/sysctl.h 204170 2010-02-21 13:57:02Z ed $
|
||
* $DragonFly: src/sys/sys/sysctl.h,v 1.29 2008/09/30 12:20:29 hasso Exp $
|
||
*/
|
||
... | ... | |
#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
|
||