The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
7.8KB

  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2012-2023 Xiph.Org Foundation
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * - Neither the name of the Xiph.org Foundation nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /* This is the preferred location of all CPP hackery to make $random_compiler
  32. * work like something approaching a C99 (or maybe more accurately GNU99)
  33. * compiler.
  34. *
  35. * It is assumed that this header will be included after "config.h".
  36. */
  37. #ifndef FLAC__SHARE__COMPAT_H
  38. #define FLAC__SHARE__COMPAT_H
  39. #include <stddef.h>
  40. #include <stdarg.h>
  41. #if defined _WIN32 && !defined __CYGWIN__
  42. /* where MSVC puts unlink() */
  43. # include <io.h>
  44. #else
  45. # include <unistd.h>
  46. #endif
  47. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  48. #include <sys/types.h> /* for off_t */
  49. #define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */
  50. #define FLAC__OFF_T_MAX INT64_MAX
  51. #if !defined __MINGW32__
  52. #define fseeko _fseeki64
  53. #define ftello _ftelli64
  54. #else /* MinGW */
  55. #if !defined(HAVE_FSEEKO)
  56. #define fseeko fseeko64
  57. #define ftello ftello64
  58. #endif
  59. #endif
  60. #else
  61. #define FLAC__off_t off_t
  62. #define FLAC__OFF_T_MAX OFF_T_MAX
  63. #endif
  64. #ifdef HAVE_INTTYPES_H
  65. #define __STDC_FORMAT_MACROS
  66. #include <inttypes.h>
  67. #endif
  68. #if defined(_MSC_VER)
  69. #define strtoll _strtoi64
  70. #define strtoull _strtoui64
  71. #endif
  72. #if defined(_MSC_VER) && !defined(__cplusplus)
  73. #define inline __inline
  74. #endif
  75. #if defined __INTEL_COMPILER || (defined _MSC_VER && defined _WIN64)
  76. /* MSVS generates VERY slow 32-bit code with __restrict */
  77. #define flac_restrict __restrict
  78. #elif defined __GNUC__
  79. #define flac_restrict __restrict__
  80. #else
  81. #define flac_restrict
  82. #endif
  83. #define FLAC__U64L(x) x##ULL
  84. #if defined _MSC_VER || defined __MINGW32__
  85. #define FLAC__STRCASECMP _stricmp
  86. #define FLAC__STRNCASECMP _strnicmp
  87. #elif defined __BORLANDC__
  88. #define FLAC__STRCASECMP stricmp
  89. #define FLAC__STRNCASECMP strnicmp
  90. #else
  91. #define FLAC__STRCASECMP strcasecmp
  92. #define FLAC__STRNCASECMP strncasecmp
  93. #endif
  94. #if defined _MSC_VER || defined __MINGW32__ || defined __EMX__
  95. #include <io.h> /* for _setmode(), chmod() */
  96. #include <fcntl.h> /* for _O_BINARY */
  97. #else
  98. #include <unistd.h> /* for chown(), unlink() */
  99. #endif
  100. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  101. #if defined __BORLANDC__
  102. #include <utime.h> /* for utime() */
  103. #else
  104. #include <sys/utime.h> /* for utime() */
  105. #endif
  106. #else
  107. #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
  108. #include <fcntl.h>
  109. #else
  110. #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
  111. #include <utime.h> /* for utime() */
  112. #endif
  113. #endif
  114. #if defined _MSC_VER
  115. # if _MSC_VER >= 1800
  116. # include <inttypes.h>
  117. # elif _MSC_VER >= 1600
  118. /* Visual Studio 2010 has decent C99 support */
  119. # include <stdint.h>
  120. # define PRIu64 "llu"
  121. # define PRId64 "lld"
  122. # define PRIx64 "llx"
  123. # else
  124. # include <limits.h>
  125. # ifndef UINT32_MAX
  126. # define UINT32_MAX _UI32_MAX
  127. # endif
  128. # define PRIu64 "I64u"
  129. # define PRId64 "I64d"
  130. # define PRIx64 "I64x"
  131. # endif
  132. # if defined(_USING_V110_SDK71_) && !defined(_DLL)
  133. # pragma message("WARNING: This compile will NOT FUNCTION PROPERLY on Windows XP. See comments in include/share/compat.h for details")
  134. #define FLAC__USE_FILELENGTHI64
  135. /*
  136. *************************************************************************************
  137. * V110_SDK71, in MSVC 2017 also known as v141_xp, is a platform toolset that is supposed
  138. * to target Windows XP. It turns out however that certain functions provided silently fail
  139. * on Windows XP only, which makes debugging challenging. This only occurs when building with
  140. * /MT. This problem has been reported to Microsoft, but there hasn't been a fix for years. See
  141. * https://web.archive.org/web/20170327195018/https://connect.microsoft.com/VisualStudio/feedback/details/1557168/wstat64-returns-1-on-xp-always
  142. *
  143. * It is known that this problem affects the functions _wstat64 (used by flac_stat i.e.
  144. * stat64_utf8) and _fstat64 (i.e. flac_fstat) and therefore affects both libFLAC in
  145. * several places as well as the flac and metaflac command line tools
  146. *
  147. * As the extent of this problem is unknown and Microsoft seems unwilling to fix it,
  148. * users of libFLAC building with Visual Studio are encouraged to not use the /MT compile
  149. * switch when explicitly targeting Windows XP. When use of /MT is deemed necessary with
  150. * this toolset, be sure to check whether your application works properly on Windows XP.
  151. * It is also possible to build for Windows XP with MinGW instead.
  152. *************************************************************************************
  153. */
  154. # endif
  155. #endif /* defined _MSC_VER */
  156. #ifdef _WIN32
  157. /* All char* strings are in UTF-8 format. Added to support Unicode files on Windows */
  158. #if 0
  159. #include "win_utf8_io.h"
  160. #define flac_printf printf_utf8
  161. #define flac_fprintf fprintf_utf8
  162. #define flac_vfprintf vfprintf_utf8
  163. #endif
  164. #define flac_fopen fopen_utf8
  165. #define flac_chmod chmod_utf8
  166. #define flac_utime utime_utf8
  167. #define flac_unlink unlink_utf8
  168. #define flac_rename rename_utf8
  169. #define flac_stat stat64_utf8
  170. #else
  171. #define flac_printf printf
  172. #define flac_fprintf fprintf
  173. #define flac_vfprintf vfprintf
  174. #define flac_fopen fopen
  175. #define flac_chmod chmod
  176. #define flac_unlink unlink
  177. #define flac_rename rename
  178. #define flac_stat stat
  179. #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
  180. #define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0)
  181. #else
  182. #define flac_utime utime
  183. #endif
  184. #endif
  185. #ifdef _WIN32
  186. #define flac_stat_s __stat64 /* stat struct */
  187. #define flac_fstat _fstat64
  188. #else
  189. #define flac_stat_s stat /* stat struct */
  190. #define flac_fstat fstat
  191. #endif
  192. #ifdef ANDROID
  193. #include <limits.h>
  194. #endif
  195. #ifndef M_LN2
  196. #define M_LN2 0.69314718055994530942
  197. #endif
  198. #ifndef M_PI
  199. #define M_PI 3.14159265358979323846
  200. #endif
  201. /* FLAC needs to compile and work correctly on systems with a normal ISO C99
  202. * snprintf as well as Microsoft Visual Studio which has an non-standards
  203. * conformant snprint_s function.
  204. *
  205. * This function wraps the MS version to behave more like the ISO version.
  206. */
  207. #ifdef __cplusplus
  208. extern "C" {
  209. #endif
  210. int flac_snprintf(char *str, size_t size, const char *fmt, ...);
  211. int flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va);
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215. #endif /* FLAC__SHARE__COMPAT_H */