OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.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 <sys/types.h>
32 #ifndef NO_SYS_PARAM_H
33 #include <sys/param.h>
34 #endif
35
36 #ifdef HAVE_SYSCONF
37 #include <unistd.h>
38 #define GNU_OUR_PAGESIZE sysconf(_SC_PAGESIZE)
39 #else
40 #ifdef  PAGESIZE
41 #define GNU_OUR_PAGESIZE PAGESIZE
42 #else   /* no PAGESIZE */
43 #ifdef  EXEC_PAGESIZE
44 #define GNU_OUR_PAGESIZE EXEC_PAGESIZE
45 #else   /* no EXEC_PAGESIZE */
46 #ifdef  NBPG
47 #define GNU_OUR_PAGESIZE (NBPG * CLSIZE)
48 #ifndef CLSIZE
49 #define CLSIZE 1
50 #endif  /* CLSIZE */
51 #else   /* no NBPG */
52 #ifdef  NBPC
53 #define GNU_OUR_PAGESIZE NBPC
54 #else   /* no NBPC */
55 #define GNU_OUR_PAGESIZE 4096   /* Just punt and use reasonable value */
56 #endif /* NBPC */
57 #endif /* NBPG */
58 #endif /* EXEC_PAGESIZE */
59 #endif /* PAGESIZE */
60 #endif /* HAVE_SYSCONF */
61
62 int
63 getpagesize ()
64 {
65   return (GNU_OUR_PAGESIZE);
66 }
67
68 #else /* VMS */
69
70 #if 0   /* older distributions of gcc-vms are missing <syidef.h> */
71 #include <syidef.h>
72 #endif
73 #ifndef SYI$_PAGE_SIZE  /* VMS V5.4 and earlier didn't have this yet */
74 #define SYI$_PAGE_SIZE 4452
75 #endif
76 extern unsigned long lib$getsyi(const unsigned short *,...);
77
78 int getpagesize ()
79 {
80   long pagsiz = 0L;
81   unsigned short itmcod = SYI$_PAGE_SIZE;
82
83   (void) lib$getsyi (&itmcod, (void *) &pagsiz);
84   if (pagsiz == 0L)
85     pagsiz = 512L;      /* VAX default */
86   return (int) pagsiz;
87 }
88
89 #endif /* VMS */