Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* Copyright (C) 2010-2020 The RetroArch team |
2 | * | |
3 | * --------------------------------------------------------------------------------------- | |
4 | * The following license statement only applies to this file (retro_common_api.h). | |
5 | * --------------------------------------------------------------------------------------- | |
6 | * | |
7 | * Permission is hereby granted, free of charge, | |
8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
9 | * to deal in the Software without restriction, including without limitation the rights to | |
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | |
11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef _LIBRETRO_COMMON_RETRO_COMMON_API_H | |
24 | #define _LIBRETRO_COMMON_RETRO_COMMON_API_H | |
25 | ||
26 | /* | |
27 | This file is designed to normalize the libretro-common compiling environment | |
28 | for public API headers. This should be leaner than a normal compiling environment, | |
29 | since it gets #included into other project's sources. | |
30 | */ | |
31 | ||
32 | /* ------------------------------------ */ | |
33 | ||
34 | /* | |
35 | Ordinarily we want to put #ifdef __cplusplus extern "C" in C library | |
36 | headers to enable them to get used by c++ sources. | |
37 | However, we want to support building this library as C++ as well, so a | |
38 | special technique is called for. | |
39 | */ | |
40 | ||
41 | #define RETRO_BEGIN_DECLS | |
42 | #define RETRO_END_DECLS | |
43 | ||
44 | #ifdef __cplusplus | |
45 | ||
46 | #ifdef CXX_BUILD | |
47 | /* build wants everything to be built as c++, so no extern "C" */ | |
48 | #else | |
49 | #undef RETRO_BEGIN_DECLS | |
50 | #undef RETRO_END_DECLS | |
51 | #define RETRO_BEGIN_DECLS extern "C" { | |
52 | #define RETRO_END_DECLS } | |
53 | #endif | |
54 | ||
55 | #else | |
56 | ||
57 | /* header is included by a C source file, so no extern "C" */ | |
58 | ||
59 | #endif | |
60 | ||
61 | /* | |
62 | IMO, this non-standard ssize_t should not be used. | |
63 | However, it's a good example of how to handle something like this. | |
64 | */ | |
65 | #ifdef _MSC_VER | |
66 | #ifndef HAVE_SSIZE_T | |
67 | #define HAVE_SSIZE_T | |
68 | #if defined(_WIN64) | |
69 | typedef __int64 ssize_t; | |
70 | #elif defined(_WIN32) | |
71 | typedef int ssize_t; | |
72 | #endif | |
73 | #endif | |
74 | #elif defined(__MACH__) | |
75 | #include <sys/types.h> | |
76 | #endif | |
77 | ||
78 | #ifdef _MSC_VER | |
79 | #if _MSC_VER >= 1800 | |
80 | #include <inttypes.h> | |
81 | #else | |
82 | #ifndef PRId64 | |
83 | #define PRId64 "I64d" | |
84 | #define PRIu64 "I64u" | |
85 | #define PRIuPTR "Iu" | |
86 | #endif | |
87 | #endif | |
88 | #else | |
89 | /* C++11 says this one isn't needed, but apparently (some versions of) mingw require it anyways */ | |
90 | /* https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format */ | |
91 | /* https://github.com/libretro/RetroArch/issues/6009 */ | |
92 | #ifndef __STDC_FORMAT_MACROS | |
93 | #define __STDC_FORMAT_MACROS 1 | |
94 | #endif | |
95 | #include <inttypes.h> | |
96 | #endif | |
97 | #ifndef PRId64 | |
98 | #error "inttypes.h is being screwy" | |
99 | #endif | |
100 | #define STRING_REP_INT64 "%" PRId64 | |
101 | #define STRING_REP_UINT64 "%" PRIu64 | |
102 | #define STRING_REP_USIZE "%" PRIuPTR | |
103 | ||
104 | /* | |
105 | I would like to see retro_inline.h moved in here; possibly boolean too. | |
106 | ||
107 | rationale: these are used in public APIs, and it is easier to find problems | |
108 | and write code that works the first time portably when theyre included uniformly | |
109 | than to do the analysis from scratch each time you think you need it, for each feature. | |
110 | ||
111 | Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h, | |
112 | then you should pay the price everywhere, so you can see how much grief it will cause. | |
113 | ||
114 | Of course, another school of thought is that you should do as little damage as possible | |
115 | in as few places as possible... | |
116 | */ | |
117 | ||
118 | /* _LIBRETRO_COMMON_RETRO_COMMON_API_H */ | |
119 | #endif |