1 /* Copyright (C) 1991,92,1994-1998,2000,2001,2008
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <sys/resource.h>
27 /* Function depends on CMD:
28 1 = Return the limit on the size of a file, in units of 512 bytes.
29 2 = Set the limit on the size of a file to NEWLIMIT. Only the
30 super-user can increase the limit.
31 3 = illegal due to shared libraries; normally is
32 (Return the maximum possible address of the data segment.)
33 4 = Return the maximum number of files that the calling process
35 Returns -1 on errors. */
37 __ulimit (int cmd
, ...)
48 /* Get limit on file size. */
49 if (__getrlimit (RLIMIT_FSIZE
, &limit
) == 0)
50 /* Convert from bytes to 512 byte units. */
51 result
= (limit
.rlim_cur
== RLIM_INFINITY
52 ? LONG_MAX
: limit
.rlim_cur
/ 512);
56 /* Set limit on file size. */
58 long int newlimit
= va_arg (va
, long int);
61 if ((rlim_t
) newlimit
> RLIM_INFINITY
/ 512)
63 limit
.rlim_cur
= RLIM_INFINITY
;
64 limit
.rlim_max
= RLIM_INFINITY
;
69 limit
.rlim_cur
= newlimit
* 512;
70 limit
.rlim_max
= newlimit
* 512;
74 result
= __setrlimit (RLIMIT_FSIZE
, &limit
);
81 result
= __sysconf (_SC_OPEN_MAX
);
93 weak_alias (__ulimit
, ulimit
);