Back to index

cell-binutils  2.17cvs20070401
getpagesize.c
Go to the documentation of this file.
00001 /* Emulation of getpagesize() for systems that need it. */
00002 
00003 /*
00004 
00005 @deftypefn Supplemental int getpagesize (void)
00006 
00007 Returns the number of bytes in a page of memory.  This is the
00008 granularity of many of the system memory management routines.  No
00009 guarantee is made as to whether or not it is the same as the basic
00010 memory management hardware page size.
00011 
00012 @end deftypefn
00013 
00014 BUGS
00015 
00016        Is intended as a reasonable replacement for systems where this
00017        is not provided as a system call.  The value of 4096 may or may
00018        not be correct for the systems where it is returned as the default
00019        value.
00020 
00021 */
00022 
00023 #ifndef VMS
00024 
00025 #include "config.h"
00026 
00027 #include <sys/types.h>
00028 #ifdef HAVE_SYS_PARAM_H
00029 #include <sys/param.h>
00030 #endif
00031 
00032 #undef GNU_OUR_PAGESIZE
00033 #if defined (HAVE_SYSCONF) && defined (HAVE_UNISTD_H)
00034 #include <unistd.h>
00035 #ifdef _SC_PAGESIZE
00036 #define GNU_OUR_PAGESIZE sysconf(_SC_PAGESIZE)
00037 #endif
00038 #endif
00039 
00040 #ifndef GNU_OUR_PAGESIZE
00041 # ifdef       PAGESIZE
00042 #  define     GNU_OUR_PAGESIZE PAGESIZE
00043 # else /* no PAGESIZE */
00044 #  ifdef      EXEC_PAGESIZE
00045 #   define    GNU_OUR_PAGESIZE EXEC_PAGESIZE
00046 #  else       /* no EXEC_PAGESIZE */
00047 #   ifdef     NBPG
00048 #    define   GNU_OUR_PAGESIZE (NBPG * CLSIZE)
00049 #    ifndef   CLSIZE
00050 #     define  CLSIZE 1
00051 #    endif    /* CLSIZE */
00052 #   else      /* no NBPG */
00053 #    ifdef    NBPC
00054 #     define  GNU_OUR_PAGESIZE NBPC
00055 #    else     /* no NBPC */
00056 #     define  GNU_OUR_PAGESIZE 4096       /* Just punt and use reasonable value */
00057 #    endif /* NBPC */
00058 #   endif /* NBPG */
00059 #  endif /* EXEC_PAGESIZE */
00060 # endif /* PAGESIZE */
00061 #endif /* GNU_OUR_PAGESIZE */
00062 
00063 int
00064 getpagesize (void)
00065 {
00066   return (GNU_OUR_PAGESIZE);
00067 }
00068 
00069 #else /* VMS */
00070 
00071 #if 0  /* older distributions of gcc-vms are missing <syidef.h> */
00072 #include <syidef.h>
00073 #endif
00074 #ifndef SYI$_PAGE_SIZE      /* VMS V5.4 and earlier didn't have this yet */
00075 #define SYI$_PAGE_SIZE 4452
00076 #endif
00077 extern unsigned long lib$getsyi(const unsigned short *,...);
00078 
00079 int getpagesize (void)
00080 {
00081   long pagsiz = 0L;
00082   unsigned short itmcod = SYI$_PAGE_SIZE;
00083 
00084   (void) lib$getsyi (&itmcod, (void *) &pagsiz);
00085   if (pagsiz == 0L)
00086     pagsiz = 512L;   /* VAX default */
00087   return (int) pagsiz;
00088 }
00089 
00090 #endif /* VMS */