Update.
[glibc.git] / sysdeps / mach / hurd / setrlimit.c
blob3fc9035dffa1ba764f427fcd0352cc632468a7db
1 /* Copyright (C) 1991, 1992, 1993, 1994, 1997 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 <hurd.h>
20 #include <hurd/resource.h>
21 #include <errno.h>
22 #include <hurd/fd.h>
25 /* Set the soft and hard limits for RESOURCE to *RLIMITS.
26 Only the super-user can increase hard limits.
27 Return 0 if successful, -1 if not (and sets errno). */
28 /* XXX should be __setrlimit ? */
29 int
30 setrlimit (resource, rlimits)
31 enum __rlimit_resource resource;
32 struct rlimit *rlimits;
34 struct rlimit lim;
36 if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
38 errno = EINVAL;
39 return -1;
42 lim = *rlimits;
44 if (lim.rlim_max != RLIM_INFINITY)
46 /* We have no enforceable resource limits. */
47 errno = ENOSYS;
48 return -1;
51 if (lim.rlim_cur > lim.rlim_max)
52 lim.rlim_cur = lim.rlim_max;
54 __mutex_lock (&_hurd_rlimit_lock);
55 _hurd_rlimits[resource] = lim;
56 __mutex_unlock (&_hurd_rlimit_lock);
58 return 0;