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