summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-04-18 19:04:04 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-04-18 19:04:04 +0000
commit5ef1fe2607b0c1572326ceabf3d6c39b61cb4500 (patch)
tree8591de221057e323bc44a3d5945005da654e299b
parent14d8b1a4ce4bf501fadb7b37f01d346e207736bb (diff)
near ulimit test case 2
-rw-r--r--regress/lib/libc/malloc/malloc_ulimit2/Makefile5
-rw-r--r--regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c41
2 files changed, 46 insertions, 0 deletions
diff --git a/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/regress/lib/libc/malloc/malloc_ulimit2/Makefile
new file mode 100644
index 00000000000..bc836664154
--- /dev/null
+++ b/regress/lib/libc/malloc/malloc_ulimit2/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $
+
+PROG= malloc_ulimit2
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c
new file mode 100644
index 00000000000..6c3fbbcb561
--- /dev/null
+++ b/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c
@@ -0,0 +1,41 @@
+/* $OpenBSD: malloc_ulimit2.c,v 1.1 2006/04/18 19:04:03 otto Exp $ */
+
+/* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <err.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define FACTOR 1024
+
+main()
+{
+ struct rlimit lim;
+ size_t sz;
+ int i;
+ void *p;
+
+ if (getrlimit(RLIMIT_DATA, &lim) == -1)
+ err(1, "getrlimit");
+
+ sz = lim.rlim_cur / FACTOR;
+
+ for (i = 0; ; i++) {
+ size_t len = (sz-i) * FACTOR;
+ p = malloc(len);
+ if (p != NULL) {
+ free(p);
+ break;
+ }
+ }
+ i += 10;
+ for (; i >= 0; i--) {
+ size_t len = (sz-i) * FACTOR;
+ p = malloc(len);
+ free(p);
+ free(malloc(4096));
+ }
+}