RetroArch
retro_common_api.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 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 #define __STDC_FORMAT_MACROS
93 #include <inttypes.h>
94 #endif
95 #ifndef PRId64
96 #error "inttypes.h is being screwy"
97 #endif
98 #define STRING_REP_INT64 "%" PRId64
99 #define STRING_REP_UINT64 "%" PRIu64
100 #define STRING_REP_USIZE "%" PRIuPTR
101 
102 /*
103 I would like to see retro_inline.h moved in here; possibly boolean too.
104 
105 rationale: these are used in public APIs, and it is easier to find problems
106 and write code that works the first time portably when theyre included uniformly
107 than to do the analysis from scratch each time you think you need it, for each feature.
108 
109 Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h,
110 then you should pay the price everywhere, so you can see how much grief it will cause.
111 
112 Of course, another school of thought is that you should do as little damage as possible
113 in as few places as possible...
114 */
115 
116 
117 /* _LIBRETRO_COMMON_RETRO_COMMON_API_H */
118 #endif