Back to index

glibc  2.9
getrlimit.c
Go to the documentation of this file.
00001 /* Copyright (C) 1999, 2000, 2003, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <sys/resource.h>
00021 
00022 #include <sysdep.h>
00023 #include <sys/syscall.h>
00024 #include <shlib-compat.h>
00025 #include <bp-checks.h>
00026 
00027 #include <kernel-features.h>
00028 
00029 extern int __new_getrlimit (enum __rlimit_resource resource,
00030                          struct rlimit *__unbounded rlimits);
00031 
00032 
00033 /* Linux 2.3.25 introduced a new system call since the types used for
00034    the limits are now unsigned.  */
00035 #if defined __NR_ugetrlimit && !defined __ASSUME_NEW_GETRLIMIT_SYSCALL
00036 int __have_no_new_getrlimit;
00037 #endif
00038 
00039 int
00040 __new_getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
00041 {
00042 #ifdef __ASSUME_NEW_GETRLIMIT_SYSCALL
00043   return INLINE_SYSCALL (ugetrlimit, 2, resource, CHECK_1 (rlimits));
00044 #else
00045   int result;
00046 
00047 # ifdef __NR_ugetrlimit
00048   if (__have_no_new_getrlimit <= 0)
00049     {
00050       result = INLINE_SYSCALL (ugetrlimit, 2, resource, CHECK_1 (rlimits));
00051 
00052       /* If the system call is available remember this fact and return.  */
00053       if (result != -1 || errno != ENOSYS)
00054        {
00055          __have_no_new_getrlimit = -1;
00056          return result;
00057        }
00058 
00059       /* Remember that the system call is not available.  */
00060       __have_no_new_getrlimit = 1;
00061     }
00062 # endif
00063 
00064   /* Fall back to the old system call.  */
00065   result = INLINE_SYSCALL (getrlimit, 2, resource, CHECK_1 (rlimits));
00066 
00067   if (result == -1)
00068     return result;
00069 
00070   /* We might have to correct the limits values.  Since the old values
00071      were signed the infinity value is too small.  */
00072   if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
00073     rlimits->rlim_cur = RLIM_INFINITY;
00074   if (rlimits->rlim_max == RLIM_INFINITY >> 1)
00075     rlimits->rlim_max = RLIM_INFINITY;
00076 
00077   return result;
00078 #endif
00079 }
00080 
00081 weak_alias (__new_getrlimit, __getrlimit);
00082 versioned_symbol (libc, __new_getrlimit, getrlimit, GLIBC_2_2);