diff options
| author | Poul-Henning Kamp <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
|---|---|---|
| committer | Poul-Henning Kamp <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
| commit | d71458ee72dc019a408ccd80b4f12abc573da287 (patch) | |
| tree | f3e5cad6b9610b6b082996ce7e9732c47feed41e /lib/libc/gen/getpagesize.c | |
| parent | 3a91de068ccffd54e9f0b1cf75c197f8a5d9f132 (diff) | |
Notes
Diffstat (limited to 'lib/libc/gen/getpagesize.c')
| -rw-r--r-- | lib/libc/gen/getpagesize.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index d586cf68d534..556ff9e032da 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -38,16 +38,24 @@ static char sccsid[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; #include <sys/param.h> #include <sys/sysctl.h> +/* + * This is unlikely to change over the running time of any + * program, so we cache the result to save some syscalls. + */ + int getpagesize() { - int mib[2], value; + int mib[2]; + static int value; size_t size; - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); + if (!value) { + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + } return (value); } |
