1 #include <sys/resource.h> 2 #include <ulimit.h> 3 #include <stdarg.h> 4 #include <limits.h> 5 ulimit(int cmd,...)6long ulimit(int cmd, ...) 7 { 8 struct rlimit rl; 9 getrlimit(RLIMIT_FSIZE, &rl); 10 if (cmd == UL_SETFSIZE) { 11 long val; 12 va_list ap; 13 va_start(ap, cmd); 14 val = va_arg(ap, long); 15 va_end(ap); 16 rl.rlim_cur = 512ULL * val; 17 if (setrlimit(RLIMIT_FSIZE, &rl)) return -1; 18 } 19 return rl.rlim_cur == RLIM_INFINITY? LONG_MAX : rl.rlim_cur / 512; 20 } 21