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