summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2008-03-16 19:56:28 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2008-03-16 19:56:28 +0000
commita76f94c31f5e1b2da03a560e6b379595e0077e1f (patch)
treef749a404534ef084386b5488b7a3958676e48a3a /lib/libc
parent184652f0aac51db18e318953058474a7ac4493b6 (diff)
Add the semi-standard _SC_PHYS_PAGES and _SC_AVPHYS_PAGES, sysconf(3) variable.
ok espie@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/sysconf.38
-rw-r--r--lib/libc/gen/sysconf.c28
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index 7bfc70fe446..a083149c00f 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sysconf.3,v 1.22 2007/05/31 19:19:28 jmc Exp $
+.\" $OpenBSD: sysconf.3,v 1.23 2008/03/16 19:56:27 kettenis Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: March 16 2008 $
.Dt SYSCONF 3
.Os
.Sh NAME
@@ -148,6 +148,10 @@ does not support the Semaphores Option.
.It Li _SC_SEM_VALUE_MAX
The maximum value a semaphore may have or \-1 if the system
does not support the Semaphores Option.
+.It Li _SC_PHYS_PAGES
+The number of pages of physical memory.
+.It Li _SC_AVPHYS_PAGES
+The number of pages of physical memory not currently in use by the system.
.El
.Sh RETURN VALUES
If the call to
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 16dbc8c6673..f888ab4c780 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysconf.c,v 1.8 2005/08/08 08:05:34 espie Exp $ */
+/* $OpenBSD: sysconf.c,v 1.9 2008/03/16 19:56:27 kettenis Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@@ -36,6 +36,7 @@
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <sys/vmmeter.h>
#include <errno.h>
#include <unistd.h>
@@ -198,6 +199,31 @@ yesno: if (sysctl(mib, namelen, &value, &len, NULL, 0) == -1)
KERN_SEMINFO_SEMMNS : KERN_SEMINFO_SEMVMX;
namelen = 3;
break;
+
+/* Extensions */
+ case _SC_PHYS_PAGES:
+ {
+ int64_t physmem;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM64;
+ len = sizeof(physmem);
+ if (sysctl(mib, namelen, &physmem, &len, NULL, 0) == -1)
+ return (-1);
+ return (physmem / getpagesize());
+ }
+ case _SC_AVPHYS_PAGES:
+ {
+ struct vmtotal vmtotal;
+
+ mib[0] = CTL_VM;
+ mib[1] = VM_METER;
+ len = sizeof(vmtotal);
+ if (sysctl(mib, namelen, &vmtotal, &len, NULL, 0) == -1)
+ return (-1);
+ return (vmtotal.t_free);
+ }
+
default:
errno = EINVAL;
return (-1);