lib/libutil/kinfo_*: style cleanup

- Use nitems(mib) instead of hardcoding mib's length
- Sort sys/ #includes

MFC after:	3 days
This commit is contained in:
Enji Cooper 2017-01-09 00:47:23 +00:00
parent 074a0dcceb
commit 7adf46f0c6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311714
4 changed files with 12 additions and 12 deletions

View File

@ -31,8 +31,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <stdlib.h>
#include <string.h>
@ -75,14 +75,14 @@ kinfo_getallproc(int *cntp)
mib[2] = KERN_PROC_PROC;
len = 0;
if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0)
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0)
return (NULL);
kipp = malloc(len);
if (kipp == NULL)
return (NULL);
if (sysctl(mib, 3, kipp, &len, NULL, 0) < 0)
if (sysctl(mib, nitems(mib), kipp, &len, NULL, 0) < 0)
goto bad;
if (len % sizeof(*kipp) != 0)
goto bad;

View File

@ -2,8 +2,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <stdlib.h>
#include <string.h>
@ -26,14 +26,14 @@ kinfo_getfile(pid_t pid, int *cntp)
mib[2] = KERN_PROC_FILEDESC;
mib[3] = pid;
error = sysctl(mib, 4, NULL, &len, NULL, 0);
error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
if (error)
return (NULL);
len = len * 4 / 3;
buf = malloc(len);
if (buf == NULL)
return (NULL);
error = sysctl(mib, 4, buf, &len, NULL, 0);
error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
if (error) {
free(buf);
return (NULL);

View File

@ -30,8 +30,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <stdlib.h>
#include <string.h>
@ -49,14 +49,14 @@ kinfo_getproc(pid_t pid)
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = pid;
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0)
return (NULL);
kipp = malloc(len);
if (kipp == NULL)
return (NULL);
if (sysctl(mib, 4, kipp, &len, NULL, 0) < 0)
if (sysctl(mib, nitems(mib), kipp, &len, NULL, 0) < 0)
goto bad;
if (len != sizeof(*kipp))
goto bad;

View File

@ -2,8 +2,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <stdlib.h>
#include <string.h>
@ -26,14 +26,14 @@ kinfo_getvmmap(pid_t pid, int *cntp)
mib[2] = KERN_PROC_VMMAP;
mib[3] = pid;
error = sysctl(mib, 4, NULL, &len, NULL, 0);
error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
if (error)
return (NULL);
len = len * 4 / 3;
buf = malloc(len);
if (buf == NULL)
return (NULL);
error = sysctl(mib, 4, buf, &len, NULL, 0);
error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
if (error) {
free(buf);
return (NULL);