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. */
20 #include <sys/param.h>
21 #include <sys/resource.h>
24 #include <sys/syscall.h>
26 #include "kernel-features.h"
29 /* Linux 2.3.25 introduced a new system call since the types used for
30 the limits are now unsigned. */
31 #if !defined __ASSUME_NEW_GETRLIMIT_SYSCALL && defined __NR_ugetrlimit
32 static int no_new_getrlimit
;
34 # define no_new_getrlimit 0
38 __setrlimit (resource
, rlimits
)
39 enum __rlimit_resource resource
;
40 const struct rlimit
*rlimits
;
42 #ifdef __NR_ugetrlimit
43 if (! no_new_getrlimit
)
45 int result
= INLINE_SYSCALL (setrlimit
, 2, resource
, rlimits
);
47 # ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
48 /* If the system call is available return. */
49 if (result
!= -1 || errno
!= ENOSYS
)
53 # ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
54 /* Remember that the system call is not available. */
60 #ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
61 /* We might have to correct the limits values. Since the old values
62 were signed the new values are too large. */
63 rlimits
.rlim_cur
= MIN ((unsigned long int) rlimits
.rlim_cur
,
65 rlimits
.rlim_max
= MIN ((unsigned long int) rlimits
.rlim_max
,
68 /* Fall back on the old system call. */
69 return INLINE_SYSCALL (setrlimit
, 2, resource
, rlimits
);
72 weak_alias (__setrlimit
, setrlimit
)