source: azure_iot_hub/trunk/musl-1.1.18/src/misc/setrlimit.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 1.1 KB
Line 
1#include <sys/resource.h>
2#include <errno.h>
3#include "syscall.h"
4#include "libc.h"
5
6#define MIN(a, b) ((a)<(b) ? (a) : (b))
7#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
8
9int __setrlimit(int resource, const struct rlimit *rlim)
10{
11 unsigned long k_rlim[2];
12 struct rlimit tmp;
13 if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
14 tmp = *rlim;
15 FIX(tmp.rlim_cur);
16 FIX(tmp.rlim_max);
17 rlim = &tmp;
18 }
19 int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
20 if (ret != -ENOSYS) return ret;
21 k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY));
22 k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY));
23 return __syscall(SYS_setrlimit, resource, k_rlim);
24}
25
26struct ctx {
27 const struct rlimit *rlim;
28 int res;
29 int err;
30};
31
32static void do_setrlimit(void *p)
33{
34 struct ctx *c = p;
35 if (c->err>0) return;
36 c->err = -__setrlimit(c->res, c->rlim);
37}
38
39int setrlimit(int resource, const struct rlimit *rlim)
40{
41 struct ctx c = { .res = resource, .rlim = rlim, .err = -1 };
42 __synccall(do_setrlimit, &c);
43 if (c.err) {
44 if (c.err>0) errno = c.err;
45 return -1;
46 }
47 return 0;
48}
49
50LFS64(setrlimit);
Note: See TracBrowser for help on using the repository browser.