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