1 /* 2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> 3 * 4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 5 */ 6 7 #include <sys/syscall.h> 8 9 #include <stdarg.h> 10 #include <unistd.h> 11 #include <ulimit.h> 12 #include <sys/resource.h> 13 14 ulimit(int cmd,...)15long int ulimit(int cmd, ...) 16 { 17 va_list va; 18 struct rlimit limit; 19 long int result = -1; 20 va_start (va, cmd); 21 switch (cmd) { 22 /* Get limit on file size. */ 23 case UL_GETFSIZE: 24 if (getrlimit(RLIMIT_FSIZE, &limit) == 0) 25 result = limit.rlim_cur / 512; /* bytes to 512 byte blocksize */ 26 break; 27 /* Set limit on file size. */ 28 case UL_SETFSIZE: 29 result = va_arg (va, long int); 30 if ((rlim_t) result > RLIM_INFINITY / 512) { 31 limit.rlim_cur = RLIM_INFINITY; 32 limit.rlim_max = RLIM_INFINITY; 33 } else { 34 limit.rlim_cur = result * 512; 35 limit.rlim_max = result * 512; 36 } 37 result = setrlimit(RLIMIT_FSIZE, &limit); 38 break; 39 case __UL_GETOPENMAX: 40 result = sysconf(_SC_OPEN_MAX); 41 break; 42 default: 43 __set_errno(EINVAL); 44 } 45 va_end (va); 46 return result; 47 } 48