Subversion Repositories eduke32

Rev

Rev 4747 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4747 Rev 4762
Line 3... Line 3...
3
// by different platforms.
3
// by different platforms.
4
4
5
#ifndef compat_h_
5
#ifndef compat_h_
6
#define compat_h_
6
#define compat_h_
7
7
8
#include <malloc.h>
-
 
9
-
 
10
#ifdef _WIN32
-
 
11
# define WIN32_LEAN_AND_MEAN
-
 
12
# include <windows.h>
-
 
13
#endif
-
 
14
-
 
15
#ifdef __APPLE__
-
 
16
# include <TargetConditionals.h>
-
 
17
# if !TARGET_OS_IPHONE
-
 
18
#  if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
-
 
19
#   include <CoreFoundation/CoreFoundation.h>
-
 
20
#  endif
-
 
21
#  include <CoreServices/CoreServices.h>
-
 
22
# endif
-
 
23
#endif
-
 
24
-
 
25
#ifdef __GNUC__
8
#ifdef __GNUC__
26
# define EDUKE32_GCC_PREREQ(major, minor) (major > __GNUC__ || (major == __GNUC__ && minor >= __GNUC_MINOR__))
9
# define EDUKE32_GCC_PREREQ(major, minor) (major < __GNUC__ || (major == __GNUC__ && minor <= __GNUC_MINOR__))
27
#else
10
#else
28
# define EDUKE32_GCC_PREREQ(major, minor) 0
11
# define EDUKE32_GCC_PREREQ(major, minor) 0
29
#endif
12
#endif
30
13
31
#ifdef __clang__
14
#ifdef __clang__
32
# define EDUKE32_CLANG_PREREQ(major, minor) (major > __clang_major__ || (major == __clang_major__ && minor >= __clang_minor__))
15
# define EDUKE32_CLANG_PREREQ(major, minor) (major < __clang_major__ || (major == __clang_major__ && minor <= __clang_minor__))
33
#else
16
#else
34
# define EDUKE32_CLANG_PREREQ(major, minor) 0
17
# define EDUKE32_CLANG_PREREQ(major, minor) 0
35
#endif
18
#endif
36
#ifndef __has_builtin
19
#ifndef __has_builtin
37
# define __has_builtin(x) 0  // Compatibility with non-clang compilers.
20
# define __has_builtin(x) 0  // Compatibility with non-clang compilers.
Line 82... Line 65...
82
#endif
65
#endif
83
#ifndef max
66
#ifndef max
84
#define max(x,y) ((x) > (y) ? (x) : (y))
67
#define max(x,y) ((x) > (y) ? (x) : (y))
85
#endif
68
#endif
86
69
-
 
70
#ifndef __APPLE__
-
 
71
# include <malloc.h>
-
 
72
#endif
-
 
73
-
 
74
#ifdef _WIN32
-
 
75
# define WIN32_LEAN_AND_MEAN
-
 
76
# include <windows.h>
-
 
77
#endif
-
 
78
-
 
79
#ifdef __APPLE__
-
 
80
# include <TargetConditionals.h>
-
 
81
# if !TARGET_OS_IPHONE
-
 
82
#  if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
-
 
83
#   include <CoreFoundation/CoreFoundation.h>
-
 
84
#  endif
-
 
85
#  include <CoreServices/CoreServices.h>
-
 
86
# endif
-
 
87
#endif
-
 
88
87
// This gives us access to 'intptr_t' and 'uintptr_t', which are
89
// This gives us access to 'intptr_t' and 'uintptr_t', which are
88
// abstractions to the size of a pointer on a given platform
90
// abstractions to the size of a pointer on a given platform
89
// (ie, they're guaranteed to be the same size as a pointer)
91
// (ie, they're guaranteed to be the same size as a pointer)
90
92
91
#undef __USE_MINGW_ANSI_STDIO // Workaround for MinGW-w64.
93
#undef __USE_MINGW_ANSI_STDIO // Workaround for MinGW-w64.
92
94
-
 
95
#ifndef __STDC_FORMAT_MACROS
93
#define __STDC_FORMAT_MACROS
96
#define __STDC_FORMAT_MACROS
-
 
97
#endif
94
#ifndef __STDC_LIMIT_MACROS
98
#ifndef __STDC_LIMIT_MACROS
95
# define __STDC_LIMIT_MACROS
99
# define __STDC_LIMIT_MACROS
96
#endif
100
#endif
97
#if defined(HAVE_INTTYPES) || defined(__cplusplus)
101
#if defined(HAVE_INTTYPES) || defined(__cplusplus)
98
# include <stdint.h>
102
# include <stdint.h>
Line 613... Line 617...
613
# else
617
# else
614
#  define Bstrdup strdup
618
#  define Bstrdup strdup
615
#  define Bchdir chdir
619
#  define Bchdir chdir
616
#  define Bgetcwd getcwd
620
#  define Bgetcwd getcwd
617
# endif
621
# endif
618
# define Bmemalign memalign
-
 
619
# define Bopen open
622
# define Bopen open
620
# define Bclose close
623
# define Bclose close
621
# define Bwrite write
624
# define Bwrite write
622
# define Bread read
625
# define Bread read
623
# define Blseek lseek
626
# define Blseek lseek
Line 844... Line 847...
844
847
845
FORCE_INLINE void *xaligned_malloc(const bsize_t alignment, const bsize_t size)
848
FORCE_INLINE void *xaligned_malloc(const bsize_t alignment, const bsize_t size)
846
{
849
{
847
#ifdef _WIN32
850
#ifdef _WIN32
848
    void *ptr = _aligned_malloc(size, alignment);
851
    void *ptr = _aligned_malloc(size, alignment);
-
 
852
#elif defined __APPLE__
-
 
853
    void *ptr = NULL;
-
 
854
    posix_memalign(&ptr, alignment, size);
849
#else
855
#else
850
    void *ptr = memalign(alignment, size);
856
    void *ptr = memalign(alignment, size);
851
#endif
857
#endif
852
858
853
    if (ptr == NULL) handle_memerr();
859
    if (ptr == NULL) handle_memerr();