diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_errno/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c | 45 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile new file mode 100644 index 0000000000..73ebe37491 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
2 | |||
3 | PROG= malloc_errno | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c new file mode 100644 index 0000000000..61d85e5d41 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* $OpenBSD: malloc_errno.c,v 1.1 2003/07/15 10:06:31 otto Exp $ */ | ||
2 | /* | ||
3 | * Public domain. 2003, Otto Moerbeek | ||
4 | */ | ||
5 | #include <err.h> | ||
6 | #include <errno.h> | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | |||
10 | static void | ||
11 | testerrno(size_t sz) | ||
12 | { | ||
13 | void *p; | ||
14 | |||
15 | errno = -1; | ||
16 | p = malloc(sz); | ||
17 | |||
18 | if (p == NULL && errno != ENOMEM) | ||
19 | errx(1, "fail: %lx %p %d\n", (unsigned long)sz, p, errno); | ||
20 | |||
21 | /* if alloc succeeded, test if errno did not change */ | ||
22 | if (p != NULL && errno != -1) | ||
23 | errx(1, "fail: %lx %p %d\n", (unsigned long)sz, p, errno); | ||
24 | |||
25 | free(p); | ||
26 | } | ||
27 | |||
28 | /* | ||
29 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
30 | * correctly. | ||
31 | */ | ||
32 | int | ||
33 | main() | ||
34 | { | ||
35 | size_t i; | ||
36 | |||
37 | testerrno(1); | ||
38 | testerrno(100000); | ||
39 | testerrno(-1); | ||
40 | testerrno(-1000); | ||
41 | testerrno(-10000); | ||
42 | for (i = 0; i < 0x10; i++) | ||
43 | testerrno(i * 0x10000000); | ||
44 | return 0; | ||
45 | } | ||