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