summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/sysconf.c
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2008-03-16 19:56:27 +0000
committerkettenis <kettenis@openbsd.org>2008-03-16 19:56:27 +0000
commit6b764f82f48fac1c013716afa6ee19434b15338b (patch)
tree45b5cf05474ca19017a9bae278018689c3778592 /lib/libc/gen/sysconf.c
parentdiff from djm@ committed at his request: (diff)
downloadwireguard-openbsd-6b764f82f48fac1c013716afa6ee19434b15338b.tar.xz
wireguard-openbsd-6b764f82f48fac1c013716afa6ee19434b15338b.zip
Add the semi-standard _SC_PHYS_PAGES and _SC_AVPHYS_PAGES, sysconf(3) variable.
ok espie@
Diffstat (limited to 'lib/libc/gen/sysconf.c')
-rw-r--r--lib/libc/gen/sysconf.c28
1 files changed, 27 insertions, 1 deletions
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);