aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2017-01-13 08:39:23 +0000
committerEnji Cooper <ngie@FreeBSD.org>2017-01-13 08:39:23 +0000
commit67f7a176115dccda6c95a4c73052a47f4845453e (patch)
treef94a35e7eb68b4c7f336299cbccb45265ce33d8d /lib/libutil
parent8a9961e9ca680529d6a7f09f7dadea0dc00c5c21 (diff)
downloadsrc-67f7a176115dccda6c95a4c73052a47f4845453e.tar.gz
src-67f7a176115dccda6c95a4c73052a47f4845453e.zip
MFC r311714:
lib/libutil/kinfo_*: style cleanup - Use nitems(mib) instead of hardcoding mib's length - Sort sys/ #includes
Notes
Notes: svn path=/stable/11/; revision=312031
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/kinfo_getallproc.c6
-rw-r--r--lib/libutil/kinfo_getfile.c6
-rw-r--r--lib/libutil/kinfo_getproc.c6
-rw-r--r--lib/libutil/kinfo_getvmmap.c6
4 files changed, 12 insertions, 12 deletions
diff --git a/lib/libutil/kinfo_getallproc.c b/lib/libutil/kinfo_getallproc.c
index 0f43ce2e1ad9..8620f48545dc 100644
--- a/lib/libutil/kinfo_getallproc.c
+++ b/lib/libutil/kinfo_getallproc.c
@@ -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;
diff --git a/lib/libutil/kinfo_getfile.c b/lib/libutil/kinfo_getfile.c
index 8a5477f40654..22baf534f504 100644
--- a/lib/libutil/kinfo_getfile.c
+++ b/lib/libutil/kinfo_getfile.c
@@ -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);
diff --git a/lib/libutil/kinfo_getproc.c b/lib/libutil/kinfo_getproc.c
index 2ae6b57ee71d..496f71f55559 100644
--- a/lib/libutil/kinfo_getproc.c
+++ b/lib/libutil/kinfo_getproc.c
@@ -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;
diff --git a/lib/libutil/kinfo_getvmmap.c b/lib/libutil/kinfo_getvmmap.c
index 9d9e4273a110..e01f48284c68 100644
--- a/lib/libutil/kinfo_getvmmap.c
+++ b/lib/libutil/kinfo_getvmmap.c
@@ -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);