add run wrapper, move t_printf and t_status into separate translation unit
[libc-test] / src / common / setrlim.c
diff --git a/src/common/setrlim.c b/src/common/setrlim.c
new file mode 100644 (file)
index 0000000..fc76a8e
--- /dev/null
@@ -0,0 +1,26 @@
+#include <string.h>
+#include <errno.h>
+#include <sys/resource.h>
+#include "test.h"
+
+int t_setrlim(int r, long lim)
+{
+       struct rlimit rl;
+
+       if (getrlimit(r, &rl)) {
+               t_error("getrlimit %d: %s\n", r, strerror(errno));
+               return -1;
+       }
+       if (lim > rl.rlim_max)
+               return -1;
+       if (lim == rl.rlim_max && lim == rl.rlim_cur)
+               return 0;
+       rl.rlim_max = lim;
+       rl.rlim_cur = lim;
+       if (setrlimit(r, &rl)) {
+               t_error("setrlimit %d: %s\n", r, strerror(errno));
+               return -1;
+       }
+       return 0;
+}
+