-
Notifications
You must be signed in to change notification settings - Fork 1
/
core-foundation.h
executable file
·143 lines (117 loc) · 3.18 KB
/
core-foundation.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* tectonic/core-foundation.h: the first header to include in Tectonic's C/C++ code
Copyright 2016-2018 the Tectonic Project
Licensed under the MIT License.
*/
/* This header should (eventually ...) be included first in all of Tectonic's
* C/C++ files. It essentially concerns itself with defining basic types and
* portability.
*/
#ifndef TECTONIC_CORE_FOUNDATION_H
#define TECTONIC_CORE_FOUNDATION_H
/* High-level defines */
#define _DARWIN_USE_64_BIT_INODE 1
/* Some versions of g++ do not define PRId64 and friends unless we #define
* this before including inttypes.h. This was apparently an idea that was
* proposed for C++11 but didn't make it into the final standard. */
#define __STDC_FORMAT_MACROS
/* Universal headers */
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
/* Convenience for C++: this way Emacs doesn't try to indent the prototypes,
* which I find annoying. */
#ifdef __cplusplus
#define BEGIN_EXTERN_C extern "C" {
#define END_EXTERN_C }
#else
#define BEGIN_EXTERN_C
#define END_EXTERN_C
#endif
/* Portability: NORETURN annotation */
#if defined __GNUC__ && __GNUC__ >= 3
#define NORETURN __attribute__((__noreturn__))
#else
#define NORETURN
#endif
/* Portability: annotations to validate args of printf-like functions */
#if defined __GNUC__ && __GNUC__ >= 3
#define PRINTF_FUNC(ifmt,iarg) __attribute__((format(printf, ifmt, iarg)))
#else
#define PRINTF_FUNC(ifmt,iarg)
#endif
/* Portability: inline annotation */
#ifdef _MSC_VER
# ifndef __cplusplus
# define inline __inline
# endif
#endif
/* Portability: MSVC variations on various common functions */
#ifdef _MSC_VER
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
# define snprintf _snprintf
# define strtoll _strtoi64
# endif
#endif
/* Portability: ssize_t
*
* On Unix, sys/types.h gives ssize_t. On MSVC we need to do the following:
*/
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
/* Portability: M_PI
*
* MSVC doesn't always define it. Based on research, sometimes #defining
* _USE_MATH_DEFINES should fix the problem, but it's not clear if that
* *always* works in all versions, and it's easy to cut to the heart of the
* matter:
*/
#ifndef M_PI
# define M_PI 3.14159265358979
#endif
/* Portability: printf format arguments for various non-core types.
*
* <inttypes.h> ought to define these for most types. We use a custom one for
* size_t since older MSVC doesn't provide %z.
*/
#ifndef PRId64
# if defined(SIZEOF_LONG)
# if SIZEOF_LONG == 8
# define PRId64 "ld"
# else
# define PRId64 "lld"
# endif
# elif defined(_WIN32)
# define PRId64 "I64d"
# else
# error "unhandled compiler/platform for PRId64 definition"
# endif
#endif
#ifndef PRIdPTR
# define PRIdPTR "ld"
#endif
#ifndef PRIxPTR
# define PRIxPTR "lx"
#endif
#ifdef _WIN32
# define PRIuZ "Iu"
# define PRIXZ "IX"
#else
# define PRIuZ "zu"
# define PRIXZ "zX"
#endif
#endif /* not TECTONIC_CORE_FOUNDATION_H */