9c0bb45783362d87d11593c192365c561ced95b2
[framework/uifw/xorg/lib/libxaw.git] / src / OS.c
1 /* Some OS-dependent utility code */
2
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6 #include <X11/Xosdefs.h>
7 #include <X11/IntrinsicP.h>
8 #include "Private.h"
9
10 #ifndef X_NOT_POSIX
11 #include <unistd.h>     /* for sysconf(), and getpagesize() */
12 #endif
13
14 #if defined(linux)
15 /* kernel header doesn't work with -ansi */
16 /* #include <asm/page.h> *//* for PAGE_SIZE */
17 #define HAS_GETPAGESIZE
18 #define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */
19 #endif
20
21 #if defined(CSRG_BASED)
22 #define HAS_GETPAGESIZE
23 #endif
24
25 #if defined(sun)
26 #define HAS_GETPAGESIZE
27 #endif
28
29 int
30 _XawGetPageSize(void)
31 {
32     static int pagesize = -1;
33
34     if (pagesize != -1)
35         return pagesize;
36
37     /* Try each supported method in the preferred order */
38
39 #if defined(_SC_PAGESIZE) || defined(HAS_SC_PAGESIZE)
40     pagesize = sysconf(_SC_PAGESIZE);
41 #endif
42
43 #ifdef _SC_PAGE_SIZE
44     if (pagesize == -1)
45         pagesize = sysconf(_SC_PAGE_SIZE);
46 #endif
47
48 #ifdef HAS_GETPAGESIZE
49     if (pagesize == -1)
50         pagesize = getpagesize();
51 #endif
52
53 #ifdef PAGE_SIZE
54     if (pagesize == -1)
55         pagesize = PAGE_SIZE;
56 #endif
57
58     if (pagesize == -1)
59         pagesize = 0;
60
61     return pagesize;
62 }