regression: setenv-oom test
[libc-test] / src / regression / setenv-oom.c
1 // commit 543787039098c121917cb5f3e129d84b61afa61b 2013-10-04
2 // setenv should not crash on oom
3 #include <stdlib.h>
4 #include <string.h>
5 #include <errno.h>
6 #include "test.h"
7
8 int main(void)
9 {
10         char buf[10000];
11
12         if (t_vmfill(0,0,0) < 0)
13                 t_error("vmfill failed: %s\n", strerror(errno));
14
15         memset(buf, 'x', sizeof buf);
16         buf[sizeof buf - 1] = 0;
17
18         errno = 0;
19         if (setenv("TESTVAR", buf, 1) != -1)
20                 t_error("setenv was successful\n");
21         if (errno != ENOMEM)
22                 t_error("expected ENOMEM, got %s\n", strerror(errno));
23
24         return t_status;
25 }