GCS  0.2.3
gu_limits.h
1 // Copyright (C) 2008 Codership Oy <info@codership.com>
2 
9 #ifndef _gu_limits_h_
10 #define _gu_limits_h_
11 
12 #include <unistd.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 # if defined(__APPLE__)
18 long gu_darwin_phys_pages (void);
19 long gu_darwin_avphys_pages (void);
20 # elif defined(__FreeBSD__)
21 long gu_freebsd_avphys_pages (void);
22 # endif
23 #ifdef __cplusplus
24 }
25 #endif
26 
27 #if defined(__APPLE__)
28 static inline size_t gu_page_size() { return getpagesize(); }
29 static inline size_t gu_phys_pages() { return gu_darwin_phys_pages(); }
30 static inline size_t gu_avphys_pages() { return gu_darwin_avphys_pages(); }
31 #elif defined(__FreeBSD__)
32 static inline size_t gu_page_size() { return sysconf(_SC_PAGESIZE); }
33 static inline size_t gu_phys_pages() { return sysconf(_SC_PHYS_PAGES); }
34 static inline size_t gu_avphys_pages() { return gu_freebsd_avphys_pages(); }
35 #else /* !__APPLE__ && !__FreeBSD__ */
36 static inline size_t gu_page_size() { return sysconf(_SC_PAGESIZE); }
37 static inline size_t gu_phys_pages() { return sysconf(_SC_PHYS_PAGES); }
38 static inline size_t gu_avphys_pages() { return sysconf(_SC_AVPHYS_PAGES); }
39 #endif /* !__APPLE__ && !__FreeBSD__ */
40 
41 /* We need this as a compile-time constant. Runtime check is implemented
42  * in gu_init.c */
43 #define GU_PAGE_SIZE 4096
44 
45 static inline size_t gu_avphys_bytes()
46 {
47  // to detect overflow on systems with >4G of RAM, see #776
48  unsigned long long avphys = gu_avphys_pages(); avphys *= gu_page_size();
49  size_t max = -1;
50  return (avphys < max ? avphys : max);
51 }
52 
53 #include <limits.h>
54 
55 #define GU_ULONG_MAX ULONG_MAX
56 #define GU_LONG_MAX LONG_MAX
57 #define GU_LONG_MIN LONG_MIN
58 #define GU_ULONG_LONG_MAX ULLONG_MAX
59 #define GU_LONG_LONG_MAX LLONG_MAX
60 #define GU_LONG_LONG_MIN LLONG_MIN
61 
62 #endif /* _gu_limits_h_ */