You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

  1. /* $Id: datalimit.c,v 1.5 2007/08/24 18:17:31 fabio Exp fabio $ */
  2. #ifndef HAVE_SYS_RESOURCE_H
  3. #define HAVE_SYS_RESOURCE_H 1
  4. #endif
  5. #ifndef HAVE_SYS_TIME_H
  6. #define HAVE_SYS_TIME_H 1
  7. #endif
  8. #ifndef HAVE_GETRLIMIT
  9. #define HAVE_GETRLIMIT 1
  10. #endif
  11. #if HAVE_SYS_RESOURCE_H == 1
  12. #if HAVE_SYS_TIME_H == 1
  13. #include <sys/time.h>
  14. #endif
  15. #include <sys/resource.h>
  16. #endif
  17. #ifndef RLIMIT_DATA_DEFAULT
  18. #define RLIMIT_DATA_DEFAULT 67108864 /* assume 64MB by default */
  19. #endif
  20. #ifndef EXTERN
  21. # ifdef __cplusplus
  22. # define EXTERN extern "C"
  23. # else
  24. # define EXTERN extern
  25. # endif
  26. #endif
  27. EXTERN unsigned long getSoftDataLimit(void);
  28. unsigned long
  29. getSoftDataLimit(void)
  30. {
  31. #if HAVE_SYS_RESOURCE_H == 1 && HAVE_GETRLIMIT == 1 && defined(RLIMIT_DATA)
  32. struct rlimit rl;
  33. int result;
  34. result = getrlimit(RLIMIT_DATA, &rl);
  35. if (result != 0 || rl.rlim_cur == RLIM_INFINITY)
  36. return((unsigned long) RLIMIT_DATA_DEFAULT);
  37. else
  38. return((unsigned long) rl.rlim_cur);
  39. #else
  40. return((unsigned long) RLIMIT_DATA_DEFAULT);
  41. #endif
  42. } /* end of getSoftDataLimit */