2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: ulimit.c /main/3 1995/11/01 16:30:47 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
29 * AT&T BELL LABORATORIES *
30 * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
31 * ACCORDANCE WITH APPLICABLE AGREEMENTS *
33 * Copyright (c) 1995 AT&T Corp. *
34 * Unpublished & Not for Publication *
35 * All Rights Reserved *
37 * The copyright notice above does not evidence any *
38 * actual or intended publication of such source code *
40 * This software was created by the *
41 * Advanced Software Technology Department *
42 * AT&T Bell Laboratories *
44 * For further information contact *
45 * {research,attmail}!dgk *
47 ***************************************************************/
49 /* : : generated by proto : : */
51 #if !defined(__PROTO__)
52 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
53 #if defined(__cplusplus)
54 #define __MANGLE__ "C"
59 #define __PROTO__(x) x
61 #define __PARAM__(n,o) n
62 #if !defined(__STDC__) && !defined(__cplusplus)
63 #if !defined(c_plusplus)
74 #define __PROTO__(x) ()
75 #define __OTORP__(x) x
76 #define __PARAM__(n,o) o
84 #if defined(__cplusplus) || defined(c_plusplus)
85 #define __VARARG__ ...
89 #if defined(__STDARG__)
90 #define __VA_START__(p,a) va_start(p,a)
92 #define __VA_START__(p,a) va_start(p)
100 #include <sys/resource.h>
102 #include "builtins.h"
106 int b_ulimit __PARAM__((int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[];__V_ *extra;){
110 error(ERROR_exit(2),e_nosupport);
118 int b_ulimit __PARAM__((int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[];__V_ *extra;){
119 register char *limit;
120 register int flag = 0, mode=0, n;
121 #ifdef _lib_getrlimit
123 #endif /* _lib_getrlimit */
125 int label, unit, noargs;
128 while((n = optget(argv,sh_optulimit))) switch(n)
147 # endif /* RLIMIT_RSS */
148 # ifdef RLIMIT_NOFILE
150 # endif /* RLIMIT_NOFILE */
153 # endif /* RLIMIT_VMEM */
163 # endif /* RLIMIT_RSS */
173 # ifdef RLIMIT_NOFILE
177 # endif /* RLIMIT_NOFILE */
182 # endif /* RLIMIT_VMEM */
183 #endif /* _lib_ulimit */
188 error(ERROR_usage(2), opt_arg);
191 limit = argv[opt_index];
195 /* only one option at a time for setting */
196 label = (flag&(flag-1));
197 if(error_info.errors || (limit && label) || argc>opt_index+1)
198 error(ERROR_usage(2),optusage((char*)0));
202 for(; flag; tp++,flag>>=1)
206 n = tp->sh_number>>11;
207 unit = tp->sh_number&0x7ff;
212 if(strcmp(limit,e_unlimited)==0)
217 if((i=sh_strnum(limit,&last)) < 0 || *last)
218 error(ERROR_system(1),e_number,limit);
221 #ifdef _lib_getrlimit
222 if(getrlimit(n,&rlp) <0)
223 error(ERROR_system(1),e_number,limit);
228 if(setrlimit(n,&rlp) <0)
229 error(ERROR_system(1),e_overlimit,limit);
231 if((i=vlimit(n,i)) < 0)
232 error(ERROR_system(1),e_number,limit);
233 #endif /* _lib_getrlimit */
237 #ifdef _lib_getrlimit
238 if(getrlimit(n,&rlp) <0)
239 error(ERROR_system(1),e_number,limit);
247 # endif /* _lib_ulimit */
249 if((i=vlimit(n,i)) < 0)
250 error(ERROR_system(1),e_number,limit);
251 #endif /* _lib_getrlimit */
253 sfputr(sfstdout,tp->sh_name,' ');
254 if(i!=INFINITY || noargs)
258 sfprintf(sfstdout,"%d\n",i/unit);
261 sfputr(sfstdout,e_unlimited,'\n');
266 #endif /* _no_ulimit */