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