conformance fixes
[libc-test.git] / src / common / setrlim.c
blobcc89f61a01cf7d03fbd9940debe602f85a9abaa7
1 #include <string.h>
2 #include <errno.h>
3 #include <sys/resource.h>
4 #include "test.h"
6 int t_setrlim(int r, long lim)
8 struct rlimit rl;
10 if (getrlimit(r, &rl)) {
11 t_error("getrlimit %d: %s\n", r, strerror(errno));
12 return -1;
14 if (lim > rl.rlim_max)
15 return -1;
16 if (lim == rl.rlim_max && lim == rl.rlim_cur)
17 return 0;
18 rl.rlim_max = lim;
19 rl.rlim_cur = lim;
20 if (setrlimit(r, &rl)) {
21 t_error("setrlimit(%d, %ld): %s\n", r, lim, strerror(errno));
22 return -1;
24 return 0;