1570af302Sopenharmony_ci#include <sys/resource.h> 2570af302Sopenharmony_ci#include <ulimit.h> 3570af302Sopenharmony_ci#include <stdarg.h> 4570af302Sopenharmony_ci#include <limits.h> 5570af302Sopenharmony_ci 6570af302Sopenharmony_cilong ulimit(int cmd, ...) 7570af302Sopenharmony_ci{ 8570af302Sopenharmony_ci struct rlimit rl; 9570af302Sopenharmony_ci getrlimit(RLIMIT_FSIZE, &rl); 10570af302Sopenharmony_ci if (cmd == UL_SETFSIZE) { 11570af302Sopenharmony_ci long val; 12570af302Sopenharmony_ci va_list ap; 13570af302Sopenharmony_ci va_start(ap, cmd); 14570af302Sopenharmony_ci val = va_arg(ap, long); 15570af302Sopenharmony_ci va_end(ap); 16570af302Sopenharmony_ci rl.rlim_cur = 512ULL * val; 17570af302Sopenharmony_ci if (setrlimit(RLIMIT_FSIZE, &rl)) return -1; 18570af302Sopenharmony_ci } 19570af302Sopenharmony_ci return rl.rlim_cur == RLIM_INFINITY? LONG_MAX : rl.rlim_cur / 512; 20570af302Sopenharmony_ci} 21