home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / malloc / mem-limits.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-22  |  2.8 KB  |  124 lines

  1. /* Includes for memory limit warnings.
  2.    Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  3.  
  4.  
  5. This file is part of the GNU C Library.
  6.  
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11.  
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. Library General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB.  If
  19. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  20. Cambridge, MA 02139, USA.  */
  21.  
  22. #ifndef BSD4_2
  23. #ifndef USG
  24. #include <sys/vlimit.h>
  25. #endif /* not USG */
  26. #else /* if BSD4_2 */
  27. #include <sys/time.h>
  28. #include <sys/resource.h>
  29. #endif /* BSD4_2 */
  30.  
  31. #ifdef emacs
  32. /* The important properties of this type are that 1) it's a pointer, and
  33.    2) arithmetic on it should work as if the size of the object pointed
  34.    to has a size of 1.  */
  35. #ifdef __STDC__
  36. typedef void *POINTER;
  37. #else
  38. typedef char *POINTER;
  39. #endif
  40.  
  41. typedef unsigned long SIZE;
  42.  
  43. #ifdef NULL
  44. #undef NULL
  45. #endif
  46. #define NULL ((POINTER) 0)
  47.  
  48. extern POINTER start_of_data ();
  49. #ifdef DATA_SEG_BITS
  50. #define EXCEEDS_LISP_PTR(ptr) \
  51.   (((unsigned int) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
  52. #else
  53. #define EXCEEDS_LISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
  54. #endif
  55.  
  56. #ifdef BSD
  57. #ifndef DATA_SEG_BITS
  58. extern char etext;
  59. #define start_of_data() &etext
  60. #endif
  61. #endif
  62.  
  63. #else  /* Not emacs */ 
  64. extern char etext;
  65. #define start_of_data() &etext
  66. #endif /* Not emacs */
  67.  
  68.   
  69.  
  70. /* start of data space; can be changed by calling malloc_init */
  71. static POINTER data_space_start;
  72.  
  73. /* Number of bytes of writable memory we can expect to be able to get */
  74. static unsigned int lim_data;
  75.  
  76. #ifdef USG
  77.  
  78. static void
  79. get_lim_data ()
  80. {
  81.   extern long ulimit ();
  82.  
  83.   lim_data = -1;
  84.  
  85.   /* Use the ulimit call, if we seem to have it.  */
  86. #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
  87.   lim_data = ulimit (3, 0);
  88. #endif
  89.  
  90.   /* If that didn't work, just use the macro's value.  */
  91. #ifdef ULIMIT_BREAK_VALUE
  92.   if (lim_data == -1)
  93.     lim_data = ULIMIT_BREAK_VALUE;
  94. #endif
  95.  
  96.   lim_data -= (long) data_space_start;
  97. }
  98.  
  99. #else /* not USG */
  100. #ifndef BSD4_2
  101.  
  102. static void
  103. get_lim_data ()
  104. {
  105.   lim_data = vlimit (LIM_DATA, -1);
  106. }
  107.  
  108. #else /* BSD4_2 */
  109.  
  110. static void
  111. get_lim_data ()
  112. {
  113.   struct rlimit XXrlimit;
  114.  
  115.   getrlimit (RLIMIT_DATA, &XXrlimit);
  116. #ifdef RLIM_INFINITY
  117.   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  118. #else
  119.   lim_data = XXrlimit.rlim_cur;    /* soft limit */
  120. #endif
  121. }
  122. #endif /* BSD4_2 */
  123. #endif /* not USG */
  124.