source: box/trunk/lib/common/BoxPlatform.h @ 3030

Revision 3030, 5.0 KB checked in by chris, 7 months ago (diff)

Avoid recompiling everything on MSVC when BoxVersion?.h changes.

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    BoxPlatform.h
5//              Purpose: Specifies what each platform supports in more detail, and includes
6//                               extra files to get basic support for types.
7//              Created: 2003/09/06
8//
9// --------------------------------------------------------------------------
10
11#ifndef BOXPLATFORM__H
12#define BOXPLATFORM__H
13
14#ifdef WIN32
15#define DIRECTORY_SEPARATOR                     "\\"
16#define DIRECTORY_SEPARATOR_ASCHAR              '\\'
17#else
18#define DIRECTORY_SEPARATOR                     "/"
19#define DIRECTORY_SEPARATOR_ASCHAR              '/'
20#endif
21
22#define PLATFORM_DEV_NULL                       "/dev/null"
23
24#ifdef _MSC_VER
25#include "BoxConfig-MSVC.h"
26#define NEED_BOX_VERSION_H
27#else
28#include "BoxConfig.h"
29#endif
30
31#ifdef WIN32
32        #ifdef __MSVCRT_VERSION__
33                #if __MSVCRT_VERSION__ < 0x0601
34                        #error Must include Box.h before sys/types.h
35                #endif
36        #else
37                // need msvcrt version 6.1 or higher for _gmtime64()
38                // must define this before importing <sys/types.h>
39                #define __MSVCRT_VERSION__ 0x0601
40        #endif
41#endif
42
43#ifdef HAVE_SYS_TYPES_H
44        #include <sys/types.h>
45#endif
46#ifdef HAVE_INTTYPES_H
47        #include <inttypes.h>
48#else
49        #ifdef HAVE_STDINT_H
50                #include <stdint.h>
51        #endif
52#endif
53
54// Slight hack; disable interception in raidfile test on Darwin and Windows
55#if defined __APPLE__ || defined WIN32
56        // TODO: Replace with autoconf test
57        #define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
58#endif
59
60// Disable memory testing under Darwin, it just doesn't like it very much.
61#ifdef __APPLE__
62        // TODO: We really should get some decent leak detection code.
63        #define PLATFORM_DISABLE_MEM_LEAK_TESTING
64#endif
65
66// Darwin also has a weird idea of permissions and dates on symlinks:
67// perms are fixed at creation time by your umask, and dates can't be
68// changed. This breaks unit tests if we try to compare these things.
69// See: http://lists.apple.com/archives/darwin-kernel/2006/Dec/msg00057.html
70#ifdef __APPLE__
71        #define PLATFORM_DISABLE_SYMLINK_ATTRIB_COMPARE
72#endif
73
74// Find out if credentials on UNIX sockets can be obtained
75#ifdef HAVE_GETPEEREID
76        //
77#elif HAVE_DECL_SO_PEERCRED
78        //
79#elif defined HAVE_UCRED_H && HAVE_GETPEERUCRED
80        //
81#else
82        #define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET
83#endif
84
85#ifdef HAVE_DEFINE_PRAGMA
86        // set packing to one bytes (can't use push/pop on gcc)
87        #define BEGIN_STRUCTURE_PACKING_FOR_WIRE        #pragma pack(1)
88
89        // Use default packing
90        #define END_STRUCTURE_PACKING_FOR_WIRE          #pragma pack()
91#else
92        #define STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS
93#endif
94
95// Handle differing xattr APIs
96#ifdef HAVE_SYS_XATTR_H
97        #if !defined(HAVE_LLISTXATTR) && defined(HAVE_LISTXATTR) && HAVE_DECL_XATTR_NOFOLLOW
98                #define llistxattr(a,b,c) listxattr(a,b,c,XATTR_NOFOLLOW)
99        #endif
100        #if !defined(HAVE_LGETXATTR) && defined(HAVE_GETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
101                #define lgetxattr(a,b,c,d) getxattr(a,b,c,d,0,XATTR_NOFOLLOW)
102        #endif
103        #if !defined(HAVE_LSETXATTR) && defined(HAVE_SETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
104                #define lsetxattr(a,b,c,d,e) setxattr(a,b,c,d,0,(e)|XATTR_NOFOLLOW)
105        #endif
106#endif
107
108#if defined WIN32 && !defined __MINGW32__
109        typedef __int8  int8_t;
110        typedef __int16 int16_t;
111        typedef __int32 int32_t;
112        typedef __int64 int64_t;
113
114        typedef unsigned __int8  u_int8_t;
115        typedef unsigned __int16 u_int16_t;
116        typedef unsigned __int32 u_int32_t;
117        typedef unsigned __int64 u_int64_t;
118
119        #define HAVE_U_INT8_T
120        #define HAVE_U_INT16_T
121        #define HAVE_U_INT32_T
122        #define HAVE_U_INT64_T
123#endif // WIN32 && !__MINGW32__
124
125// Define missing types
126#ifndef HAVE_UINT8_T
127        typedef u_int8_t uint8_t;
128#endif
129
130#ifndef HAVE_UINT16_T
131        typedef u_int16_t uint16_t;
132#endif
133
134#ifndef HAVE_UINT32_T
135        typedef u_int32_t uint32_t;
136#endif
137
138#ifndef HAVE_UINT64_T
139        typedef u_int64_t uint64_t;
140#endif
141
142#ifndef HAVE_U_INT8_T
143        typedef uint8_t u_int8_t;
144#endif
145
146#ifndef HAVE_U_INT16_T
147        typedef uint16_t u_int16_t;
148#endif
149
150#ifndef HAVE_U_INT32_T
151        typedef uint32_t u_int32_t;
152#endif
153
154#ifndef HAVE_U_INT64_T
155        typedef uint64_t u_int64_t;
156#endif
157
158#if !HAVE_DECL_INFTIM
159        #define INFTIM -1
160#endif
161
162// Define O_BINARY for Unix compatibility with Windows :-)
163// MSVC 2010 and newer MinGW define this in fcntl.h, which is probably
164// not included by this point, so include it now so that we can detect
165// if we need O_BINARY
166
167#ifdef HAVE_FCNTL_H
168#       include <fcntl.h>
169#endif
170
171#ifndef O_BINARY
172        #define O_BINARY 0
173#endif
174
175#ifdef WIN32
176        typedef u_int64_t InodeRefType;
177#else
178        typedef ino_t InodeRefType;
179#endif
180
181#ifdef WIN32
182        #define WIN32_LEAN_AND_MEAN
183#endif
184
185#include "emu.h"
186
187#ifdef WIN32
188        #define INVALID_FILE INVALID_HANDLE_VALUE
189        typedef HANDLE tOSFileHandle;
190#else
191        #define INVALID_FILE -1
192        typedef int tOSFileHandle;
193#endif
194
195// Solaris has no dirfd(x) macro or function, and we need one for
196// intercept tests. We cannot define macros with arguments directly
197// using AC_DEFINE, so do it here instead of in configure.ac.
198
199#if ! defined PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE && ! HAVE_DECL_DIRFD
200        #ifdef HAVE_DIR_D_FD
201                #define dirfd(x) (x)->d_fd
202        #elif defined HAVE_DIR_DD_FD
203                #define dirfd(x) (x)->dd_fd
204        #else
205                #error No way to get file descriptor from DIR structure
206        #endif
207#endif
208
209#endif // BOXPLATFORM__H
Note: See TracBrowser for help on using the repository browser.