ulimit.c 432 B

1234567891011121314151617181920212223242526
  1. #include <errno.h>
  2. ulimit(cmd, newlimit)
  3. long newlimit;
  4. {
  5. extern int errno;
  6. struct {
  7. long soft, hard;
  8. } x;
  9. switch(cmd) {
  10. case 1:
  11. if (getrlimit(1, &x) < 0) return -1;
  12. return ((x.soft + 511) & ~511) >> 9;
  13. case 2:
  14. x.soft = x.hard = (newlimit << 9);
  15. if (setrlimit(1, &x) < 0) return -1;
  16. return x.soft;
  17. case 3:
  18. if (getrlimit(2, &x) < 0) return -1;
  19. return x.soft;
  20. default:
  21. errno = EINVAL;
  22. return -1;
  23. }
  24. }