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