getpagesize.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Emulation of getpagesize() for systems that need it. */
  2. /*
  3. @deftypefn Supplemental int getpagesize (void)
  4. Returns the number of bytes in a page of memory. This is the
  5. granularity of many of the system memory management routines. No
  6. guarantee is made as to whether or not it is the same as the basic
  7. memory management hardware page size.
  8. @end deftypefn
  9. BUGS
  10. Is intended as a reasonable replacement for systems where this
  11. is not provided as a system call. The value of 4096 may or may
  12. not be correct for the systems where it is returned as the default
  13. value.
  14. */
  15. #ifndef VMS
  16. #include "config.h"
  17. #include <sys/types.h>
  18. #ifdef HAVE_SYS_PARAM_H
  19. #include <sys/param.h>
  20. #endif
  21. #undef GNU_OUR_PAGESIZE
  22. #if defined (HAVE_SYSCONF) && defined (HAVE_UNISTD_H)
  23. #include <unistd.h>
  24. #ifdef _SC_PAGESIZE
  25. #define GNU_OUR_PAGESIZE sysconf(_SC_PAGESIZE)
  26. #endif
  27. #endif
  28. #ifndef GNU_OUR_PAGESIZE
  29. # ifdef PAGESIZE
  30. # define GNU_OUR_PAGESIZE PAGESIZE
  31. # else /* no PAGESIZE */
  32. # ifdef EXEC_PAGESIZE
  33. # define GNU_OUR_PAGESIZE EXEC_PAGESIZE
  34. # else /* no EXEC_PAGESIZE */
  35. # ifdef NBPG
  36. # define GNU_OUR_PAGESIZE (NBPG * CLSIZE)
  37. # ifndef CLSIZE
  38. # define CLSIZE 1
  39. # endif /* CLSIZE */
  40. # else /* no NBPG */
  41. # ifdef NBPC
  42. # define GNU_OUR_PAGESIZE NBPC
  43. # else /* no NBPC */
  44. # define GNU_OUR_PAGESIZE 4096 /* Just punt and use reasonable value */
  45. # endif /* NBPC */
  46. # endif /* NBPG */
  47. # endif /* EXEC_PAGESIZE */
  48. # endif /* PAGESIZE */
  49. #endif /* GNU_OUR_PAGESIZE */
  50. int
  51. getpagesize (void)
  52. {
  53. return (GNU_OUR_PAGESIZE);
  54. }
  55. #else /* VMS */
  56. #if 0 /* older distributions of gcc-vms are missing <syidef.h> */
  57. #include <syidef.h>
  58. #endif
  59. #ifndef SYI$_PAGE_SIZE /* VMS V5.4 and earlier didn't have this yet */
  60. #define SYI$_PAGE_SIZE 4452
  61. #endif
  62. extern unsigned long lib$getsyi(const unsigned short *,...);
  63. int getpagesize (void)
  64. {
  65. long pagsiz = 0L;
  66. unsigned short itmcod = SYI$_PAGE_SIZE;
  67. (void) lib$getsyi (&itmcod, (void *) &pagsiz);
  68. if (pagsiz == 0L)
  69. pagsiz = 512L; /* VAX default */
  70. return (int) pagsiz;
  71. }
  72. #endif /* VMS */