-
Notifications
You must be signed in to change notification settings - Fork 20
/
platform.h
110 lines (73 loc) · 1.93 KB
/
platform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
MIT license slip
Compatibility header for alternative build targets (MSVC - win32/64)
*/
#ifndef __PLATFORM_H__
#define __PLATFORM_H__ 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#define __builtin_bswap16 _byteswap_ushort
#define __builtin_bswap32 _byteswap_ulong
#define __builtin_bswap64 _byteswap_uint64
#define fseek _fseeki64
#define _CRT_SECURE_NO_WARNINGS 1
#define PACKED
/* Assume that win32 platform runs on intel or little endian ARM */
#define __ORDER_LITTLE_ENDIAN__ 1
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#elif __GNUC__
#define PACKED __attribute__( ( __packed__ ) )
#else //elif __MINGW32__
#error Compiler is not supported.
#endif
#ifdef __linux__
//linux code goes here
#include <sys/types.h>
#define PATH_SEPARATOR '/'
#define PATH_SEPARATOR_STR "/"
#define _FILE_OFFSET_BITS 64
typedef off_t off64_t;
#elif __APPLE__
#include <sys/types.h>
#define PATH_SEPARATOR '/'
#define PATH_SEPARATOR_STR "/"
#define _FILE_OFFSET_BITS 64
typedef off_t off64_t;
#elif _WIN32
// windows code goes here
#include <direct.h>
#define PATH_SEPARATOR '\\'
#define PATH_SEPARATOR_STR "\\"
typedef long long int off64_t;
#endif
//And a few universal definitions useful everywhere
int imin( int a, int b ) {
return a < b ? a : b;
}
unsigned int umin( unsigned int a, unsigned int b ) {
return a < b ? a : b;
}
long long int lmin( long long int a, long long int b ) {
return a < b ? a : b;
}
unsigned long long int ulmin( unsigned long long int a, unsigned long long int b ) {
return a < b ? a : b;
}
int imax( int a, int b ) {
return a > b ? a : b;
}
unsigned int umax( unsigned int a, unsigned int b ) {
return a > b ? a : b;
}
long long int lmax( long long int a, long long int b ) {
return a > b ? a : b;
}
unsigned long long int ulmax( unsigned long long int a, unsigned long long int b ) {
return a > b ? a : b;
}
#ifdef __cplusplus
}
#endif
#endif /* __PLATFORM_H__ */