retro_common_api.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifndef _LIBRETRO_COMMON_RETRO_COMMON_API_H
  23. #define _LIBRETRO_COMMON_RETRO_COMMON_API_H
  24. /*
  25. This file is designed to normalize the libretro-common compiling environment
  26. for public API headers. This should be leaner than a normal compiling environment,
  27. since it gets #included into other project's sources.
  28. */
  29. /* ------------------------------------ */
  30. /*
  31. Ordinarily we want to put #ifdef __cplusplus extern "C" in C library
  32. headers to enable them to get used by c++ sources.
  33. However, we want to support building this library as C++ as well, so a
  34. special technique is called for.
  35. */
  36. #define RETRO_BEGIN_DECLS
  37. #define RETRO_END_DECLS
  38. #ifdef __cplusplus
  39. #ifdef CXX_BUILD
  40. /* build wants everything to be built as c++, so no extern "C" */
  41. #else
  42. #undef RETRO_BEGIN_DECLS
  43. #undef RETRO_END_DECLS
  44. #define RETRO_BEGIN_DECLS extern "C" {
  45. #define RETRO_END_DECLS }
  46. #endif
  47. #else
  48. /* header is included by a C source file, so no extern "C" */
  49. #endif
  50. /*
  51. IMO, this non-standard ssize_t should not be used.
  52. However, it's a good example of how to handle something like this.
  53. */
  54. #ifdef _MSC_VER
  55. #ifndef HAVE_SSIZE_T
  56. #define HAVE_SSIZE_T
  57. #if defined(_WIN64)
  58. typedef __int64 ssize_t;
  59. #elif defined(_WIN32)
  60. typedef int ssize_t;
  61. #endif
  62. #endif
  63. #elif defined(__MACH__)
  64. #include <sys/types.h>
  65. #endif
  66. #ifdef _MSC_VER
  67. #if _MSC_VER >= 1800
  68. #include <inttypes.h>
  69. #else
  70. #ifndef PRId64
  71. #define PRId64 "I64d"
  72. #define PRIu64 "I64u"
  73. #define PRIuPTR "Iu"
  74. #endif
  75. #endif
  76. #else
  77. /* C++11 says this one isn't needed, but apparently (some versions of) mingw require it anyways */
  78. /* https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format */
  79. /* https://github.com/libretro/RetroArch/issues/6009 */
  80. #ifndef __STDC_FORMAT_MACROS
  81. #define __STDC_FORMAT_MACROS 1
  82. #endif
  83. #include <inttypes.h>
  84. #endif
  85. #ifndef PRId64
  86. #error "inttypes.h is being screwy"
  87. #endif
  88. #define STRING_REP_INT64 "%" PRId64
  89. #define STRING_REP_UINT64 "%" PRIu64
  90. #define STRING_REP_USIZE "%" PRIuPTR
  91. /*
  92. I would like to see retro_inline.h moved in here; possibly boolean too.
  93. rationale: these are used in public APIs, and it is easier to find problems
  94. and write code that works the first time portably when theyre included uniformly
  95. than to do the analysis from scratch each time you think you need it, for each feature.
  96. Moreover it helps force you to make hard decisions: if you EVER bring in boolean.h,
  97. then you should pay the price everywhere, so you can see how much grief it will cause.
  98. Of course, another school of thought is that you should do as little damage as possible
  99. in as few places as possible...
  100. */
  101. /* _LIBRETRO_COMMON_RETRO_COMMON_API_H */
  102. #endif