Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jan 2017 00:47:24 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r311714 - head/lib/libutil
Message-ID:  <201701090047.v090lOlF077136@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Mon Jan  9 00:47:23 2017
New Revision: 311714
URL: https://svnweb.freebsd.org/changeset/base/311714

Log:
  lib/libutil/kinfo_*: style cleanup
  
  - Use nitems(mib) instead of hardcoding mib's length
  - Sort sys/ #includes
  
  MFC after:	3 days

Modified:
  head/lib/libutil/kinfo_getallproc.c
  head/lib/libutil/kinfo_getfile.c
  head/lib/libutil/kinfo_getproc.c
  head/lib/libutil/kinfo_getvmmap.c

Modified: head/lib/libutil/kinfo_getallproc.c
==============================================================================
--- head/lib/libutil/kinfo_getallproc.c	Mon Jan  9 00:38:19 2017	(r311713)
+++ head/lib/libutil/kinfo_getallproc.c	Mon Jan  9 00:47:23 2017	(r311714)
@@ -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;

Modified: head/lib/libutil/kinfo_getfile.c
==============================================================================
--- head/lib/libutil/kinfo_getfile.c	Mon Jan  9 00:38:19 2017	(r311713)
+++ head/lib/libutil/kinfo_getfile.c	Mon Jan  9 00:47:23 2017	(r311714)
@@ -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);

Modified: head/lib/libutil/kinfo_getproc.c
==============================================================================
--- head/lib/libutil/kinfo_getproc.c	Mon Jan  9 00:38:19 2017	(r311713)
+++ head/lib/libutil/kinfo_getproc.c	Mon Jan  9 00:47:23 2017	(r311714)
@@ -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;

Modified: head/lib/libutil/kinfo_getvmmap.c
==============================================================================
--- head/lib/libutil/kinfo_getvmmap.c	Mon Jan  9 00:38:19 2017	(r311713)
+++ head/lib/libutil/kinfo_getvmmap.c	Mon Jan  9 00:47:23 2017	(r311714)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701090047.v090lOlF077136>