Date: Fri, 13 Jan 2017 08:39:40 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r312032 - stable/10/lib/libutil Message-ID: <201701130839.v0D8def3049949@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Fri Jan 13 08:39:40 2017 New Revision: 312032 URL: https://svnweb.freebsd.org/changeset/base/312032 Log: MFC r311714: lib/libutil/kinfo_*: style cleanup - Use nitems(mib) instead of hardcoding mib's length - Sort sys/ #includes Modified: stable/10/lib/libutil/kinfo_getallproc.c stable/10/lib/libutil/kinfo_getfile.c stable/10/lib/libutil/kinfo_getproc.c stable/10/lib/libutil/kinfo_getvmmap.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libutil/kinfo_getallproc.c ============================================================================== --- stable/10/lib/libutil/kinfo_getallproc.c Fri Jan 13 08:39:23 2017 (r312031) +++ stable/10/lib/libutil/kinfo_getallproc.c Fri Jan 13 08:39:40 2017 (r312032) @@ -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: stable/10/lib/libutil/kinfo_getfile.c ============================================================================== --- stable/10/lib/libutil/kinfo_getfile.c Fri Jan 13 08:39:23 2017 (r312031) +++ stable/10/lib/libutil/kinfo_getfile.c Fri Jan 13 08:39:40 2017 (r312032) @@ -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: stable/10/lib/libutil/kinfo_getproc.c ============================================================================== --- stable/10/lib/libutil/kinfo_getproc.c Fri Jan 13 08:39:23 2017 (r312031) +++ stable/10/lib/libutil/kinfo_getproc.c Fri Jan 13 08:39:40 2017 (r312032) @@ -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: stable/10/lib/libutil/kinfo_getvmmap.c ============================================================================== --- stable/10/lib/libutil/kinfo_getvmmap.c Fri Jan 13 08:39:23 2017 (r312031) +++ stable/10/lib/libutil/kinfo_getvmmap.c Fri Jan 13 08:39:40 2017 (r312032) @@ -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?201701130839.v0D8def3049949>