Debian Codegraph @

external/flac/flac_share_compat.h

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