gcc/testsuite/gfortran.dg/set_vm_limit.c
raw| 1 | /* Called by pr68078. */ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <sys/time.h> |
| 6 | #include <sys/resource.h> |
| 7 | |
| 8 | void |
| 9 | set_vm_limit (int vm_limit) |
| 10 | { |
| 11 | struct rlimit rl; |
| 12 | int r; |
| 13 | |
| 14 | r = getrlimit (RLIMIT_AS, &rl); |
| 15 | if (r) |
| 16 | { |
| 17 | perror ("get_vm_limit"); |
| 18 | exit (1); |
| 19 | } |
| 20 | |
| 21 | if (vm_limit >= rl.rlim_cur) |
| 22 | return; |
| 23 | |
| 24 | rl.rlim_cur = vm_limit; |
| 25 | r = setrlimit (RLIMIT_AS, &rl); |
| 26 | if (r) |
| 27 | { |
| 28 | perror ("set_vm_limit"); |
| 29 | exit (1); |
| 30 | } |
| 31 | |
| 32 | return; |
| 33 | } |