1 /* libFLAC - Free Lossless Audio Codec library 2 * Copyright (C) 2012-2022 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 32 /* This is the preferred location of all CPP hackery to make $random_compiler 33 * work like something approaching a C99 (or maybe more accurately GNU99) 34 * compiler. 35 * 36 * It is assumed that this header will be included after "config.h". 37 */ 38 39 #ifndef FLAC__SHARE__COMPAT_H 40 #define FLAC__SHARE__COMPAT_H 41 42 #include <stddef.h> 43 #include <stdarg.h> 44 45 #if defined _WIN32 && !defined __CYGWIN__ 46 /* where MSVC puts unlink() */ 47 # include <io.h> 48 #else 49 # include <unistd.h> 50 #endif 51 52 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ 53 #include <sys/types.h> /* for off_t */ 54 #define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */ 55 #if !defined __MINGW32__ 56 #define fseeko _fseeki64 57 #define ftello _ftelli64 58 #else /* MinGW */ 59 #if !defined(HAVE_FSEEKO) 60 #define fseeko fseeko64 61 #define ftello ftello64 62 #endif 63 #endif 64 #else 65 #define FLAC__off_t off_t 66 #endif 67 68 #ifdef HAVE_INTTYPES_H 69 #include <inttypes.h> 70 #endif 71 72 #if defined(_MSC_VER) 73 #define strtoll _strtoi64 74 #define strtoull _strtoui64 75 #endif 76 77 #if defined(_MSC_VER) && !defined(__cplusplus) 78 #define inline __inline 79 #endif 80 81 #if defined __INTEL_COMPILER || (defined _MSC_VER && defined _WIN64) 82 /* MSVS generates VERY slow 32-bit code with __restrict */ 83 #define flac_restrict __restrict 84 #elif defined __GNUC__ 85 #define flac_restrict __restrict__ 86 #else 87 #define flac_restrict 88 #endif 89 90 #define FLAC__U64L(x) x##ULL 91 92 #if defined _MSC_VER || defined __MINGW32__ 93 #define FLAC__STRCASECMP _stricmp 94 #define FLAC__STRNCASECMP _strnicmp 95 #elif defined __BORLANDC__ 96 #define FLAC__STRCASECMP stricmp 97 #define FLAC__STRNCASECMP strnicmp 98 #else 99 #define FLAC__STRCASECMP strcasecmp 100 #define FLAC__STRNCASECMP strncasecmp 101 #endif 102 103 #if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ 104 #include <io.h> /* for _setmode(), chmod() */ 105 #include <fcntl.h> /* for _O_BINARY */ 106 #else 107 #include <unistd.h> /* for chown(), unlink() */ 108 #endif 109 110 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ 111 #if defined __BORLANDC__ 112 #include <utime.h> /* for utime() */ 113 #else 114 #include <sys/utime.h> /* for utime() */ 115 #endif 116 #else 117 #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) 118 #include <fcntl.h> 119 #else 120 #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */ 121 #include <utime.h> /* for utime() */ 122 #endif 123 #endif 124 125 #if defined _MSC_VER 126 # if _MSC_VER >= 1800 127 # include <inttypes.h> 128 # elif _MSC_VER >= 1600 129 /* Visual Studio 2010 has decent C99 support */ 130 # include <stdint.h> 131 # define PRIu64 "llu" 132 # define PRId64 "lld" 133 # define PRIx64 "llx" 134 # else 135 # include <limits.h> 136 # ifndef UINT32_MAX 137 # define UINT32_MAX _UI32_MAX 138 # endif 139 # define PRIu64 "I64u" 140 # define PRId64 "I64d" 141 # define PRIx64 "I64x" 142 # endif 143 # if defined(_USING_V110_SDK71_) && !defined(_DLL) 144 # pragma message("WARNING: This compile will NOT FUNCTION PROPERLY on Windows XP. See comments in include/share/compat.h for details") 145 #define FLAC__USE_FILELENGTHI64 146 /* 147 ************************************************************************************* 148 * V110_SDK71, in MSVC 2017 also known as v141_xp, is a platform toolset that is supposed 149 * to target Windows XP. It turns out however that certain functions provided silently fail 150 * on Windows XP only, which makes debugging challenging. This only occurs when building with 151 * /MT. This problem has been reported to Microsoft, but there hasn't been a fix for years. See 152 * https://web.archive.org/web/20170327195018/https://connect.microsoft.com/VisualStudio/feedback/details/1557168/wstat64-returns-1-on-xp-always 153 * 154 * It is known that this problem affects the functions _wstat64 (used by flac_stat i.e. 155 * stat64_utf8) and _fstat64 (i.e. flac_fstat) and therefore affects both libFLAC in 156 * several places as well as the flac and metaflac command line tools 157 * 158 * As the extent of this problem is unknown and Microsoft seems unwilling to fix it, 159 * users of libFLAC building with Visual Studio are encouraged to not use the /MT compile 160 * switch when explicitly targeting Windows XP. When use of /MT is deemed necessary with 161 * this toolset, be sure to check whether your application works properly on Windows XP. 162 * It is also possible to build for Windows XP with MinGW instead. 163 ************************************************************************************* 164 */ 165 # endif 166 #endif /* defined _MSC_VER */ 167 168 #ifdef _WIN32 169 /* All char* strings are in UTF-8 format. Added to support Unicode files on Windows */ 170 171 #include "share/win_utf8_io.h" 172 #define flac_printf printf_utf8 173 #define flac_fprintf fprintf_utf8 174 #define flac_vfprintf vfprintf_utf8 175 #define flac_fopen fopen_utf8 176 #define flac_chmod chmod_utf8 177 #define flac_utime utime_utf8 178 #define flac_unlink unlink_utf8 179 #define flac_rename rename_utf8 180 #define flac_stat stat64_utf8 181 182 #else 183 184 #define flac_printf printf 185 #define flac_fprintf fprintf 186 #define flac_vfprintf vfprintf 187 188 #define flac_fopen fopen 189 #define flac_chmod chmod 190 #define flac_unlink unlink 191 #define flac_rename rename 192 #define flac_stat stat 193 194 #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) 195 #define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0) 196 #else 197 #define flac_utime utime 198 #endif 199 #endif 200 201 #ifdef _WIN32 202 #define flac_stat_s __stat64 /* stat struct */ 203 #define flac_fstat _fstat64 204 #else 205 #define flac_stat_s stat /* stat struct */ 206 #define flac_fstat fstat 207 #endif 208 209 #ifdef ANDROID 210 #include <limits.h> 211 #endif 212 213 #ifndef M_LN2 214 #define M_LN2 0.69314718055994530942 215 #endif 216 #ifndef M_PI 217 #define M_PI 3.14159265358979323846 218 #endif 219 220 /* FLAC needs to compile and work correctly on systems with a normal ISO C99 221 * snprintf as well as Microsoft Visual Studio which has an non-standards 222 * conformant snprint_s function. 223 * 224 * This function wraps the MS version to behave more like the ISO version. 225 */ 226 #ifdef __cplusplus 227 extern "C" { 228 #endif 229 int flac_snprintf(char *str, size_t size, const char *fmt, ...); 230 int flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va); 231 #ifdef __cplusplus 232 }; 233 #endif 234 235 #endif /* FLAC__SHARE__COMPAT_H */ 236