add run wrapper, move t_printf and t_status into separate translation unit
[libc-test] / src / common / setrlim.c
1 #include <string.h>
2 #include <errno.h>
3 #include <sys/resource.h>
4 #include "test.h"
5
6 int t_setrlim(int r, long lim)
7 {
8         struct rlimit rl;
9
10         if (getrlimit(r, &rl)) {
11                 t_error("getrlimit %d: %s\n", r, strerror(errno));
12                 return -1;
13         }
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: %s\n", r, strerror(errno));
22                 return -1;
23         }
24         return 0;
25 }
26