summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-getpagesize.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2017-06-01 15:25:13 +1000
committerDamien Miller <djm@mindrot.org>2017-06-01 15:25:13 +1000
commit151c6e433a5f5af761c78de87d7b5d30a453cf5e (patch)
tree77cdffcee99995b20821a8f2a957504e861475d5 /openbsd-compat/bsd-getpagesize.c
parent01e6f78924da308447e71e9a32c8a6104ef4e888 (diff)
add recallocarray replacement and dependency
recallocarray() needs getpagesize() so add a tiny replacement for that.
Diffstat (limited to 'openbsd-compat/bsd-getpagesize.c')
-rw-r--r--openbsd-compat/bsd-getpagesize.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/openbsd-compat/bsd-getpagesize.c b/openbsd-compat/bsd-getpagesize.c
new file mode 100644
index 00000000..9daddfbd
--- /dev/null
+++ b/openbsd-compat/bsd-getpagesize.c
@@ -0,0 +1,23 @@
+/* Placed in the public domain */
+
+#ifndef HAVE_GETPAGESIZE
+
+#include <unistd.h>
+#include <limits.h>
+
+int
+getpagesize(void)
+{
+#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
+ long r = sysconf(_SC_PAGESIZE);
+ if (r > 0 && r < INT_MAX)
+ return (int)r;
+#endif
+ /*
+ * This is at the lower end of common values and appropriate for
+ * our current use of getpagesize() in recallocarray().
+ */
+ return 4096;
+}
+
+#endif /* HAVE_GETPAGESIZE */