Update.
[glibc.git] / sysdeps / unix / sysv / linux / setrlimit.c
blob43bfdbbbc42e16787b23fca415daa0dbd20c1ee9
1 /* Copyright (C) 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <errno.h>
20 #include <sys/param.h>
21 #include <sys/resource.h>
23 #include <sysdep.h>
24 #include <sys/syscall.h>
26 #include "kernel-features.h"
28 extern int __syscall_setrlimit (unsigned int resource,
29 const struct rlimit *rlimits);
31 /* Linux 2.3.25 introduced a new system call since the types used for
32 the limits are now unsigned. */
33 #if !defined __ASSUME_NEW_GETRLIMIT_SYSCALL && defined __NR_ugetrlimit
34 static int no_new_getrlimit;
35 #else
36 # define no_new_getrlimit 0
37 #endif
39 int
40 __setrlimit (resource, rlimits)
41 enum __rlimit_resource resource;
42 const struct rlimit *rlimits;
44 #ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
45 struct rlimit rlimits_small;
46 #endif
48 #ifdef __NR_ugetrlimit
49 if (! no_new_getrlimit)
51 int result = INLINE_SYSCALL (setrlimit, 2, resource, rlimits);
53 # ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
54 /* If the system call is available return. */
55 if (result != -1 || errno != ENOSYS)
56 # endif
57 return result;
59 # ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
60 /* Remember that the system call is not available. */
61 no_new_getrlimit = 1;
62 # endif
64 #endif
66 #ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
67 /* We might have to correct the limits values. Since the old values
68 were signed the new values are too large. */
69 rlimits_small.rlim_cur = MIN ((unsigned long int) rlimits->rlim_cur,
70 RLIM_INFINITY >> 2);
71 rlimits_small.rlim_max = MIN ((unsigned long int) rlimits->rlim_max,
72 RLIM_INFINITY >> 2);
74 /* Fall back on the old system call. */
75 return INLINE_SYSCALL (setrlimit, 2, resource, &rlimits_small);
76 #endif
78 weak_alias (__setrlimit, setrlimit)