Update.
[glibc.git] / sysdeps / unix / sysv / linux / setrlimit.c
blob13161593534ba68460f24dcb84ad6791eb70ca9c
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"
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;
33 #else
34 # define no_new_getrlimit 0
35 #endif
37 int
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)
50 # endif
51 return result;
53 # ifndef __ASSUME_NEW_GETRLIMIT_SYSCALL
54 /* Remember that the system call is not available. */
55 no_new_getrlimit = 1;
56 # endif
58 #endif
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,
64 RLIM_INFINITY >> 2);
65 rlimits.rlim_max = MIN ((unsigned long int) rlimits.rlim_max,
66 RLIM_INFINITY >> 2);
68 /* Fall back on the old system call. */
69 return INLINE_SYSCALL (setrlimit, 2, resource, rlimits);
70 #endif
72 weak_alias (__setrlimit, setrlimit)