xref: /third_party/musl/libc-test/src/common/setrlim.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/libc-test/src/common/
1570af302Sopenharmony_ci#include <string.h>
2570af302Sopenharmony_ci#include <errno.h>
3570af302Sopenharmony_ci#include <sys/resource.h>
4570af302Sopenharmony_ci#include "test.h"
5570af302Sopenharmony_ci
6570af302Sopenharmony_ciint t_setrlim(int r, long lim)
7570af302Sopenharmony_ci{
8570af302Sopenharmony_ci	struct rlimit rl;
9570af302Sopenharmony_ci
10570af302Sopenharmony_ci	if (getrlimit(r, &rl)) {
11570af302Sopenharmony_ci		t_error("getrlimit %d: %s\n", r, strerror(errno));
12570af302Sopenharmony_ci		return -1;
13570af302Sopenharmony_ci	}
14570af302Sopenharmony_ci	if (lim > rl.rlim_max)
15570af302Sopenharmony_ci		return -1;
16570af302Sopenharmony_ci	if (lim == rl.rlim_max && lim == rl.rlim_cur)
17570af302Sopenharmony_ci		return 0;
18570af302Sopenharmony_ci	rl.rlim_max = lim;
19570af302Sopenharmony_ci	rl.rlim_cur = lim;
20570af302Sopenharmony_ci	if (setrlimit(r, &rl)) {
21570af302Sopenharmony_ci		t_error("setrlimit(%d, %ld): %s\n", r, lim, strerror(errno));
22570af302Sopenharmony_ci		return -1;
23570af302Sopenharmony_ci	}
24570af302Sopenharmony_ci	return 0;
25570af302Sopenharmony_ci}
26570af302Sopenharmony_ci
27

Indexes created Thu Nov 07 10:32:03 CST 2024