diff options
author | otto <> | 2006-04-18 19:04:03 +0000 |
---|---|---|
committer | otto <> | 2006-04-18 19:04:03 +0000 |
commit | 04e1c7d3381a8e957a4ac6ddfc5dc4f5406b3a54 (patch) | |
tree | 007998123d26c0382c7beffd4d7437fec13f54e6 | |
parent | 6bf19059cbe736f5a23b8bf7451935947bb681a4 (diff) | |
download | openbsd-04e1c7d3381a8e957a4ac6ddfc5dc4f5406b3a54.tar.gz openbsd-04e1c7d3381a8e957a4ac6ddfc5dc4f5406b3a54.tar.bz2 openbsd-04e1c7d3381a8e957a4ac6ddfc5dc4f5406b3a54.zip |
near ulimit test case 2
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_ulimit2/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile new file mode 100644 index 0000000000..bc83666415 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
2 | |||
3 | PROG= malloc_ulimit2 | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c new file mode 100644 index 0000000000..6c3fbbcb56 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c | |||
@@ -0,0 +1,41 @@ | |||
1 | /* $OpenBSD: malloc_ulimit2.c,v 1.1 2006/04/18 19:04:03 otto Exp $ */ | ||
2 | |||
3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/time.h> | ||
7 | #include <sys/resource.h> | ||
8 | #include <err.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | #define FACTOR 1024 | ||
13 | |||
14 | main() | ||
15 | { | ||
16 | struct rlimit lim; | ||
17 | size_t sz; | ||
18 | int i; | ||
19 | void *p; | ||
20 | |||
21 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
22 | err(1, "getrlimit"); | ||
23 | |||
24 | sz = lim.rlim_cur / FACTOR; | ||
25 | |||
26 | for (i = 0; ; i++) { | ||
27 | size_t len = (sz-i) * FACTOR; | ||
28 | p = malloc(len); | ||
29 | if (p != NULL) { | ||
30 | free(p); | ||
31 | break; | ||
32 | } | ||
33 | } | ||
34 | i += 10; | ||
35 | for (; i >= 0; i--) { | ||
36 | size_t len = (sz-i) * FACTOR; | ||
37 | p = malloc(len); | ||
38 | free(p); | ||
39 | free(malloc(4096)); | ||
40 | } | ||
41 | } | ||