-
Notifications
You must be signed in to change notification settings - Fork 19
/
types.h
116 lines (101 loc) · 3.36 KB
/
types.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
111
112
113
114
115
116
#ifndef _TYPES_H
#define _TYPES_H
/* include this file AFTER you have included libc files, since some libc's defines these, and get confused if predefined */
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
#else
#define __bswap_16(x) \
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
#define __bswap_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#define __bswap_64(x) \
((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
#endif
#ifdef WORDS_BIGENDIAN
# define int16_little(x) ((int16_t)(__bswap_16 (x)))
# define int32_little(x) ((int32_t)(__bswap_32 (x)))
# define uint16_little(x) ((uint16_t)(__bswap_16 (x)))
# define uint32_little(x) ((uint32_t)(__bswap_32 (x)))
# define uint64_little(x) ((uint16_t)(__bswap_64 (x)))
# define int16_big(x) (x)
# define int32_big(x) (x)
# define uint16_big(x) (x)
# define uint32_big(x) (x)
# define uint64_big(x) (x)
# else
# define int16_little(x) (x)
# define int32_little(x) (x)
# define uint16_little(x) (x)
# define uint32_little(x) (x)
# define uint64_little(x) (x)
# define int16_big(x) ((int16_t)(__bswap_16 (x)))
# define int32_big(x) ((int32_t)(__bswap_32 (x)))
# define uint16_big(x) ((uint16_t)(__bswap_16 (x)))
# define uint32_big(x) ((uint32_t)(__bswap_32 (x)))
# define uint64_big(x) ((uint64_t)(__bswap_64 (x)))
# endif
/* oddly this is declared in a glibc header, so not all GCC have it. */
#ifdef __GNUC__
# ifndef __GNUC_PREREQ
# define __GNUC_PREREQ(ma, mi) \
(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
# endif
#endif
/* Detect MacOS / OS-X */
#if defined(__APPLE__) && defined(__MACH__)
# ifdef HAVE_AVAILABILITY_H
# include <Availability.h>
# endif
# ifdef HAVE_AVAILABILITYVERSIONS_H
/* This header file is available from MacOS version 10.15 */
# include <AvailabilityVersions.h>
# endif
# ifdef HAVE_AVAILABILITYMACROS_H
# include <AvailabilityMacros.h>
# endif
# if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
# include <time.h>
# include <mach/clock_types.h>
# define CLOCK_REALTIME CALENDAR_CLOCK
# define CLOCK_MONOTONIC SYSTEM_CLOCK
# ifdef __cplusplus
extern "C" {
# endif
typedef int clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *tp);
# ifdef __cplusplus
}
# endif
# endif
#endif
# ifdef __HAIKU__
# ifdef ioctl
# undef ioctl
# endif
# endif
#ifdef _WIN32
# define localtime_r(a,b) (localtime_s(b,a)?0:b)
#endif
#ifdef _WIN32
#define OCP_INTERNAL
#else
#define OCP_INTERNAL __attribute__ ((visibility ("internal")))
#endif
#endif