- extern long ulimit ();
-
- lim_data = -1;
-
- /* Use the ulimit call, if we seem to have it. */
-#if !defined (ULIMIT_BREAK_VALUE) || defined (GNU_LINUX)
- lim_data = ulimit (3, 0);
-#endif
-
- /* If that didn't work, just use the macro's value. */
-#ifdef ULIMIT_BREAK_VALUE
- if (lim_data == -1)
- lim_data = ULIMIT_BREAK_VALUE;
-#endif
-
- lim_data -= (long) data_space_start;
+ /* Set LIM_DATA to the minimum of the maximum object size and the
+ maximum address space. Don't bother to check for values like
+ RLIM_INFINITY since in practice they are not much less than SIZE_MAX. */
+ struct rlimit rlimit;
+ lim_data
+ = (getrlimit (RLIMIT_AS, &rlimit) == 0 && rlimit.rlim_cur <= SIZE_MAX
+ ? rlimit.rlim_cur
+ : SIZE_MAX);