1 | /* |
2 | Simple DirectMedia Layer |
3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
4 | |
5 | This software is provided 'as-is', without any express or implied |
6 | warranty. In no event will the authors be held liable for any damages |
7 | arising from the use of this software. |
8 | |
9 | Permission is granted to anyone to use this software for any purpose, |
10 | including commercial applications, and to alter it and redistribute it |
11 | freely, subject to the following restrictions: |
12 | |
13 | 1. The origin of this software must not be misrepresented; you must not |
14 | claim that you wrote the original software. If you use this software |
15 | in a product, an acknowledgment in the product documentation would be |
16 | appreciated but is not required. |
17 | 2. Altered source versions must be plainly marked as such, and must not be |
18 | misrepresented as being the original software. |
19 | 3. This notice may not be removed or altered from any source distribution. |
20 | */ |
21 | |
22 | /** |
23 | * # CategoryStdinc |
24 | * |
25 | * SDL provides its own implementation of some of the most important C runtime |
26 | * functions. |
27 | * |
28 | * Using these functions allows an app to have access to common C |
29 | * functionality without depending on a specific C runtime (or a C runtime at |
30 | * all). More importantly, the SDL implementations work identically across |
31 | * platforms, so apps can avoid surprises like snprintf() behaving differently |
32 | * between Windows and Linux builds, or itoa() only existing on some |
33 | * platforms. |
34 | * |
35 | * For many of the most common functions, like SDL_memcpy, SDL might just call |
36 | * through to the usual C runtime behind the scenes, if it makes sense to do |
37 | * so (if it's faster and always available/reliable on a given platform), |
38 | * reducing library size and offering the most optimized option. |
39 | * |
40 | * SDL also offers other C-runtime-adjacent functionality in this header that |
41 | * either isn't, strictly speaking, part of any C runtime standards, like |
42 | * SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better |
43 | * options, like SDL_strlcpy(), which functions as a safer form of strcpy(). |
44 | */ |
45 | |
46 | #ifndef SDL_stdinc_h_ |
47 | #define SDL_stdinc_h_ |
48 | |
49 | #include <SDL3/SDL_platform_defines.h> |
50 | |
51 | #include <stdarg.h> |
52 | #include <stdint.h> |
53 | #include <string.h> |
54 | #include <wchar.h> |
55 | |
56 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ |
57 | defined(SDL_INCLUDE_INTTYPES_H) |
58 | #include <inttypes.h> |
59 | #endif |
60 | |
61 | #ifndef __cplusplus |
62 | #if defined(__has_include) && !defined(SDL_INCLUDE_STDBOOL_H) |
63 | #if __has_include(<stdbool.h>) |
64 | #define SDL_INCLUDE_STDBOOL_H |
65 | #endif |
66 | #endif |
67 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ |
68 | (defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \ |
69 | defined(SDL_INCLUDE_STDBOOL_H) |
70 | #include <stdbool.h> |
71 | #elif !defined(__bool_true_false_are_defined) && !defined(bool) |
72 | #define bool unsigned char |
73 | #define false 0 |
74 | #define true 1 |
75 | #define __bool_true_false_are_defined 1 |
76 | #endif |
77 | #endif /* !__cplusplus */ |
78 | |
79 | #ifndef SDL_DISABLE_ALLOCA |
80 | # ifndef alloca |
81 | # ifdef HAVE_ALLOCA_H |
82 | # include <alloca.h> |
83 | # elif defined(SDL_PLATFORM_NETBSD) |
84 | # if defined(__STRICT_ANSI__) |
85 | # define SDL_DISABLE_ALLOCA |
86 | # else |
87 | # include <stdlib.h> |
88 | # endif |
89 | # elif defined(__GNUC__) |
90 | # define alloca __builtin_alloca |
91 | # elif defined(_MSC_VER) |
92 | # include <malloc.h> |
93 | # define alloca _alloca |
94 | # elif defined(__WATCOMC__) |
95 | # include <malloc.h> |
96 | # elif defined(__BORLANDC__) |
97 | # include <malloc.h> |
98 | # elif defined(__DMC__) |
99 | # include <stdlib.h> |
100 | # elif defined(SDL_PLATFORM_AIX) |
101 | # pragma alloca |
102 | # elif defined(__MRC__) |
103 | void *alloca(unsigned); |
104 | # else |
105 | void *alloca(size_t); |
106 | # endif |
107 | # endif |
108 | #endif |
109 | |
110 | |
111 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
112 | |
113 | /** |
114 | * Don't let SDL use "long long" C types. |
115 | * |
116 | * SDL will define this if it believes the compiler doesn't understand the |
117 | * "long long" syntax for C datatypes. This can happen on older compilers. |
118 | * |
119 | * If _your_ compiler doesn't support "long long" but SDL doesn't know it, it |
120 | * is safe to define this yourself to build against the SDL headers. |
121 | * |
122 | * If this is defined, it will remove access to some C runtime support |
123 | * functions, like SDL_ulltoa and SDL_strtoll that refer to this datatype |
124 | * explicitly. The rest of SDL will still be available. |
125 | * |
126 | * SDL's own source code cannot be built with a compiler that has this |
127 | * defined, for various technical reasons. |
128 | */ |
129 | #define SDL_NOLONGLONG 1 |
130 | |
131 | #elif defined(_MSC_VER) && (_MSC_VER < 1310) /* long long introduced in Visual Studio.NET 2003 */ |
132 | # define SDL_NOLONGLONG 1 |
133 | #endif |
134 | |
135 | |
136 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
137 | |
138 | /** |
139 | * The largest value that a `size_t` can hold for the target platform. |
140 | * |
141 | * `size_t` is generally the same size as a pointer in modern times, but this |
142 | * can get weird on very old and very esoteric machines. For example, on a |
143 | * 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment |
144 | * plus 16-bit offset), but `size_t` is 16 bits, because it can only deal with |
145 | * the offset into an individual segment. |
146 | * |
147 | * In modern times, it's generally expected to cover an entire linear address |
148 | * space. But be careful! |
149 | * |
150 | * \since This macro is available since SDL 3.2.0. |
151 | */ |
152 | #define SDL_SIZE_MAX SIZE_MAX |
153 | |
154 | #elif defined(SIZE_MAX) |
155 | # define SDL_SIZE_MAX SIZE_MAX |
156 | #else |
157 | # define SDL_SIZE_MAX ((size_t) -1) |
158 | #endif |
159 | |
160 | #ifndef SDL_COMPILE_TIME_ASSERT |
161 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
162 | |
163 | /** |
164 | * A compile-time assertion. |
165 | * |
166 | * This can check constant values _known to the compiler at build time_ for |
167 | * correctness, and end the compile with the error if they fail. |
168 | * |
169 | * Often times these are used to verify basic truths, like the size of a |
170 | * datatype is what is expected: |
171 | * |
172 | * ```c |
173 | * SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4); |
174 | * ``` |
175 | * |
176 | * The `name` parameter must be a valid C symbol, and must be unique across |
177 | * all compile-time asserts in the same compilation unit (one run of the |
178 | * compiler), or the build might fail with cryptic errors on some targets. |
179 | * This is used with a C language trick that works on older compilers that |
180 | * don't support better assertion techniques. |
181 | * |
182 | * If you need an assertion that operates at runtime, on variable data, you |
183 | * should try SDL_assert instead. |
184 | * |
185 | * \param name a unique identifier for this assertion. |
186 | * \param x the value to test. Must be a boolean value. |
187 | * |
188 | * \threadsafety This macro doesn't generate any code to run. |
189 | * |
190 | * \since This macro is available since SDL 3.2.0. |
191 | * |
192 | * \sa SDL_assert |
193 | */ |
194 | #define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x) |
195 | #elif defined(__cplusplus) |
196 | /* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */ |
197 | #if (__cplusplus >= 201103L) |
198 | #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) |
199 | #endif |
200 | #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) |
201 | #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) |
202 | #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) |
203 | #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x) |
204 | #endif |
205 | #endif /* !SDL_COMPILE_TIME_ASSERT */ |
206 | |
207 | #ifndef SDL_COMPILE_TIME_ASSERT |
208 | /* universal, but may trigger -Wunused-local-typedefs */ |
209 | #define SDL_COMPILE_TIME_ASSERT(name, x) \ |
210 | typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1] |
211 | #endif |
212 | |
213 | /** |
214 | * The number of elements in a static array. |
215 | * |
216 | * This will compile but return incorrect results for a pointer to an array; |
217 | * it has to be an array the compiler knows the size of. |
218 | * |
219 | * This macro looks like it double-evaluates the argument, but it does so |
220 | * inside of `sizeof`, so there are no side-effects here, as expressions do |
221 | * not actually run any code in these cases. |
222 | * |
223 | * \since This macro is available since SDL 3.2.0. |
224 | */ |
225 | #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) |
226 | |
227 | /** |
228 | * Macro useful for building other macros with strings in them. |
229 | * |
230 | * For example: |
231 | * |
232 | * ```c |
233 | * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")` |
234 | * ``` |
235 | * |
236 | * \param arg the text to turn into a string literal. |
237 | * |
238 | * \since This macro is available since SDL 3.2.0. |
239 | */ |
240 | #define SDL_STRINGIFY_ARG(arg) #arg |
241 | |
242 | /** |
243 | * \name Cast operators |
244 | * |
245 | * Use proper C++ casts when compiled as C++ to be compatible with the option |
246 | * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above). |
247 | */ |
248 | /* @{ */ |
249 | |
250 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
251 | |
252 | /** |
253 | * Handle a Reinterpret Cast properly whether using C or C++. |
254 | * |
255 | * If compiled as C++, this macro offers a proper C++ reinterpret_cast<>. |
256 | * |
257 | * If compiled as C, this macro does a normal C-style cast. |
258 | * |
259 | * This is helpful to avoid compiler warnings in C++. |
260 | * |
261 | * \param type the type to cast the expression to. |
262 | * \param expression the expression to cast to a different type. |
263 | * \returns `expression`, cast to `type`. |
264 | * |
265 | * \threadsafety It is safe to call this macro from any thread. |
266 | * |
267 | * \since This macro is available since SDL 3.2.0. |
268 | * |
269 | * \sa SDL_static_cast |
270 | * \sa SDL_const_cast |
271 | */ |
272 | #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */ |
273 | |
274 | /** |
275 | * Handle a Static Cast properly whether using C or C++. |
276 | * |
277 | * If compiled as C++, this macro offers a proper C++ static_cast<>. |
278 | * |
279 | * If compiled as C, this macro does a normal C-style cast. |
280 | * |
281 | * This is helpful to avoid compiler warnings in C++. |
282 | * |
283 | * \param type the type to cast the expression to. |
284 | * \param expression the expression to cast to a different type. |
285 | * \returns `expression`, cast to `type`. |
286 | * |
287 | * \threadsafety It is safe to call this macro from any thread. |
288 | * |
289 | * \since This macro is available since SDL 3.2.0. |
290 | * |
291 | * \sa SDL_reinterpret_cast |
292 | * \sa SDL_const_cast |
293 | */ |
294 | #define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */ |
295 | |
296 | /** |
297 | * Handle a Const Cast properly whether using C or C++. |
298 | * |
299 | * If compiled as C++, this macro offers a proper C++ const_cast<>. |
300 | * |
301 | * If compiled as C, this macro does a normal C-style cast. |
302 | * |
303 | * This is helpful to avoid compiler warnings in C++. |
304 | * |
305 | * \param type the type to cast the expression to. |
306 | * \param expression the expression to cast to a different type. |
307 | * \returns `expression`, cast to `type`. |
308 | * |
309 | * \threadsafety It is safe to call this macro from any thread. |
310 | * |
311 | * \since This macro is available since SDL 3.2.0. |
312 | * |
313 | * \sa SDL_reinterpret_cast |
314 | * \sa SDL_static_cast |
315 | */ |
316 | #define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */ |
317 | |
318 | #elif defined(__cplusplus) |
319 | #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) |
320 | #define SDL_static_cast(type, expression) static_cast<type>(expression) |
321 | #define SDL_const_cast(type, expression) const_cast<type>(expression) |
322 | #else |
323 | #define SDL_reinterpret_cast(type, expression) ((type)(expression)) |
324 | #define SDL_static_cast(type, expression) ((type)(expression)) |
325 | #define SDL_const_cast(type, expression) ((type)(expression)) |
326 | #endif |
327 | |
328 | /* @} *//* Cast operators */ |
329 | |
330 | /** |
331 | * Define a four character code as a Uint32. |
332 | * |
333 | * \param A the first ASCII character. |
334 | * \param B the second ASCII character. |
335 | * \param C the third ASCII character. |
336 | * \param D the fourth ASCII character. |
337 | * \returns the four characters converted into a Uint32, one character |
338 | * per-byte. |
339 | * |
340 | * \threadsafety It is safe to call this macro from any thread. |
341 | * |
342 | * \since This macro is available since SDL 3.2.0. |
343 | */ |
344 | #define SDL_FOURCC(A, B, C, D) \ |
345 | ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \ |
346 | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \ |
347 | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \ |
348 | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24)) |
349 | |
350 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
351 | |
352 | /** |
353 | * Append the 64 bit integer suffix to a signed integer literal. |
354 | * |
355 | * This helps compilers that might believe a integer literal larger than |
356 | * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)` |
357 | * instead of `0xFFFFFFFF1` by itself. |
358 | * |
359 | * \since This macro is available since SDL 3.2.0. |
360 | * |
361 | * \sa SDL_UINT64_C |
362 | */ |
363 | #define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */ |
364 | |
365 | /** |
366 | * Append the 64 bit integer suffix to an unsigned integer literal. |
367 | * |
368 | * This helps compilers that might believe a integer literal larger than |
369 | * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)` |
370 | * instead of `0xFFFFFFFF1` by itself. |
371 | * |
372 | * \since This macro is available since SDL 3.2.0. |
373 | * |
374 | * \sa SDL_SINT64_C |
375 | */ |
376 | #define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */ |
377 | |
378 | #else /* !SDL_WIKI_DOCUMENTATION_SECTION */ |
379 | |
380 | #ifndef SDL_SINT64_C |
381 | #if defined(INT64_C) |
382 | #define SDL_SINT64_C(c) INT64_C(c) |
383 | #elif defined(_MSC_VER) |
384 | #define SDL_SINT64_C(c) c ## i64 |
385 | #elif defined(__LP64__) || defined(_LP64) |
386 | #define SDL_SINT64_C(c) c ## L |
387 | #else |
388 | #define SDL_SINT64_C(c) c ## LL |
389 | #endif |
390 | #endif /* !SDL_SINT64_C */ |
391 | |
392 | #ifndef SDL_UINT64_C |
393 | #if defined(UINT64_C) |
394 | #define SDL_UINT64_C(c) UINT64_C(c) |
395 | #elif defined(_MSC_VER) |
396 | #define SDL_UINT64_C(c) c ## ui64 |
397 | #elif defined(__LP64__) || defined(_LP64) |
398 | #define SDL_UINT64_C(c) c ## UL |
399 | #else |
400 | #define SDL_UINT64_C(c) c ## ULL |
401 | #endif |
402 | #endif /* !SDL_UINT64_C */ |
403 | |
404 | #endif /* !SDL_WIKI_DOCUMENTATION_SECTION */ |
405 | |
406 | /** |
407 | * \name Basic data types |
408 | */ |
409 | /* @{ */ |
410 | |
411 | /** |
412 | * A signed 8-bit integer type. |
413 | * |
414 | * \since This macro is available since SDL 3.2.0. |
415 | */ |
416 | typedef int8_t Sint8; |
417 | #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */ |
418 | #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */ |
419 | |
420 | /** |
421 | * An unsigned 8-bit integer type. |
422 | * |
423 | * \since This macro is available since SDL 3.2.0. |
424 | */ |
425 | typedef uint8_t Uint8; |
426 | #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */ |
427 | #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */ |
428 | |
429 | /** |
430 | * A signed 16-bit integer type. |
431 | * |
432 | * \since This macro is available since SDL 3.2.0. |
433 | */ |
434 | typedef int16_t Sint16; |
435 | #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */ |
436 | #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */ |
437 | |
438 | /** |
439 | * An unsigned 16-bit integer type. |
440 | * |
441 | * \since This macro is available since SDL 3.2.0. |
442 | */ |
443 | typedef uint16_t Uint16; |
444 | #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */ |
445 | #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */ |
446 | |
447 | /** |
448 | * A signed 32-bit integer type. |
449 | * |
450 | * \since This macro is available since SDL 3.2.0. |
451 | */ |
452 | typedef int32_t Sint32; |
453 | #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */ |
454 | #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */ |
455 | |
456 | /** |
457 | * An unsigned 32-bit integer type. |
458 | * |
459 | * \since This macro is available since SDL 3.2.0. |
460 | */ |
461 | typedef uint32_t Uint32; |
462 | #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */ |
463 | #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */ |
464 | |
465 | /** |
466 | * A signed 64-bit integer type. |
467 | * |
468 | * \since This macro is available since SDL 3.2.0. |
469 | * |
470 | * \sa SDL_SINT64_C |
471 | */ |
472 | typedef int64_t Sint64; |
473 | #define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */ |
474 | #define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */ |
475 | |
476 | /** |
477 | * An unsigned 64-bit integer type. |
478 | * |
479 | * \since This macro is available since SDL 3.2.0. |
480 | * |
481 | * \sa SDL_UINT64_C |
482 | */ |
483 | typedef uint64_t Uint64; |
484 | #define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */ |
485 | #define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */ |
486 | |
487 | /** |
488 | * SDL times are signed, 64-bit integers representing nanoseconds since the |
489 | * Unix epoch (Jan 1, 1970). |
490 | * |
491 | * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS() |
492 | * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with |
493 | * SDL_TimeToWindows() and SDL_TimeFromWindows(). |
494 | * |
495 | * \since This macro is available since SDL 3.2.0. |
496 | * |
497 | * \sa SDL_MAX_SINT64 |
498 | * \sa SDL_MIN_SINT64 |
499 | */ |
500 | typedef Sint64 SDL_Time; |
501 | #define SDL_MAX_TIME SDL_MAX_SINT64 |
502 | #define SDL_MIN_TIME SDL_MIN_SINT64 |
503 | |
504 | /* @} *//* Basic data types */ |
505 | |
506 | /** |
507 | * \name Floating-point constants |
508 | */ |
509 | /* @{ */ |
510 | |
511 | #ifdef FLT_EPSILON |
512 | #define SDL_FLT_EPSILON FLT_EPSILON |
513 | #else |
514 | |
515 | /** |
516 | * Epsilon constant, used for comparing floating-point numbers. |
517 | * |
518 | * Equals by default to platform-defined `FLT_EPSILON`, or |
519 | * `1.1920928955078125e-07F` if that's not available. |
520 | * |
521 | * \since This macro is available since SDL 3.2.0. |
522 | */ |
523 | #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */ |
524 | #endif |
525 | |
526 | /* @} *//* Floating-point constants */ |
527 | |
528 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
529 | |
530 | /** |
531 | * A printf-formatting string for an Sint64 value. |
532 | * |
533 | * Use it like this: |
534 | * |
535 | * ```c |
536 | * SDL_Log("There are %" SDL_PRIs64 " bottles of beer on the wall.", bottles); |
537 | * ``` |
538 | * |
539 | * \since This macro is available since SDL 3.2.0. |
540 | */ |
541 | #define SDL_PRIs64 "lld" |
542 | |
543 | /** |
544 | * A printf-formatting string for a Uint64 value. |
545 | * |
546 | * Use it like this: |
547 | * |
548 | * ```c |
549 | * SDL_Log("There are %" SDL_PRIu64 " bottles of beer on the wall.", bottles); |
550 | * ``` |
551 | * |
552 | * \since This macro is available since SDL 3.2.0. |
553 | */ |
554 | #define SDL_PRIu64 "llu" |
555 | |
556 | /** |
557 | * A printf-formatting string for a Uint64 value as lower-case hexadecimal. |
558 | * |
559 | * Use it like this: |
560 | * |
561 | * ```c |
562 | * SDL_Log("There are %" SDL_PRIx64 " bottles of beer on the wall.", bottles); |
563 | * ``` |
564 | * |
565 | * \since This macro is available since SDL 3.2.0. |
566 | */ |
567 | #define SDL_PRIx64 "llx" |
568 | |
569 | /** |
570 | * A printf-formatting string for a Uint64 value as upper-case hexadecimal. |
571 | * |
572 | * Use it like this: |
573 | * |
574 | * ```c |
575 | * SDL_Log("There are %" SDL_PRIX64 " bottles of beer on the wall.", bottles); |
576 | * ``` |
577 | * |
578 | * \since This macro is available since SDL 3.2.0. |
579 | */ |
580 | #define SDL_PRIX64 "llX" |
581 | |
582 | /** |
583 | * A printf-formatting string for an Sint32 value. |
584 | * |
585 | * Use it like this: |
586 | * |
587 | * ```c |
588 | * SDL_Log("There are %" SDL_PRIs32 " bottles of beer on the wall.", bottles); |
589 | * ``` |
590 | * |
591 | * \since This macro is available since SDL 3.2.0. |
592 | */ |
593 | #define SDL_PRIs32 "d" |
594 | |
595 | /** |
596 | * A printf-formatting string for a Uint32 value. |
597 | * |
598 | * Use it like this: |
599 | * |
600 | * ```c |
601 | * SDL_Log("There are %" SDL_PRIu32 " bottles of beer on the wall.", bottles); |
602 | * ``` |
603 | * |
604 | * \since This macro is available since SDL 3.2.0. |
605 | */ |
606 | #define SDL_PRIu32 "u" |
607 | |
608 | /** |
609 | * A printf-formatting string for a Uint32 value as lower-case hexadecimal. |
610 | * |
611 | * Use it like this: |
612 | * |
613 | * ```c |
614 | * SDL_Log("There are %" SDL_PRIx32 " bottles of beer on the wall.", bottles); |
615 | * ``` |
616 | * |
617 | * \since This macro is available since SDL 3.2.0. |
618 | */ |
619 | #define SDL_PRIx32 "x" |
620 | |
621 | /** |
622 | * A printf-formatting string for a Uint32 value as upper-case hexadecimal. |
623 | * |
624 | * Use it like this: |
625 | * |
626 | * ```c |
627 | * SDL_Log("There are %" SDL_PRIX32 " bottles of beer on the wall.", bottles); |
628 | * ``` |
629 | * |
630 | * \since This macro is available since SDL 3.2.0. |
631 | */ |
632 | #define SDL_PRIX32 "X" |
633 | |
634 | /** |
635 | * A printf-formatting string prefix for a `long long` value. |
636 | * |
637 | * This is just the prefix! You probably actually want SDL_PRILLd, SDL_PRILLu, |
638 | * SDL_PRILLx, or SDL_PRILLX instead. |
639 | * |
640 | * Use it like this: |
641 | * |
642 | * ```c |
643 | * SDL_Log("There are %" SDL_PRILL_PREFIX "d bottles of beer on the wall.", bottles); |
644 | * ``` |
645 | * |
646 | * \since This macro is available since SDL 3.2.0. |
647 | */ |
648 | #define SDL_PRILL_PREFIX "ll" |
649 | |
650 | /** |
651 | * A printf-formatting string for a `long long` value. |
652 | * |
653 | * Use it like this: |
654 | * |
655 | * ```c |
656 | * SDL_Log("There are %" SDL_PRILLd " bottles of beer on the wall.", bottles); |
657 | * ``` |
658 | * |
659 | * \since This macro is available since SDL 3.2.0. |
660 | */ |
661 | #define SDL_PRILLd SDL_PRILL_PREFIX "d" |
662 | |
663 | /** |
664 | * A printf-formatting string for a `unsigned long long` value. |
665 | * |
666 | * Use it like this: |
667 | * |
668 | * ```c |
669 | * SDL_Log("There are %" SDL_PRILLu " bottles of beer on the wall.", bottles); |
670 | * ``` |
671 | * |
672 | * \since This macro is available since SDL 3.2.0. |
673 | */ |
674 | #define SDL_PRILLu SDL_PRILL_PREFIX "u" |
675 | |
676 | /** |
677 | * A printf-formatting string for an `unsigned long long` value as lower-case |
678 | * hexadecimal. |
679 | * |
680 | * Use it like this: |
681 | * |
682 | * ```c |
683 | * SDL_Log("There are %" SDL_PRILLx " bottles of beer on the wall.", bottles); |
684 | * ``` |
685 | * |
686 | * \since This macro is available since SDL 3.2.0. |
687 | */ |
688 | #define SDL_PRILLx SDL_PRILL_PREFIX "x" |
689 | |
690 | /** |
691 | * A printf-formatting string for an `unsigned long long` value as upper-case |
692 | * hexadecimal. |
693 | * |
694 | * Use it like this: |
695 | * |
696 | * ```c |
697 | * SDL_Log("There are %" SDL_PRILLX " bottles of beer on the wall.", bottles); |
698 | * ``` |
699 | * |
700 | * \since This macro is available since SDL 3.2.0. |
701 | */ |
702 | #define SDL_PRILLX SDL_PRILL_PREFIX "X" |
703 | #endif /* SDL_WIKI_DOCUMENTATION_SECTION */ |
704 | |
705 | /* Make sure we have macros for printing width-based integers. |
706 | * <inttypes.h> should define these but this is not true all platforms. |
707 | * (for example win32) */ |
708 | #ifndef SDL_PRIs64 |
709 | #if defined(SDL_PLATFORM_WINDOWS) |
710 | #define SDL_PRIs64 "I64d" |
711 | #elif defined(PRId64) |
712 | #define SDL_PRIs64 PRId64 |
713 | #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__) |
714 | #define SDL_PRIs64 "ld" |
715 | #else |
716 | #define SDL_PRIs64 "lld" |
717 | #endif |
718 | #endif |
719 | #ifndef SDL_PRIu64 |
720 | #if defined(SDL_PLATFORM_WINDOWS) |
721 | #define SDL_PRIu64 "I64u" |
722 | #elif defined(PRIu64) |
723 | #define SDL_PRIu64 PRIu64 |
724 | #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__) |
725 | #define SDL_PRIu64 "lu" |
726 | #else |
727 | #define SDL_PRIu64 "llu" |
728 | #endif |
729 | #endif |
730 | #ifndef SDL_PRIx64 |
731 | #if defined(SDL_PLATFORM_WINDOWS) |
732 | #define SDL_PRIx64 "I64x" |
733 | #elif defined(PRIx64) |
734 | #define SDL_PRIx64 PRIx64 |
735 | #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) |
736 | #define SDL_PRIx64 "lx" |
737 | #else |
738 | #define SDL_PRIx64 "llx" |
739 | #endif |
740 | #endif |
741 | #ifndef SDL_PRIX64 |
742 | #if defined(SDL_PLATFORM_WINDOWS) |
743 | #define SDL_PRIX64 "I64X" |
744 | #elif defined(PRIX64) |
745 | #define SDL_PRIX64 PRIX64 |
746 | #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) |
747 | #define SDL_PRIX64 "lX" |
748 | #else |
749 | #define SDL_PRIX64 "llX" |
750 | #endif |
751 | #endif |
752 | #ifndef SDL_PRIs32 |
753 | #ifdef PRId32 |
754 | #define SDL_PRIs32 PRId32 |
755 | #else |
756 | #define SDL_PRIs32 "d" |
757 | #endif |
758 | #endif |
759 | #ifndef SDL_PRIu32 |
760 | #ifdef PRIu32 |
761 | #define SDL_PRIu32 PRIu32 |
762 | #else |
763 | #define SDL_PRIu32 "u" |
764 | #endif |
765 | #endif |
766 | #ifndef SDL_PRIx32 |
767 | #ifdef PRIx32 |
768 | #define SDL_PRIx32 PRIx32 |
769 | #else |
770 | #define SDL_PRIx32 "x" |
771 | #endif |
772 | #endif |
773 | #ifndef SDL_PRIX32 |
774 | #ifdef PRIX32 |
775 | #define SDL_PRIX32 PRIX32 |
776 | #else |
777 | #define SDL_PRIX32 "X" |
778 | #endif |
779 | #endif |
780 | /* Specifically for the `long long` -- SDL-specific. */ |
781 | #ifdef SDL_PLATFORM_WINDOWS |
782 | #ifndef SDL_NOLONGLONG |
783 | SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */ |
784 | #endif |
785 | #define SDL_PRILL_PREFIX "I64" |
786 | #else |
787 | #define SDL_PRILL_PREFIX "ll" |
788 | #endif |
789 | #ifndef SDL_PRILLd |
790 | #define SDL_PRILLd SDL_PRILL_PREFIX "d" |
791 | #endif |
792 | #ifndef SDL_PRILLu |
793 | #define SDL_PRILLu SDL_PRILL_PREFIX "u" |
794 | #endif |
795 | #ifndef SDL_PRILLx |
796 | #define SDL_PRILLx SDL_PRILL_PREFIX "x" |
797 | #endif |
798 | #ifndef SDL_PRILLX |
799 | #define SDL_PRILLX SDL_PRILL_PREFIX "X" |
800 | #endif |
801 | |
802 | /* Annotations to help code analysis tools */ |
803 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
804 | |
805 | /** |
806 | * Macro that annotates function params with input buffer size. |
807 | * |
808 | * If we were to annotate `memcpy`: |
809 | * |
810 | * ```c |
811 | * void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len); |
812 | * ``` |
813 | * |
814 | * This notes that `src` should be `len` bytes in size and is only read by the |
815 | * function. The compiler or other analysis tools can warn when this doesn't |
816 | * appear to be the case. |
817 | * |
818 | * On compilers without this annotation mechanism, this is defined to nothing. |
819 | * |
820 | * \since This macro is available since SDL 3.2.0. |
821 | */ |
822 | #define SDL_IN_BYTECAP(x) _In_bytecount_(x) |
823 | |
824 | /** |
825 | * Macro that annotates function params with input/output string buffer size. |
826 | * |
827 | * If we were to annotate `strlcat`: |
828 | * |
829 | * ```c |
830 | * size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen); |
831 | * ``` |
832 | * |
833 | * This notes that `dst` is a null-terminated C string, should be `maxlen` |
834 | * bytes in size, and is both read from and written to by the function. The |
835 | * compiler or other analysis tools can warn when this doesn't appear to be |
836 | * the case. |
837 | * |
838 | * On compilers without this annotation mechanism, this is defined to nothing. |
839 | * |
840 | * \since This macro is available since SDL 3.2.0. |
841 | */ |
842 | #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x) |
843 | |
844 | /** |
845 | * Macro that annotates function params with output string buffer size. |
846 | * |
847 | * If we were to annotate `snprintf`: |
848 | * |
849 | * ```c |
850 | * int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...); |
851 | * ``` |
852 | * |
853 | * This notes that `text` is a null-terminated C string, should be `maxlen` |
854 | * bytes in size, and is only written to by the function. The compiler or |
855 | * other analysis tools can warn when this doesn't appear to be the case. |
856 | * |
857 | * On compilers without this annotation mechanism, this is defined to nothing. |
858 | * |
859 | * \since This macro is available since SDL 3.2.0. |
860 | */ |
861 | #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x) |
862 | |
863 | /** |
864 | * Macro that annotates function params with output buffer size. |
865 | * |
866 | * If we were to annotate `wcsncpy`: |
867 | * |
868 | * ```c |
869 | * char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize); |
870 | * ``` |
871 | * |
872 | * This notes that `dst` should have a capacity of `bufsize` wchar_t in size, |
873 | * and is only written to by the function. The compiler or other analysis |
874 | * tools can warn when this doesn't appear to be the case. |
875 | * |
876 | * This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for |
877 | * bytes. |
878 | * |
879 | * On compilers without this annotation mechanism, this is defined to nothing. |
880 | * |
881 | * \since This macro is available since SDL 3.2.0. |
882 | */ |
883 | #define SDL_OUT_CAP(x) _Out_cap_(x) |
884 | |
885 | /** |
886 | * Macro that annotates function params with output buffer size. |
887 | * |
888 | * If we were to annotate `memcpy`: |
889 | * |
890 | * ```c |
891 | * void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize); |
892 | * ``` |
893 | * |
894 | * This notes that `dst` should have a capacity of `bufsize` bytes in size, |
895 | * and is only written to by the function. The compiler or other analysis |
896 | * tools can warn when this doesn't appear to be the case. |
897 | * |
898 | * On compilers without this annotation mechanism, this is defined to nothing. |
899 | * |
900 | * \since This macro is available since SDL 3.2.0. |
901 | */ |
902 | #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x) |
903 | |
904 | /** |
905 | * Macro that annotates function params with output buffer string size. |
906 | * |
907 | * If we were to annotate `strcpy`: |
908 | * |
909 | * ```c |
910 | * char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize); |
911 | * ``` |
912 | * |
913 | * This notes that `dst` should have a capacity of `bufsize` bytes in size, |
914 | * and a zero-terminated string is written to it by the function. The compiler |
915 | * or other analysis tools can warn when this doesn't appear to be the case. |
916 | * |
917 | * On compilers without this annotation mechanism, this is defined to nothing. |
918 | * |
919 | * \since This macro is available since SDL 3.2.0. |
920 | */ |
921 | #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x) |
922 | |
923 | /** |
924 | * Macro that annotates function params as printf-style format strings. |
925 | * |
926 | * If we were to annotate `fprintf`: |
927 | * |
928 | * ```c |
929 | * int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...); |
930 | * ``` |
931 | * |
932 | * This notes that `fmt` should be a printf-style format string. The compiler |
933 | * or other analysis tools can warn when this doesn't appear to be the case. |
934 | * |
935 | * On compilers without this annotation mechanism, this is defined to nothing. |
936 | * |
937 | * \since This macro is available since SDL 3.2.0. |
938 | */ |
939 | #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_ |
940 | |
941 | /** |
942 | * Macro that annotates function params as scanf-style format strings. |
943 | * |
944 | * If we were to annotate `fscanf`: |
945 | * |
946 | * ```c |
947 | * int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...); |
948 | * ``` |
949 | * |
950 | * This notes that `fmt` should be a scanf-style format string. The compiler |
951 | * or other analysis tools can warn when this doesn't appear to be the case. |
952 | * |
953 | * On compilers without this annotation mechanism, this is defined to nothing. |
954 | * |
955 | * \since This macro is available since SDL 3.2.0. |
956 | */ |
957 | #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_ |
958 | |
959 | /** |
960 | * Macro that annotates a vararg function that operates like printf. |
961 | * |
962 | * If we were to annotate `fprintf`: |
963 | * |
964 | * ```c |
965 | * int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2); |
966 | * ``` |
967 | * |
968 | * This notes that the second parameter should be a printf-style format |
969 | * string, followed by `...`. The compiler or other analysis tools can warn |
970 | * when this doesn't appear to be the case. |
971 | * |
972 | * On compilers without this annotation mechanism, this is defined to nothing. |
973 | * |
974 | * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which |
975 | * between them will cover at least Visual Studio, GCC, and Clang. |
976 | * |
977 | * \since This macro is available since SDL 3.2.0. |
978 | */ |
979 | #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 ))) |
980 | |
981 | /** |
982 | * Macro that annotates a va_list function that operates like printf. |
983 | * |
984 | * If we were to annotate `vfprintf`: |
985 | * |
986 | * ```c |
987 | * int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2); |
988 | * ``` |
989 | * |
990 | * This notes that the second parameter should be a printf-style format |
991 | * string, followed by a va_list. The compiler or other analysis tools can |
992 | * warn when this doesn't appear to be the case. |
993 | * |
994 | * On compilers without this annotation mechanism, this is defined to nothing. |
995 | * |
996 | * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which |
997 | * between them will cover at least Visual Studio, GCC, and Clang. |
998 | * |
999 | * \since This macro is available since SDL 3.2.0. |
1000 | */ |
1001 | #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 ))) |
1002 | |
1003 | /** |
1004 | * Macro that annotates a vararg function that operates like scanf. |
1005 | * |
1006 | * If we were to annotate `fscanf`: |
1007 | * |
1008 | * ```c |
1009 | * int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2); |
1010 | * ``` |
1011 | * |
1012 | * This notes that the second parameter should be a scanf-style format string, |
1013 | * followed by `...`. The compiler or other analysis tools can warn when this |
1014 | * doesn't appear to be the case. |
1015 | * |
1016 | * On compilers without this annotation mechanism, this is defined to nothing. |
1017 | * |
1018 | * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which |
1019 | * between them will cover at least Visual Studio, GCC, and Clang. |
1020 | * |
1021 | * \since This macro is available since SDL 3.2.0. |
1022 | */ |
1023 | #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 ))) |
1024 | |
1025 | /** |
1026 | * Macro that annotates a va_list function that operates like scanf. |
1027 | * |
1028 | * If we were to annotate `vfscanf`: |
1029 | * |
1030 | * ```c |
1031 | * int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2); |
1032 | * ``` |
1033 | * |
1034 | * This notes that the second parameter should be a scanf-style format string, |
1035 | * followed by a va_list. The compiler or other analysis tools can warn when |
1036 | * this doesn't appear to be the case. |
1037 | * |
1038 | * On compilers without this annotation mechanism, this is defined to nothing. |
1039 | * |
1040 | * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which |
1041 | * between them will cover at least Visual Studio, GCC, and Clang. |
1042 | * |
1043 | * \since This macro is available since SDL 3.2.0. |
1044 | */ |
1045 | #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 ))) |
1046 | |
1047 | /** |
1048 | * Macro that annotates a vararg function that operates like wprintf. |
1049 | * |
1050 | * If we were to annotate `fwprintf`: |
1051 | * |
1052 | * ```c |
1053 | * int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2); |
1054 | * ``` |
1055 | * |
1056 | * This notes that the second parameter should be a wprintf-style format wide |
1057 | * string, followed by `...`. The compiler or other analysis tools can warn |
1058 | * when this doesn't appear to be the case. |
1059 | * |
1060 | * On compilers without this annotation mechanism, this is defined to nothing. |
1061 | * |
1062 | * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which |
1063 | * between them will cover at least Visual Studio, GCC, and Clang. |
1064 | * |
1065 | * \since This macro is available since SDL 3.2.0. |
1066 | */ |
1067 | #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */ |
1068 | |
1069 | /** |
1070 | * Macro that annotates a va_list function that operates like wprintf. |
1071 | * |
1072 | * If we were to annotate `vfwprintf`: |
1073 | * |
1074 | * ```c |
1075 | * int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2); |
1076 | * ``` |
1077 | * |
1078 | * This notes that the second parameter should be a wprintf-style format wide |
1079 | * string, followed by a va_list. The compiler or other analysis tools can |
1080 | * warn when this doesn't appear to be the case. |
1081 | * |
1082 | * On compilers without this annotation mechanism, this is defined to nothing. |
1083 | * |
1084 | * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which |
1085 | * between them will cover at least Visual Studio, GCC, and Clang. |
1086 | * |
1087 | * \since This macro is available since SDL 3.2.0. |
1088 | */ |
1089 | #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */ |
1090 | |
1091 | #elif defined(SDL_DISABLE_ANALYZE_MACROS) |
1092 | #define SDL_IN_BYTECAP(x) |
1093 | #define SDL_INOUT_Z_CAP(x) |
1094 | #define SDL_OUT_Z_CAP(x) |
1095 | #define SDL_OUT_CAP(x) |
1096 | #define SDL_OUT_BYTECAP(x) |
1097 | #define SDL_OUT_Z_BYTECAP(x) |
1098 | #define SDL_PRINTF_FORMAT_STRING |
1099 | #define SDL_SCANF_FORMAT_STRING |
1100 | #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) |
1101 | #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) |
1102 | #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) |
1103 | #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) |
1104 | #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) |
1105 | #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) |
1106 | #else |
1107 | #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */ |
1108 | #include <sal.h> |
1109 | |
1110 | #define SDL_IN_BYTECAP(x) _In_bytecount_(x) |
1111 | #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x) |
1112 | #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x) |
1113 | #define SDL_OUT_CAP(x) _Out_cap_(x) |
1114 | #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x) |
1115 | #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x) |
1116 | |
1117 | #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_ |
1118 | #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_ |
1119 | #else |
1120 | #define SDL_IN_BYTECAP(x) |
1121 | #define SDL_INOUT_Z_CAP(x) |
1122 | #define SDL_OUT_Z_CAP(x) |
1123 | #define SDL_OUT_CAP(x) |
1124 | #define SDL_OUT_BYTECAP(x) |
1125 | #define SDL_OUT_Z_BYTECAP(x) |
1126 | #define SDL_PRINTF_FORMAT_STRING |
1127 | #define SDL_SCANF_FORMAT_STRING |
1128 | #endif |
1129 | #if defined(__GNUC__) || defined(__clang__) |
1130 | #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 ))) |
1131 | #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 ))) |
1132 | #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 ))) |
1133 | #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 ))) |
1134 | #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */ |
1135 | #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */ |
1136 | #else |
1137 | #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) |
1138 | #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) |
1139 | #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) |
1140 | #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) |
1141 | #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) |
1142 | #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) |
1143 | #endif |
1144 | #endif /* SDL_DISABLE_ANALYZE_MACROS */ |
1145 | |
1146 | /** \cond */ |
1147 | #ifndef DOXYGEN_SHOULD_IGNORE_THIS |
1148 | SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1); |
1149 | SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1); |
1150 | SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1); |
1151 | SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2); |
1152 | SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2); |
1153 | SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4); |
1154 | SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4); |
1155 | SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8); |
1156 | SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8); |
1157 | #ifndef SDL_NOLONGLONG |
1158 | SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long)); |
1159 | SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long)); |
1160 | #endif |
1161 | typedef struct SDL_alignment_test |
1162 | { |
1163 | Uint8 a; |
1164 | void *b; |
1165 | } SDL_alignment_test; |
1166 | SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *))); |
1167 | SDL_COMPILE_TIME_ASSERT(two_s_complement, (int)~(int)0 == (int)(-1)); |
1168 | #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ |
1169 | /** \endcond */ |
1170 | |
1171 | /* Check to make sure enums are the size of ints, for structure packing. |
1172 | For both Watcom C/C++ and Borland C/C++ the compiler option that makes |
1173 | enums having the size of an int must be enabled. |
1174 | This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). |
1175 | */ |
1176 | |
1177 | /** \cond */ |
1178 | #ifndef DOXYGEN_SHOULD_IGNORE_THIS |
1179 | #if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS) |
1180 | /* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */ |
1181 | typedef enum SDL_DUMMY_ENUM |
1182 | { |
1183 | DUMMY_ENUM_VALUE |
1184 | } SDL_DUMMY_ENUM; |
1185 | |
1186 | SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); |
1187 | #endif |
1188 | #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ |
1189 | /** \endcond */ |
1190 | |
1191 | #include <SDL3/SDL_begin_code.h> |
1192 | /* Set up for C function definitions, even when using C++ */ |
1193 | #ifdef __cplusplus |
1194 | extern "C" { |
1195 | #endif |
1196 | |
1197 | /** |
1198 | * A macro to initialize an SDL interface. |
1199 | * |
1200 | * This macro will initialize an SDL interface structure and should be called |
1201 | * before you fill out the fields with your implementation. |
1202 | * |
1203 | * You can use it like this: |
1204 | * |
1205 | * ```c |
1206 | * SDL_IOStreamInterface iface; |
1207 | * |
1208 | * SDL_INIT_INTERFACE(&iface); |
1209 | * |
1210 | * // Fill in the interface function pointers with your implementation |
1211 | * iface.seek = ... |
1212 | * |
1213 | * stream = SDL_OpenIO(&iface, NULL); |
1214 | * ``` |
1215 | * |
1216 | * If you are using designated initializers, you can use the size of the |
1217 | * interface as the version, e.g. |
1218 | * |
1219 | * ```c |
1220 | * SDL_IOStreamInterface iface = { |
1221 | * .version = sizeof(iface), |
1222 | * .seek = ... |
1223 | * }; |
1224 | * stream = SDL_OpenIO(&iface, NULL); |
1225 | * ``` |
1226 | * |
1227 | * \threadsafety It is safe to call this macro from any thread. |
1228 | * |
1229 | * \since This macro is available since SDL 3.2.0. |
1230 | * |
1231 | * \sa SDL_IOStreamInterface |
1232 | * \sa SDL_StorageInterface |
1233 | * \sa SDL_VirtualJoystickDesc |
1234 | */ |
1235 | #define SDL_INIT_INTERFACE(iface) \ |
1236 | do { \ |
1237 | SDL_zerop(iface); \ |
1238 | (iface)->version = sizeof(*(iface)); \ |
1239 | } while (0) |
1240 | |
1241 | |
1242 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
1243 | |
1244 | /** |
1245 | * Allocate memory on the stack (maybe). |
1246 | * |
1247 | * If SDL knows how to access alloca() on the current platform, it will use it |
1248 | * to stack-allocate memory here. If it doesn't, it will use SDL_malloc() to |
1249 | * heap-allocate memory. |
1250 | * |
1251 | * Since this might not be stack memory at all, it's important that you check |
1252 | * the returned pointer for NULL, and that you call SDL_stack_free on the |
1253 | * memory when done with it. Since this might be stack memory, it's important |
1254 | * that you don't allocate large amounts of it, or allocate in a loop without |
1255 | * returning from the function, so the stack doesn't overflow. |
1256 | * |
1257 | * \param type the datatype of the memory to allocate. |
1258 | * \param count the number of `type` objects to allocate. |
1259 | * \returns newly-allocated memory, or NULL on failure. |
1260 | * |
1261 | * \threadsafety It is safe to call this macro from any thread. |
1262 | * |
1263 | * \since This macro is available since SDL 3.2.0. |
1264 | * |
1265 | * \sa SDL_stack_free |
1266 | */ |
1267 | #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count)) |
1268 | |
1269 | /** |
1270 | * Free memory previously allocated with SDL_stack_alloc. |
1271 | * |
1272 | * If SDL used alloca() to allocate this memory, this macro does nothing and |
1273 | * the allocated memory will be automatically released when the function that |
1274 | * called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will |
1275 | * SDL_free the memory immediately. |
1276 | * |
1277 | * \param data the pointer, from SDL_stack_alloc(), to free. |
1278 | * |
1279 | * \threadsafety It is safe to call this macro from any thread. |
1280 | * |
1281 | * \since This macro is available since SDL 3.2.0. |
1282 | * |
1283 | * \sa SDL_stack_alloc |
1284 | */ |
1285 | #define SDL_stack_free(data) |
1286 | #elif !defined(SDL_DISABLE_ALLOCA) |
1287 | #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count)) |
1288 | #define SDL_stack_free(data) |
1289 | #else |
1290 | #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count)) |
1291 | #define SDL_stack_free(data) SDL_free(data) |
1292 | #endif |
1293 | |
1294 | /** |
1295 | * Allocate uninitialized memory. |
1296 | * |
1297 | * The allocated memory returned by this function must be freed with |
1298 | * SDL_free(). |
1299 | * |
1300 | * If `size` is 0, it will be set to 1. |
1301 | * |
1302 | * If you want to allocate memory aligned to a specific alignment, consider |
1303 | * using SDL_aligned_alloc(). |
1304 | * |
1305 | * \param size the size to allocate. |
1306 | * \returns a pointer to the allocated memory, or NULL if allocation failed. |
1307 | * |
1308 | * \threadsafety It is safe to call this function from any thread. |
1309 | * |
1310 | * \since This function is available since SDL 3.2.0. |
1311 | * |
1312 | * \sa SDL_free |
1313 | * \sa SDL_calloc |
1314 | * \sa SDL_realloc |
1315 | * \sa SDL_aligned_alloc |
1316 | */ |
1317 | extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size); |
1318 | |
1319 | /** |
1320 | * Allocate a zero-initialized array. |
1321 | * |
1322 | * The memory returned by this function must be freed with SDL_free(). |
1323 | * |
1324 | * If either of `nmemb` or `size` is 0, they will both be set to 1. |
1325 | * |
1326 | * \param nmemb the number of elements in the array. |
1327 | * \param size the size of each element of the array. |
1328 | * \returns a pointer to the allocated array, or NULL if allocation failed. |
1329 | * |
1330 | * \threadsafety It is safe to call this function from any thread. |
1331 | * |
1332 | * \since This function is available since SDL 3.2.0. |
1333 | * |
1334 | * \sa SDL_free |
1335 | * \sa SDL_malloc |
1336 | * \sa SDL_realloc |
1337 | */ |
1338 | extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size); |
1339 | |
1340 | /** |
1341 | * Change the size of allocated memory. |
1342 | * |
1343 | * The memory returned by this function must be freed with SDL_free(). |
1344 | * |
1345 | * If `size` is 0, it will be set to 1. Note that this is unlike some other C |
1346 | * runtime `realloc` implementations, which may treat `realloc(mem, 0)` the |
1347 | * same way as `free(mem)`. |
1348 | * |
1349 | * If `mem` is NULL, the behavior of this function is equivalent to |
1350 | * SDL_malloc(). Otherwise, the function can have one of three possible |
1351 | * outcomes: |
1352 | * |
1353 | * - If it returns the same pointer as `mem`, it means that `mem` was resized |
1354 | * in place without freeing. |
1355 | * - If it returns a different non-NULL pointer, it means that `mem` was freed |
1356 | * and cannot be dereferenced anymore. |
1357 | * - If it returns NULL (indicating failure), then `mem` will remain valid and |
1358 | * must still be freed with SDL_free(). |
1359 | * |
1360 | * \param mem a pointer to allocated memory to reallocate, or NULL. |
1361 | * \param size the new size of the memory. |
1362 | * \returns a pointer to the newly allocated memory, or NULL if allocation |
1363 | * failed. |
1364 | * |
1365 | * \threadsafety It is safe to call this function from any thread. |
1366 | * |
1367 | * \since This function is available since SDL 3.2.0. |
1368 | * |
1369 | * \sa SDL_free |
1370 | * \sa SDL_malloc |
1371 | * \sa SDL_calloc |
1372 | */ |
1373 | extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size); |
1374 | |
1375 | /** |
1376 | * Free allocated memory. |
1377 | * |
1378 | * The pointer is no longer valid after this call and cannot be dereferenced |
1379 | * anymore. |
1380 | * |
1381 | * If `mem` is NULL, this function does nothing. |
1382 | * |
1383 | * \param mem a pointer to allocated memory, or NULL. |
1384 | * |
1385 | * \threadsafety It is safe to call this function from any thread. |
1386 | * |
1387 | * \since This function is available since SDL 3.2.0. |
1388 | * |
1389 | * \sa SDL_malloc |
1390 | * \sa SDL_calloc |
1391 | * \sa SDL_realloc |
1392 | */ |
1393 | extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem); |
1394 | |
1395 | /** |
1396 | * A callback used to implement SDL_malloc(). |
1397 | * |
1398 | * SDL will always ensure that the passed `size` is greater than 0. |
1399 | * |
1400 | * \param size the size to allocate. |
1401 | * \returns a pointer to the allocated memory, or NULL if allocation failed. |
1402 | * |
1403 | * \threadsafety It should be safe to call this callback from any thread. |
1404 | * |
1405 | * \since This datatype is available since SDL 3.2.0. |
1406 | * |
1407 | * \sa SDL_malloc |
1408 | * \sa SDL_GetOriginalMemoryFunctions |
1409 | * \sa SDL_GetMemoryFunctions |
1410 | * \sa SDL_SetMemoryFunctions |
1411 | */ |
1412 | typedef void *(SDLCALL *SDL_malloc_func)(size_t size); |
1413 | |
1414 | /** |
1415 | * A callback used to implement SDL_calloc(). |
1416 | * |
1417 | * SDL will always ensure that the passed `nmemb` and `size` are both greater |
1418 | * than 0. |
1419 | * |
1420 | * \param nmemb the number of elements in the array. |
1421 | * \param size the size of each element of the array. |
1422 | * \returns a pointer to the allocated array, or NULL if allocation failed. |
1423 | * |
1424 | * \threadsafety It should be safe to call this callback from any thread. |
1425 | * |
1426 | * \since This datatype is available since SDL 3.2.0. |
1427 | * |
1428 | * \sa SDL_calloc |
1429 | * \sa SDL_GetOriginalMemoryFunctions |
1430 | * \sa SDL_GetMemoryFunctions |
1431 | * \sa SDL_SetMemoryFunctions |
1432 | */ |
1433 | typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size); |
1434 | |
1435 | /** |
1436 | * A callback used to implement SDL_realloc(). |
1437 | * |
1438 | * SDL will always ensure that the passed `size` is greater than 0. |
1439 | * |
1440 | * \param mem a pointer to allocated memory to reallocate, or NULL. |
1441 | * \param size the new size of the memory. |
1442 | * \returns a pointer to the newly allocated memory, or NULL if allocation |
1443 | * failed. |
1444 | * |
1445 | * \threadsafety It should be safe to call this callback from any thread. |
1446 | * |
1447 | * \since This datatype is available since SDL 3.2.0. |
1448 | * |
1449 | * \sa SDL_realloc |
1450 | * \sa SDL_GetOriginalMemoryFunctions |
1451 | * \sa SDL_GetMemoryFunctions |
1452 | * \sa SDL_SetMemoryFunctions |
1453 | */ |
1454 | typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size); |
1455 | |
1456 | /** |
1457 | * A callback used to implement SDL_free(). |
1458 | * |
1459 | * SDL will always ensure that the passed `mem` is a non-NULL pointer. |
1460 | * |
1461 | * \param mem a pointer to allocated memory. |
1462 | * |
1463 | * \threadsafety It should be safe to call this callback from any thread. |
1464 | * |
1465 | * \since This datatype is available since SDL 3.2.0. |
1466 | * |
1467 | * \sa SDL_free |
1468 | * \sa SDL_GetOriginalMemoryFunctions |
1469 | * \sa SDL_GetMemoryFunctions |
1470 | * \sa SDL_SetMemoryFunctions |
1471 | */ |
1472 | typedef void (SDLCALL *SDL_free_func)(void *mem); |
1473 | |
1474 | /** |
1475 | * Get the original set of SDL memory functions. |
1476 | * |
1477 | * This is what SDL_malloc and friends will use by default, if there has been |
1478 | * no call to SDL_SetMemoryFunctions. This is not necessarily using the C |
1479 | * runtime's `malloc` functions behind the scenes! Different platforms and |
1480 | * build configurations might do any number of unexpected things. |
1481 | * |
1482 | * \param malloc_func filled with malloc function. |
1483 | * \param calloc_func filled with calloc function. |
1484 | * \param realloc_func filled with realloc function. |
1485 | * \param free_func filled with free function. |
1486 | * |
1487 | * \threadsafety It is safe to call this function from any thread. |
1488 | * |
1489 | * \since This function is available since SDL 3.2.0. |
1490 | */ |
1491 | extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func, |
1492 | SDL_calloc_func *calloc_func, |
1493 | SDL_realloc_func *realloc_func, |
1494 | SDL_free_func *free_func); |
1495 | |
1496 | /** |
1497 | * Get the current set of SDL memory functions. |
1498 | * |
1499 | * \param malloc_func filled with malloc function. |
1500 | * \param calloc_func filled with calloc function. |
1501 | * \param realloc_func filled with realloc function. |
1502 | * \param free_func filled with free function. |
1503 | * |
1504 | * \threadsafety This does not hold a lock, so do not call this in the |
1505 | * unlikely event of a background thread calling |
1506 | * SDL_SetMemoryFunctions simultaneously. |
1507 | * |
1508 | * \since This function is available since SDL 3.2.0. |
1509 | * |
1510 | * \sa SDL_SetMemoryFunctions |
1511 | * \sa SDL_GetOriginalMemoryFunctions |
1512 | */ |
1513 | extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func, |
1514 | SDL_calloc_func *calloc_func, |
1515 | SDL_realloc_func *realloc_func, |
1516 | SDL_free_func *free_func); |
1517 | |
1518 | /** |
1519 | * Replace SDL's memory allocation functions with a custom set. |
1520 | * |
1521 | * It is not safe to call this function once any allocations have been made, |
1522 | * as future calls to SDL_free will use the new allocator, even if they came |
1523 | * from an SDL_malloc made with the old one! |
1524 | * |
1525 | * If used, usually this needs to be the first call made into the SDL library, |
1526 | * if not the very first thing done at program startup time. |
1527 | * |
1528 | * \param malloc_func custom malloc function. |
1529 | * \param calloc_func custom calloc function. |
1530 | * \param realloc_func custom realloc function. |
1531 | * \param free_func custom free function. |
1532 | * \returns true on success or false on failure; call SDL_GetError() for more |
1533 | * information. |
1534 | * |
1535 | * \threadsafety It is safe to call this function from any thread, but one |
1536 | * should not replace the memory functions once any allocations |
1537 | * are made! |
1538 | * |
1539 | * \since This function is available since SDL 3.2.0. |
1540 | * |
1541 | * \sa SDL_GetMemoryFunctions |
1542 | * \sa SDL_GetOriginalMemoryFunctions |
1543 | */ |
1544 | extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, |
1545 | SDL_calloc_func calloc_func, |
1546 | SDL_realloc_func realloc_func, |
1547 | SDL_free_func free_func); |
1548 | |
1549 | /** |
1550 | * Allocate memory aligned to a specific alignment. |
1551 | * |
1552 | * The memory returned by this function must be freed with SDL_aligned_free(), |
1553 | * _not_ SDL_free(). |
1554 | * |
1555 | * If `alignment` is less than the size of `void *`, it will be increased to |
1556 | * match that. |
1557 | * |
1558 | * The returned memory address will be a multiple of the alignment value, and |
1559 | * the size of the memory allocated will be a multiple of the alignment value. |
1560 | * |
1561 | * \param alignment the alignment of the memory. |
1562 | * \param size the size to allocate. |
1563 | * \returns a pointer to the aligned memory, or NULL if allocation failed. |
1564 | * |
1565 | * \threadsafety It is safe to call this function from any thread. |
1566 | * |
1567 | * \since This function is available since SDL 3.2.0. |
1568 | * |
1569 | * \sa SDL_aligned_free |
1570 | */ |
1571 | extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size); |
1572 | |
1573 | /** |
1574 | * Free memory allocated by SDL_aligned_alloc(). |
1575 | * |
1576 | * The pointer is no longer valid after this call and cannot be dereferenced |
1577 | * anymore. |
1578 | * |
1579 | * If `mem` is NULL, this function does nothing. |
1580 | * |
1581 | * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL. |
1582 | * |
1583 | * \threadsafety It is safe to call this function from any thread. |
1584 | * |
1585 | * \since This function is available since SDL 3.2.0. |
1586 | * |
1587 | * \sa SDL_aligned_alloc |
1588 | */ |
1589 | extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem); |
1590 | |
1591 | /** |
1592 | * Get the number of outstanding (unfreed) allocations. |
1593 | * |
1594 | * \returns the number of allocations or -1 if allocation counting is |
1595 | * disabled. |
1596 | * |
1597 | * \threadsafety It is safe to call this function from any thread. |
1598 | * |
1599 | * \since This function is available since SDL 3.2.0. |
1600 | */ |
1601 | extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void); |
1602 | |
1603 | /** |
1604 | * A thread-safe set of environment variables |
1605 | * |
1606 | * \since This struct is available since SDL 3.2.0. |
1607 | * |
1608 | * \sa SDL_GetEnvironment |
1609 | * \sa SDL_CreateEnvironment |
1610 | * \sa SDL_GetEnvironmentVariable |
1611 | * \sa SDL_GetEnvironmentVariables |
1612 | * \sa SDL_SetEnvironmentVariable |
1613 | * \sa SDL_UnsetEnvironmentVariable |
1614 | * \sa SDL_DestroyEnvironment |
1615 | */ |
1616 | typedef struct SDL_Environment SDL_Environment; |
1617 | |
1618 | /** |
1619 | * Get the process environment. |
1620 | * |
1621 | * This is initialized at application start and is not affected by setenv() |
1622 | * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and |
1623 | * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or |
1624 | * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist |
1625 | * in the C runtime environment after SDL_Quit(). |
1626 | * |
1627 | * \returns a pointer to the environment for the process or NULL on failure; |
1628 | * call SDL_GetError() for more information. |
1629 | * |
1630 | * \threadsafety It is safe to call this function from any thread. |
1631 | * |
1632 | * \since This function is available since SDL 3.2.0. |
1633 | * |
1634 | * \sa SDL_GetEnvironmentVariable |
1635 | * \sa SDL_GetEnvironmentVariables |
1636 | * \sa SDL_SetEnvironmentVariable |
1637 | * \sa SDL_UnsetEnvironmentVariable |
1638 | */ |
1639 | extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void); |
1640 | |
1641 | /** |
1642 | * Create a set of environment variables |
1643 | * |
1644 | * \param populated true to initialize it from the C runtime environment, |
1645 | * false to create an empty environment. |
1646 | * \returns a pointer to the new environment or NULL on failure; call |
1647 | * SDL_GetError() for more information. |
1648 | * |
1649 | * \threadsafety If `populated` is false, it is safe to call this function |
1650 | * from any thread, otherwise it is safe if no other threads are |
1651 | * calling setenv() or unsetenv() |
1652 | * |
1653 | * \since This function is available since SDL 3.2.0. |
1654 | * |
1655 | * \sa SDL_GetEnvironmentVariable |
1656 | * \sa SDL_GetEnvironmentVariables |
1657 | * \sa SDL_SetEnvironmentVariable |
1658 | * \sa SDL_UnsetEnvironmentVariable |
1659 | * \sa SDL_DestroyEnvironment |
1660 | */ |
1661 | extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated); |
1662 | |
1663 | /** |
1664 | * Get the value of a variable in the environment. |
1665 | * |
1666 | * \param env the environment to query. |
1667 | * \param name the name of the variable to get. |
1668 | * \returns a pointer to the value of the variable or NULL if it can't be |
1669 | * found. |
1670 | * |
1671 | * \threadsafety It is safe to call this function from any thread. |
1672 | * |
1673 | * \since This function is available since SDL 3.2.0. |
1674 | * |
1675 | * \sa SDL_GetEnvironment |
1676 | * \sa SDL_CreateEnvironment |
1677 | * \sa SDL_GetEnvironmentVariables |
1678 | * \sa SDL_SetEnvironmentVariable |
1679 | * \sa SDL_UnsetEnvironmentVariable |
1680 | */ |
1681 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name); |
1682 | |
1683 | /** |
1684 | * Get all variables in the environment. |
1685 | * |
1686 | * \param env the environment to query. |
1687 | * \returns a NULL terminated array of pointers to environment variables in |
1688 | * the form "variable=value" or NULL on failure; call SDL_GetError() |
1689 | * for more information. This is a single allocation that should be |
1690 | * freed with SDL_free() when it is no longer needed. |
1691 | * |
1692 | * \threadsafety It is safe to call this function from any thread. |
1693 | * |
1694 | * \since This function is available since SDL 3.2.0. |
1695 | * |
1696 | * \sa SDL_GetEnvironment |
1697 | * \sa SDL_CreateEnvironment |
1698 | * \sa SDL_GetEnvironmentVariables |
1699 | * \sa SDL_SetEnvironmentVariable |
1700 | * \sa SDL_UnsetEnvironmentVariable |
1701 | */ |
1702 | extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env); |
1703 | |
1704 | /** |
1705 | * Set the value of a variable in the environment. |
1706 | * |
1707 | * \param env the environment to modify. |
1708 | * \param name the name of the variable to set. |
1709 | * \param value the value of the variable to set. |
1710 | * \param overwrite true to overwrite the variable if it exists, false to |
1711 | * return success without setting the variable if it already |
1712 | * exists. |
1713 | * \returns true on success or false on failure; call SDL_GetError() for more |
1714 | * information. |
1715 | * |
1716 | * \threadsafety It is safe to call this function from any thread. |
1717 | * |
1718 | * \since This function is available since SDL 3.2.0. |
1719 | * |
1720 | * \sa SDL_GetEnvironment |
1721 | * \sa SDL_CreateEnvironment |
1722 | * \sa SDL_GetEnvironmentVariable |
1723 | * \sa SDL_GetEnvironmentVariables |
1724 | * \sa SDL_UnsetEnvironmentVariable |
1725 | */ |
1726 | extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite); |
1727 | |
1728 | /** |
1729 | * Clear a variable from the environment. |
1730 | * |
1731 | * \param env the environment to modify. |
1732 | * \param name the name of the variable to unset. |
1733 | * \returns true on success or false on failure; call SDL_GetError() for more |
1734 | * information. |
1735 | * |
1736 | * \threadsafety It is safe to call this function from any thread. |
1737 | * |
1738 | * \since This function is available since SDL 3.2.0. |
1739 | * |
1740 | * \sa SDL_GetEnvironment |
1741 | * \sa SDL_CreateEnvironment |
1742 | * \sa SDL_GetEnvironmentVariable |
1743 | * \sa SDL_GetEnvironmentVariables |
1744 | * \sa SDL_SetEnvironmentVariable |
1745 | * \sa SDL_UnsetEnvironmentVariable |
1746 | */ |
1747 | extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name); |
1748 | |
1749 | /** |
1750 | * Destroy a set of environment variables. |
1751 | * |
1752 | * \param env the environment to destroy. |
1753 | * |
1754 | * \threadsafety It is safe to call this function from any thread, as long as |
1755 | * the environment is no longer in use. |
1756 | * |
1757 | * \since This function is available since SDL 3.2.0. |
1758 | * |
1759 | * \sa SDL_CreateEnvironment |
1760 | */ |
1761 | extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env); |
1762 | |
1763 | /** |
1764 | * Get the value of a variable in the environment. |
1765 | * |
1766 | * This function uses SDL's cached copy of the environment and is thread-safe. |
1767 | * |
1768 | * \param name the name of the variable to get. |
1769 | * \returns a pointer to the value of the variable or NULL if it can't be |
1770 | * found. |
1771 | * |
1772 | * \threadsafety It is safe to call this function from any thread. |
1773 | * |
1774 | * \since This function is available since SDL 3.2.0. |
1775 | */ |
1776 | extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name); |
1777 | |
1778 | /** |
1779 | * Get the value of a variable in the environment. |
1780 | * |
1781 | * This function bypasses SDL's cached copy of the environment and is not |
1782 | * thread-safe. |
1783 | * |
1784 | * \param name the name of the variable to get. |
1785 | * \returns a pointer to the value of the variable or NULL if it can't be |
1786 | * found. |
1787 | * |
1788 | * \threadsafety This function is not thread safe, consider using SDL_getenv() |
1789 | * instead. |
1790 | * |
1791 | * \since This function is available since SDL 3.2.0. |
1792 | * |
1793 | * \sa SDL_getenv |
1794 | */ |
1795 | extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name); |
1796 | |
1797 | /** |
1798 | * Set the value of a variable in the environment. |
1799 | * |
1800 | * \param name the name of the variable to set. |
1801 | * \param value the value of the variable to set. |
1802 | * \param overwrite 1 to overwrite the variable if it exists, 0 to return |
1803 | * success without setting the variable if it already exists. |
1804 | * \returns 0 on success, -1 on error. |
1805 | * |
1806 | * \threadsafety This function is not thread safe, consider using |
1807 | * SDL_SetEnvironmentVariable() instead. |
1808 | * |
1809 | * \since This function is available since SDL 3.2.0. |
1810 | * |
1811 | * \sa SDL_SetEnvironmentVariable |
1812 | */ |
1813 | extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite); |
1814 | |
1815 | /** |
1816 | * Clear a variable from the environment. |
1817 | * |
1818 | * \param name the name of the variable to unset. |
1819 | * \returns 0 on success, -1 on error. |
1820 | * |
1821 | * \threadsafety This function is not thread safe, consider using |
1822 | * SDL_UnsetEnvironmentVariable() instead. |
1823 | * |
1824 | * \since This function is available since SDL 3.2.0. |
1825 | * |
1826 | * \sa SDL_UnsetEnvironmentVariable |
1827 | */ |
1828 | extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name); |
1829 | |
1830 | /** |
1831 | * A callback used with SDL sorting and binary search functions. |
1832 | * |
1833 | * \param a a pointer to the first element being compared. |
1834 | * \param b a pointer to the second element being compared. |
1835 | * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted |
1836 | * before `a`, 0 if they are equal. If two elements are equal, their |
1837 | * order in the sorted array is undefined. |
1838 | * |
1839 | * \since This callback is available since SDL 3.2.0. |
1840 | * |
1841 | * \sa SDL_bsearch |
1842 | * \sa SDL_qsort |
1843 | */ |
1844 | typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b); |
1845 | |
1846 | /** |
1847 | * Sort an array. |
1848 | * |
1849 | * For example: |
1850 | * |
1851 | * ```c |
1852 | * typedef struct { |
1853 | * int key; |
1854 | * const char *string; |
1855 | * } data; |
1856 | * |
1857 | * int SDLCALL compare(const void *a, const void *b) |
1858 | * { |
1859 | * const data *A = (const data *)a; |
1860 | * const data *B = (const data *)b; |
1861 | * |
1862 | * if (A->n < B->n) { |
1863 | * return -1; |
1864 | * } else if (B->n < A->n) { |
1865 | * return 1; |
1866 | * } else { |
1867 | * return 0; |
1868 | * } |
1869 | * } |
1870 | * |
1871 | * data values[] = { |
1872 | * { 3, "third" }, { 1, "first" }, { 2, "second" } |
1873 | * }; |
1874 | * |
1875 | * SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare); |
1876 | * ``` |
1877 | * |
1878 | * \param base a pointer to the start of the array. |
1879 | * \param nmemb the number of elements in the array. |
1880 | * \param size the size of the elements in the array. |
1881 | * \param compare a function used to compare elements in the array. |
1882 | * |
1883 | * \threadsafety It is safe to call this function from any thread. |
1884 | * |
1885 | * \since This function is available since SDL 3.2.0. |
1886 | * |
1887 | * \sa SDL_bsearch |
1888 | * \sa SDL_qsort_r |
1889 | */ |
1890 | extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare); |
1891 | |
1892 | /** |
1893 | * Perform a binary search on a previously sorted array. |
1894 | * |
1895 | * For example: |
1896 | * |
1897 | * ```c |
1898 | * typedef struct { |
1899 | * int key; |
1900 | * const char *string; |
1901 | * } data; |
1902 | * |
1903 | * int SDLCALL compare(const void *a, const void *b) |
1904 | * { |
1905 | * const data *A = (const data *)a; |
1906 | * const data *B = (const data *)b; |
1907 | * |
1908 | * if (A->n < B->n) { |
1909 | * return -1; |
1910 | * } else if (B->n < A->n) { |
1911 | * return 1; |
1912 | * } else { |
1913 | * return 0; |
1914 | * } |
1915 | * } |
1916 | * |
1917 | * data values[] = { |
1918 | * { 1, "first" }, { 2, "second" }, { 3, "third" } |
1919 | * }; |
1920 | * data key = { 2, NULL }; |
1921 | * |
1922 | * data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare); |
1923 | * ``` |
1924 | * |
1925 | * \param key a pointer to a key equal to the element being searched for. |
1926 | * \param base a pointer to the start of the array. |
1927 | * \param nmemb the number of elements in the array. |
1928 | * \param size the size of the elements in the array. |
1929 | * \param compare a function used to compare elements in the array. |
1930 | * \returns a pointer to the matching element in the array, or NULL if not |
1931 | * found. |
1932 | * |
1933 | * \threadsafety It is safe to call this function from any thread. |
1934 | * |
1935 | * \since This function is available since SDL 3.2.0. |
1936 | * |
1937 | * \sa SDL_bsearch_r |
1938 | * \sa SDL_qsort |
1939 | */ |
1940 | extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare); |
1941 | |
1942 | /** |
1943 | * A callback used with SDL sorting and binary search functions. |
1944 | * |
1945 | * \param userdata the `userdata` pointer passed to the sort function. |
1946 | * \param a a pointer to the first element being compared. |
1947 | * \param b a pointer to the second element being compared. |
1948 | * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted |
1949 | * before `a`, 0 if they are equal. If two elements are equal, their |
1950 | * order in the sorted array is undefined. |
1951 | * |
1952 | * \since This callback is available since SDL 3.2.0. |
1953 | * |
1954 | * \sa SDL_qsort_r |
1955 | * \sa SDL_bsearch_r |
1956 | */ |
1957 | typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b); |
1958 | |
1959 | /** |
1960 | * Sort an array, passing a userdata pointer to the compare function. |
1961 | * |
1962 | * For example: |
1963 | * |
1964 | * ```c |
1965 | * typedef enum { |
1966 | * sort_increasing, |
1967 | * sort_decreasing, |
1968 | * } sort_method; |
1969 | * |
1970 | * typedef struct { |
1971 | * int key; |
1972 | * const char *string; |
1973 | * } data; |
1974 | * |
1975 | * int SDLCALL compare(const void *userdata, const void *a, const void *b) |
1976 | * { |
1977 | * sort_method method = (sort_method)(uintptr_t)userdata; |
1978 | * const data *A = (const data *)a; |
1979 | * const data *B = (const data *)b; |
1980 | * |
1981 | * if (A->key < B->key) { |
1982 | * return (method == sort_increasing) ? -1 : 1; |
1983 | * } else if (B->key < A->key) { |
1984 | * return (method == sort_increasing) ? 1 : -1; |
1985 | * } else { |
1986 | * return 0; |
1987 | * } |
1988 | * } |
1989 | * |
1990 | * data values[] = { |
1991 | * { 3, "third" }, { 1, "first" }, { 2, "second" } |
1992 | * }; |
1993 | * |
1994 | * SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing); |
1995 | * ``` |
1996 | * |
1997 | * \param base a pointer to the start of the array. |
1998 | * \param nmemb the number of elements in the array. |
1999 | * \param size the size of the elements in the array. |
2000 | * \param compare a function used to compare elements in the array. |
2001 | * \param userdata a pointer to pass to the compare function. |
2002 | * |
2003 | * \threadsafety It is safe to call this function from any thread. |
2004 | * |
2005 | * \since This function is available since SDL 3.2.0. |
2006 | * |
2007 | * \sa SDL_bsearch_r |
2008 | * \sa SDL_qsort |
2009 | */ |
2010 | extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata); |
2011 | |
2012 | /** |
2013 | * Perform a binary search on a previously sorted array, passing a userdata |
2014 | * pointer to the compare function. |
2015 | * |
2016 | * For example: |
2017 | * |
2018 | * ```c |
2019 | * typedef enum { |
2020 | * sort_increasing, |
2021 | * sort_decreasing, |
2022 | * } sort_method; |
2023 | * |
2024 | * typedef struct { |
2025 | * int key; |
2026 | * const char *string; |
2027 | * } data; |
2028 | * |
2029 | * int SDLCALL compare(const void *userdata, const void *a, const void *b) |
2030 | * { |
2031 | * sort_method method = (sort_method)(uintptr_t)userdata; |
2032 | * const data *A = (const data *)a; |
2033 | * const data *B = (const data *)b; |
2034 | * |
2035 | * if (A->key < B->key) { |
2036 | * return (method == sort_increasing) ? -1 : 1; |
2037 | * } else if (B->key < A->key) { |
2038 | * return (method == sort_increasing) ? 1 : -1; |
2039 | * } else { |
2040 | * return 0; |
2041 | * } |
2042 | * } |
2043 | * |
2044 | * data values[] = { |
2045 | * { 1, "first" }, { 2, "second" }, { 3, "third" } |
2046 | * }; |
2047 | * data key = { 2, NULL }; |
2048 | * |
2049 | * data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing); |
2050 | * ``` |
2051 | * |
2052 | * \param key a pointer to a key equal to the element being searched for. |
2053 | * \param base a pointer to the start of the array. |
2054 | * \param nmemb the number of elements in the array. |
2055 | * \param size the size of the elements in the array. |
2056 | * \param compare a function used to compare elements in the array. |
2057 | * \param userdata a pointer to pass to the compare function. |
2058 | * \returns a pointer to the matching element in the array, or NULL if not |
2059 | * found. |
2060 | * |
2061 | * \threadsafety It is safe to call this function from any thread. |
2062 | * |
2063 | * \since This function is available since SDL 3.2.0. |
2064 | * |
2065 | * \sa SDL_bsearch |
2066 | * \sa SDL_qsort_r |
2067 | */ |
2068 | extern SDL_DECLSPEC void * SDLCALL SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata); |
2069 | |
2070 | /** |
2071 | * Compute the absolute value of `x`. |
2072 | * |
2073 | * \param x an integer value. |
2074 | * \returns the absolute value of x. |
2075 | * |
2076 | * \threadsafety It is safe to call this function from any thread. |
2077 | * |
2078 | * \since This function is available since SDL 3.2.0. |
2079 | */ |
2080 | extern SDL_DECLSPEC int SDLCALL SDL_abs(int x); |
2081 | |
2082 | /** |
2083 | * Return the lesser of two values. |
2084 | * |
2085 | * This is a helper macro that might be more clear than writing out the |
2086 | * comparisons directly, and works with any type that can be compared with the |
2087 | * `<` operator. However, it double-evaluates both its parameters, so do not |
2088 | * use expressions with side-effects here. |
2089 | * |
2090 | * \param x the first value to compare. |
2091 | * \param y the second value to compare. |
2092 | * \returns the lesser of `x` and `y`. |
2093 | * |
2094 | * \threadsafety It is safe to call this macro from any thread. |
2095 | * |
2096 | * \since This macro is available since SDL 3.2.0. |
2097 | */ |
2098 | #define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) |
2099 | |
2100 | /** |
2101 | * Return the greater of two values. |
2102 | * |
2103 | * This is a helper macro that might be more clear than writing out the |
2104 | * comparisons directly, and works with any type that can be compared with the |
2105 | * `>` operator. However, it double-evaluates both its parameters, so do not |
2106 | * use expressions with side-effects here. |
2107 | * |
2108 | * \param x the first value to compare. |
2109 | * \param y the second value to compare. |
2110 | * \returns the greater of `x` and `y`. |
2111 | * |
2112 | * \threadsafety It is safe to call this macro from any thread. |
2113 | * |
2114 | * \since This macro is available since SDL 3.2.0. |
2115 | */ |
2116 | #define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) |
2117 | |
2118 | /** |
2119 | * Return a value clamped to a range. |
2120 | * |
2121 | * If `x` is outside the range a values between `a` and `b`, the returned |
2122 | * value will be `a` or `b` as appropriate. Otherwise, `x` is returned. |
2123 | * |
2124 | * This macro will produce incorrect results if `b` is less than `a`. |
2125 | * |
2126 | * This is a helper macro that might be more clear than writing out the |
2127 | * comparisons directly, and works with any type that can be compared with the |
2128 | * `<` and `>` operators. However, it double-evaluates all its parameters, so |
2129 | * do not use expressions with side-effects here. |
2130 | * |
2131 | * \param x the value to compare. |
2132 | * \param a the low end value. |
2133 | * \param b the high end value. |
2134 | * \returns x, clamped between a and b. |
2135 | * |
2136 | * \threadsafety It is safe to call this macro from any thread. |
2137 | * |
2138 | * \since This macro is available since SDL 3.2.0. |
2139 | */ |
2140 | #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x))) |
2141 | |
2142 | /** |
2143 | * Query if a character is alphabetic (a letter). |
2144 | * |
2145 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2146 | * for English 'a-z' and 'A-Z' as true. |
2147 | * |
2148 | * \param x character value to check. |
2149 | * \returns non-zero if x falls within the character class, zero otherwise. |
2150 | * |
2151 | * \threadsafety It is safe to call this function from any thread. |
2152 | * |
2153 | * \since This function is available since SDL 3.2.0. |
2154 | */ |
2155 | extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x); |
2156 | |
2157 | /** |
2158 | * Query if a character is alphabetic (a letter) or a number. |
2159 | * |
2160 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2161 | * for English 'a-z', 'A-Z', and '0-9' as true. |
2162 | * |
2163 | * \param x character value to check. |
2164 | * \returns non-zero if x falls within the character class, zero otherwise. |
2165 | * |
2166 | * \threadsafety It is safe to call this function from any thread. |
2167 | * |
2168 | * \since This function is available since SDL 3.2.0. |
2169 | */ |
2170 | extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x); |
2171 | |
2172 | /** |
2173 | * Report if a character is blank (a space or tab). |
2174 | * |
2175 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2176 | * 0x20 (space) or 0x9 (tab) as true. |
2177 | * |
2178 | * \param x character value to check. |
2179 | * \returns non-zero if x falls within the character class, zero otherwise. |
2180 | * |
2181 | * \threadsafety It is safe to call this function from any thread. |
2182 | * |
2183 | * \since This function is available since SDL 3.2.0. |
2184 | */ |
2185 | extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x); |
2186 | |
2187 | /** |
2188 | * Report if a character is a control character. |
2189 | * |
2190 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2191 | * 0 through 0x1F, and 0x7F, as true. |
2192 | * |
2193 | * \param x character value to check. |
2194 | * \returns non-zero if x falls within the character class, zero otherwise. |
2195 | * |
2196 | * \threadsafety It is safe to call this function from any thread. |
2197 | * |
2198 | * \since This function is available since SDL 3.2.0. |
2199 | */ |
2200 | extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x); |
2201 | |
2202 | /** |
2203 | * Report if a character is a numeric digit. |
2204 | * |
2205 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2206 | * '0' (0x30) through '9' (0x39), as true. |
2207 | * |
2208 | * \param x character value to check. |
2209 | * \returns non-zero if x falls within the character class, zero otherwise. |
2210 | * |
2211 | * \threadsafety It is safe to call this function from any thread. |
2212 | * |
2213 | * \since This function is available since SDL 3.2.0. |
2214 | */ |
2215 | extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x); |
2216 | |
2217 | /** |
2218 | * Report if a character is a hexadecimal digit. |
2219 | * |
2220 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2221 | * 'A' through 'F', 'a' through 'f', and '0' through '9', as true. |
2222 | * |
2223 | * \param x character value to check. |
2224 | * \returns non-zero if x falls within the character class, zero otherwise. |
2225 | * |
2226 | * \threadsafety It is safe to call this function from any thread. |
2227 | * |
2228 | * \since This function is available since SDL 3.2.0. |
2229 | */ |
2230 | extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x); |
2231 | |
2232 | /** |
2233 | * Report if a character is a punctuation mark. |
2234 | * |
2235 | * **WARNING**: Regardless of system locale, this is equivalent to |
2236 | * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`. |
2237 | * |
2238 | * \param x character value to check. |
2239 | * \returns non-zero if x falls within the character class, zero otherwise. |
2240 | * |
2241 | * \threadsafety It is safe to call this function from any thread. |
2242 | * |
2243 | * \since This function is available since SDL 3.2.0. |
2244 | * |
2245 | * \sa SDL_isgraph |
2246 | * \sa SDL_isalnum |
2247 | */ |
2248 | extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x); |
2249 | |
2250 | /** |
2251 | * Report if a character is whitespace. |
2252 | * |
2253 | * **WARNING**: Regardless of system locale, this will only treat the |
2254 | * following ASCII values as true: |
2255 | * |
2256 | * - space (0x20) |
2257 | * - tab (0x09) |
2258 | * - newline (0x0A) |
2259 | * - vertical tab (0x0B) |
2260 | * - form feed (0x0C) |
2261 | * - return (0x0D) |
2262 | * |
2263 | * \param x character value to check. |
2264 | * \returns non-zero if x falls within the character class, zero otherwise. |
2265 | * |
2266 | * \threadsafety It is safe to call this function from any thread. |
2267 | * |
2268 | * \since This function is available since SDL 3.2.0. |
2269 | */ |
2270 | extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x); |
2271 | |
2272 | /** |
2273 | * Report if a character is upper case. |
2274 | * |
2275 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2276 | * 'A' through 'Z' as true. |
2277 | * |
2278 | * \param x character value to check. |
2279 | * \returns non-zero if x falls within the character class, zero otherwise. |
2280 | * |
2281 | * \threadsafety It is safe to call this function from any thread. |
2282 | * |
2283 | * \since This function is available since SDL 3.2.0. |
2284 | */ |
2285 | extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x); |
2286 | |
2287 | /** |
2288 | * Report if a character is lower case. |
2289 | * |
2290 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2291 | * 'a' through 'z' as true. |
2292 | * |
2293 | * \param x character value to check. |
2294 | * \returns non-zero if x falls within the character class, zero otherwise. |
2295 | * |
2296 | * \threadsafety It is safe to call this function from any thread. |
2297 | * |
2298 | * \since This function is available since SDL 3.2.0. |
2299 | */ |
2300 | extern SDL_DECLSPEC int SDLCALL SDL_islower(int x); |
2301 | |
2302 | /** |
2303 | * Report if a character is "printable". |
2304 | * |
2305 | * Be advised that "printable" has a definition that goes back to text |
2306 | * terminals from the dawn of computing, making this a sort of special case |
2307 | * function that is not suitable for Unicode (or most any) text management. |
2308 | * |
2309 | * **WARNING**: Regardless of system locale, this will only treat ASCII values |
2310 | * ' ' (0x20) through '~' (0x7E) as true. |
2311 | * |
2312 | * \param x character value to check. |
2313 | * \returns non-zero if x falls within the character class, zero otherwise. |
2314 | * |
2315 | * \threadsafety It is safe to call this function from any thread. |
2316 | * |
2317 | * \since This function is available since SDL 3.2.0. |
2318 | */ |
2319 | extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x); |
2320 | |
2321 | /** |
2322 | * Report if a character is any "printable" except space. |
2323 | * |
2324 | * Be advised that "printable" has a definition that goes back to text |
2325 | * terminals from the dawn of computing, making this a sort of special case |
2326 | * function that is not suitable for Unicode (or most any) text management. |
2327 | * |
2328 | * **WARNING**: Regardless of system locale, this is equivalent to |
2329 | * `(SDL_isprint(x)) && ((x) != ' ')`. |
2330 | * |
2331 | * \param x character value to check. |
2332 | * \returns non-zero if x falls within the character class, zero otherwise. |
2333 | * |
2334 | * \threadsafety It is safe to call this function from any thread. |
2335 | * |
2336 | * \since This function is available since SDL 3.2.0. |
2337 | * |
2338 | * \sa SDL_isprint |
2339 | */ |
2340 | extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x); |
2341 | |
2342 | /** |
2343 | * Convert low-ASCII English letters to uppercase. |
2344 | * |
2345 | * **WARNING**: Regardless of system locale, this will only convert ASCII |
2346 | * values 'a' through 'z' to uppercase. |
2347 | * |
2348 | * This function returns the uppercase equivalent of `x`. If a character |
2349 | * cannot be converted, or is already uppercase, this function returns `x`. |
2350 | * |
2351 | * \param x character value to check. |
2352 | * \returns capitalized version of x, or x if no conversion available. |
2353 | * |
2354 | * \threadsafety It is safe to call this function from any thread. |
2355 | * |
2356 | * \since This function is available since SDL 3.2.0. |
2357 | */ |
2358 | extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x); |
2359 | |
2360 | /** |
2361 | * Convert low-ASCII English letters to lowercase. |
2362 | * |
2363 | * **WARNING**: Regardless of system locale, this will only convert ASCII |
2364 | * values 'A' through 'Z' to lowercase. |
2365 | * |
2366 | * This function returns the lowercase equivalent of `x`. If a character |
2367 | * cannot be converted, or is already lowercase, this function returns `x`. |
2368 | * |
2369 | * \param x character value to check. |
2370 | * \returns lowercase version of x, or x if no conversion available. |
2371 | * |
2372 | * \threadsafety It is safe to call this function from any thread. |
2373 | * |
2374 | * \since This function is available since SDL 3.2.0. |
2375 | */ |
2376 | extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x); |
2377 | |
2378 | /** |
2379 | * Calculate a CRC-16 value. |
2380 | * |
2381 | * https://en.wikipedia.org/wiki/Cyclic_redundancy_check |
2382 | * |
2383 | * This function can be called multiple times, to stream data to be |
2384 | * checksummed in blocks. Each call must provide the previous CRC-16 return |
2385 | * value to be updated with the next block. The first call to this function |
2386 | * for a set of blocks should pass in a zero CRC value. |
2387 | * |
2388 | * \param crc the current checksum for this data set, or 0 for a new data set. |
2389 | * \param data a new block of data to add to the checksum. |
2390 | * \param len the size, in bytes, of the new block of data. |
2391 | * \returns a CRC-16 checksum value of all blocks in the data set. |
2392 | * |
2393 | * \threadsafety It is safe to call this function from any thread. |
2394 | * |
2395 | * \since This function is available since SDL 3.2.0. |
2396 | */ |
2397 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len); |
2398 | |
2399 | /** |
2400 | * Calculate a CRC-32 value. |
2401 | * |
2402 | * https://en.wikipedia.org/wiki/Cyclic_redundancy_check |
2403 | * |
2404 | * This function can be called multiple times, to stream data to be |
2405 | * checksummed in blocks. Each call must provide the previous CRC-32 return |
2406 | * value to be updated with the next block. The first call to this function |
2407 | * for a set of blocks should pass in a zero CRC value. |
2408 | * |
2409 | * \param crc the current checksum for this data set, or 0 for a new data set. |
2410 | * \param data a new block of data to add to the checksum. |
2411 | * \param len the size, in bytes, of the new block of data. |
2412 | * \returns a CRC-32 checksum value of all blocks in the data set. |
2413 | * |
2414 | * \threadsafety It is safe to call this function from any thread. |
2415 | * |
2416 | * \since This function is available since SDL 3.2.0. |
2417 | */ |
2418 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len); |
2419 | |
2420 | /** |
2421 | * Calculate a 32-bit MurmurHash3 value for a block of data. |
2422 | * |
2423 | * https://en.wikipedia.org/wiki/MurmurHash |
2424 | * |
2425 | * A seed may be specified, which changes the final results consistently, but |
2426 | * this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous |
2427 | * result from this function back into itself as the next seed value to |
2428 | * calculate a hash in chunks; it won't produce the same hash as it would if |
2429 | * the same data was provided in a single call. |
2430 | * |
2431 | * If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not |
2432 | * cryptographically secure, so it shouldn't be used for hashing top-secret |
2433 | * data. |
2434 | * |
2435 | * \param data the data to be hashed. |
2436 | * \param len the size of data, in bytes. |
2437 | * \param seed a value that alters the final hash value. |
2438 | * \returns a Murmur3 32-bit hash value. |
2439 | * |
2440 | * \threadsafety It is safe to call this function from any thread. |
2441 | * |
2442 | * \since This function is available since SDL 3.2.0. |
2443 | */ |
2444 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed); |
2445 | |
2446 | /** |
2447 | * Copy non-overlapping memory. |
2448 | * |
2449 | * The memory regions must not overlap. If they do, use SDL_memmove() instead. |
2450 | * |
2451 | * \param dst The destination memory region. Must not be NULL, and must not |
2452 | * overlap with `src`. |
2453 | * \param src The source memory region. Must not be NULL, and must not overlap |
2454 | * with `dst`. |
2455 | * \param len The length in bytes of both `dst` and `src`. |
2456 | * \returns `dst`. |
2457 | * |
2458 | * \threadsafety It is safe to call this function from any thread. |
2459 | * |
2460 | * \since This function is available since SDL 3.2.0. |
2461 | * |
2462 | * \sa SDL_memmove |
2463 | */ |
2464 | extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len); |
2465 | |
2466 | /* Take advantage of compiler optimizations for memcpy */ |
2467 | #ifndef SDL_SLOW_MEMCPY |
2468 | #ifdef SDL_memcpy |
2469 | #undef SDL_memcpy |
2470 | #endif |
2471 | #define SDL_memcpy memcpy |
2472 | #endif |
2473 | |
2474 | |
2475 | /** |
2476 | * A macro to copy memory between objects, with basic type checking. |
2477 | * |
2478 | * SDL_memcpy and SDL_memmove do not care where you copy memory to and from, |
2479 | * which can lead to bugs. This macro aims to avoid most of those bugs by |
2480 | * making sure that the source and destination are both pointers to objects |
2481 | * that are the same size. It does not check that the objects are the same |
2482 | * _type_, just that the copy will not overflow either object. |
2483 | * |
2484 | * The size check happens at compile time, and the compiler will throw an |
2485 | * error if the objects are different sizes. |
2486 | * |
2487 | * Generally this is intended to copy a single object, not an array. |
2488 | * |
2489 | * This macro looks like it double-evaluates its parameters, but the extras |
2490 | * them are in `sizeof` sections, which generate no code nor side-effects. |
2491 | * |
2492 | * \param dst a pointer to the destination object. Must not be NULL. |
2493 | * \param src a pointer to the source object. Must not be NULL. |
2494 | * |
2495 | * \threadsafety It is safe to call this function from any thread. |
2496 | * |
2497 | * \since This function is available since SDL 3.2.0. |
2498 | */ |
2499 | #define SDL_copyp(dst, src) \ |
2500 | { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \ |
2501 | SDL_memcpy((dst), (src), sizeof(*(src))) |
2502 | |
2503 | /** |
2504 | * Copy memory ranges that might overlap. |
2505 | * |
2506 | * It is okay for the memory regions to overlap. If you are confident that the |
2507 | * regions never overlap, using SDL_memcpy() may improve performance. |
2508 | * |
2509 | * \param dst The destination memory region. Must not be NULL. |
2510 | * \param src The source memory region. Must not be NULL. |
2511 | * \param len The length in bytes of both `dst` and `src`. |
2512 | * \returns `dst`. |
2513 | * |
2514 | * \threadsafety It is safe to call this function from any thread. |
2515 | * |
2516 | * \since This function is available since SDL 3.2.0. |
2517 | * |
2518 | * \sa SDL_memcpy |
2519 | */ |
2520 | extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len); |
2521 | |
2522 | /* Take advantage of compiler optimizations for memmove */ |
2523 | #ifndef SDL_SLOW_MEMMOVE |
2524 | #ifdef SDL_memmove |
2525 | #undef SDL_memmove |
2526 | #endif |
2527 | #define SDL_memmove memmove |
2528 | #endif |
2529 | |
2530 | /** |
2531 | * Initialize all bytes of buffer of memory to a specific value. |
2532 | * |
2533 | * This function will set `len` bytes, pointed to by `dst`, to the value |
2534 | * specified in `c`. |
2535 | * |
2536 | * Despite `c` being an `int` instead of a `char`, this only operates on |
2537 | * bytes; `c` must be a value between 0 and 255, inclusive. |
2538 | * |
2539 | * \param dst the destination memory region. Must not be NULL. |
2540 | * \param c the byte value to set. |
2541 | * \param len the length, in bytes, to set in `dst`. |
2542 | * \returns `dst`. |
2543 | * |
2544 | * \threadsafety It is safe to call this function from any thread. |
2545 | * |
2546 | * \since This function is available since SDL 3.2.0. |
2547 | */ |
2548 | extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len); |
2549 | |
2550 | /** |
2551 | * Initialize all 32-bit words of buffer of memory to a specific value. |
2552 | * |
2553 | * This function will set a buffer of `dwords` Uint32 values, pointed to by |
2554 | * `dst`, to the value specified in `val`. |
2555 | * |
2556 | * Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited |
2557 | * to a range of 0-255. |
2558 | * |
2559 | * \param dst the destination memory region. Must not be NULL. |
2560 | * \param val the Uint32 value to set. |
2561 | * \param dwords the number of Uint32 values to set in `dst`. |
2562 | * \returns `dst`. |
2563 | * |
2564 | * \threadsafety It is safe to call this function from any thread. |
2565 | * |
2566 | * \since This function is available since SDL 3.2.0. |
2567 | */ |
2568 | extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords); |
2569 | |
2570 | /* Take advantage of compiler optimizations for memset */ |
2571 | #ifndef SDL_SLOW_MEMSET |
2572 | #ifdef SDL_memset |
2573 | #undef SDL_memset |
2574 | #endif |
2575 | #define SDL_memset memset |
2576 | #endif |
2577 | |
2578 | /** |
2579 | * Clear an object's memory to zero. |
2580 | * |
2581 | * This is wrapper over SDL_memset that handles calculating the object size, |
2582 | * so there's no chance of copy/paste errors, and the code is cleaner. |
2583 | * |
2584 | * This requires an object, not a pointer to an object, nor an array. |
2585 | * |
2586 | * \param x the object to clear. |
2587 | * |
2588 | * \threadsafety It is safe to call this macro from any thread. |
2589 | * |
2590 | * \since This macro is available since SDL 3.2.0. |
2591 | * |
2592 | * \sa SDL_zerop |
2593 | * \sa SDL_zeroa |
2594 | */ |
2595 | #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) |
2596 | |
2597 | /** |
2598 | * Clear an object's memory to zero, using a pointer. |
2599 | * |
2600 | * This is wrapper over SDL_memset that handles calculating the object size, |
2601 | * so there's no chance of copy/paste errors, and the code is cleaner. |
2602 | * |
2603 | * This requires a pointer to an object, not an object itself, nor an array. |
2604 | * |
2605 | * \param x a pointer to the object to clear. |
2606 | * |
2607 | * \threadsafety It is safe to call this macro from any thread. |
2608 | * |
2609 | * \since This macro is available since SDL 3.2.0. |
2610 | * |
2611 | * \sa SDL_zero |
2612 | * \sa SDL_zeroa |
2613 | */ |
2614 | #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) |
2615 | |
2616 | /** |
2617 | * Clear an array's memory to zero. |
2618 | * |
2619 | * This is wrapper over SDL_memset that handles calculating the array size, so |
2620 | * there's no chance of copy/paste errors, and the code is cleaner. |
2621 | * |
2622 | * This requires an array, not an object, nor a pointer to an object. |
2623 | * |
2624 | * \param x an array to clear. |
2625 | * |
2626 | * \threadsafety It is safe to call this macro from any thread. |
2627 | * |
2628 | * \since This macro is available since SDL 3.2.0. |
2629 | * |
2630 | * \sa SDL_zero |
2631 | * \sa SDL_zeroa |
2632 | */ |
2633 | #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x))) |
2634 | |
2635 | |
2636 | /** |
2637 | * Compare two buffers of memory. |
2638 | * |
2639 | * \param s1 the first buffer to compare. NULL is not permitted! |
2640 | * \param s2 the second buffer to compare. NULL is not permitted! |
2641 | * \param len the number of bytes to compare between the buffers. |
2642 | * \returns less than zero if s1 is "less than" s2, greater than zero if s1 is |
2643 | * "greater than" s2, and zero if the buffers match exactly for `len` |
2644 | * bytes. |
2645 | * |
2646 | * \threadsafety It is safe to call this function from any thread. |
2647 | * |
2648 | * \since This function is available since SDL 3.2.0. |
2649 | */ |
2650 | extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); |
2651 | |
2652 | /** |
2653 | * This works exactly like wcslen() but doesn't require access to a C runtime. |
2654 | * |
2655 | * Counts the number of wchar_t values in `wstr`, excluding the null |
2656 | * terminator. |
2657 | * |
2658 | * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string, |
2659 | * this counts wchar_t values in a string, even if the string's encoding is of |
2660 | * variable width, like UTF-16. |
2661 | * |
2662 | * Also be aware that wchar_t is different sizes on different platforms (4 |
2663 | * bytes on Linux, 2 on Windows, etc). |
2664 | * |
2665 | * \param wstr The null-terminated wide string to read. Must not be NULL. |
2666 | * \returns the length (in wchar_t values, excluding the null terminator) of |
2667 | * `wstr`. |
2668 | * |
2669 | * \threadsafety It is safe to call this function from any thread. |
2670 | * |
2671 | * \since This function is available since SDL 3.2.0. |
2672 | * |
2673 | * \sa SDL_wcsnlen |
2674 | * \sa SDL_utf8strlen |
2675 | * \sa SDL_utf8strnlen |
2676 | */ |
2677 | extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr); |
2678 | |
2679 | /** |
2680 | * This works exactly like wcsnlen() but doesn't require access to a C |
2681 | * runtime. |
2682 | * |
2683 | * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the |
2684 | * null terminator. |
2685 | * |
2686 | * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string, |
2687 | * this counts wchar_t values in a string, even if the string's encoding is of |
2688 | * variable width, like UTF-16. |
2689 | * |
2690 | * Also be aware that wchar_t is different sizes on different platforms (4 |
2691 | * bytes on Linux, 2 on Windows, etc). |
2692 | * |
2693 | * Also, `maxlen` is a count of wide characters, not bytes! |
2694 | * |
2695 | * \param wstr The null-terminated wide string to read. Must not be NULL. |
2696 | * \param maxlen The maximum amount of wide characters to count. |
2697 | * \returns the length (in wide characters, excluding the null terminator) of |
2698 | * `wstr` but never more than `maxlen`. |
2699 | * |
2700 | * \threadsafety It is safe to call this function from any thread. |
2701 | * |
2702 | * \since This function is available since SDL 3.2.0. |
2703 | * |
2704 | * \sa SDL_wcslen |
2705 | * \sa SDL_utf8strlen |
2706 | * \sa SDL_utf8strnlen |
2707 | */ |
2708 | extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen); |
2709 | |
2710 | /** |
2711 | * Copy a wide string. |
2712 | * |
2713 | * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then |
2714 | * appends a null terminator. |
2715 | * |
2716 | * `src` and `dst` must not overlap. |
2717 | * |
2718 | * If `maxlen` is 0, no wide characters are copied and no null terminator is |
2719 | * written. |
2720 | * |
2721 | * \param dst The destination buffer. Must not be NULL, and must not overlap |
2722 | * with `src`. |
2723 | * \param src The null-terminated wide string to copy. Must not be NULL, and |
2724 | * must not overlap with `dst`. |
2725 | * \param maxlen The length (in wide characters) of the destination buffer. |
2726 | * \returns the length (in wide characters, excluding the null terminator) of |
2727 | * `src`. |
2728 | * |
2729 | * \threadsafety It is safe to call this function from any thread. |
2730 | * |
2731 | * \since This function is available since SDL 3.2.0. |
2732 | * |
2733 | * \sa SDL_wcslcat |
2734 | */ |
2735 | extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen); |
2736 | |
2737 | /** |
2738 | * Concatenate wide strings. |
2739 | * |
2740 | * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters |
2741 | * from `src` to the end of the wide string in `dst`, then appends a null |
2742 | * terminator. |
2743 | * |
2744 | * `src` and `dst` must not overlap. |
2745 | * |
2746 | * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is |
2747 | * unmodified. |
2748 | * |
2749 | * \param dst The destination buffer already containing the first |
2750 | * null-terminated wide string. Must not be NULL and must not |
2751 | * overlap with `src`. |
2752 | * \param src The second null-terminated wide string. Must not be NULL, and |
2753 | * must not overlap with `dst`. |
2754 | * \param maxlen The length (in wide characters) of the destination buffer. |
2755 | * \returns the length (in wide characters, excluding the null terminator) of |
2756 | * the string in `dst` plus the length of `src`. |
2757 | * |
2758 | * \threadsafety It is safe to call this function from any thread. |
2759 | * |
2760 | * \since This function is available since SDL 3.2.0. |
2761 | * |
2762 | * \sa SDL_wcslcpy |
2763 | */ |
2764 | extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen); |
2765 | |
2766 | /** |
2767 | * Allocate a copy of a wide string. |
2768 | * |
2769 | * This allocates enough space for a null-terminated copy of `wstr`, using |
2770 | * SDL_malloc, and then makes a copy of the string into this space. |
2771 | * |
2772 | * The returned string is owned by the caller, and should be passed to |
2773 | * SDL_free when no longer needed. |
2774 | * |
2775 | * \param wstr the string to copy. |
2776 | * \returns a pointer to the newly-allocated wide string. |
2777 | * |
2778 | * \threadsafety It is safe to call this function from any thread. |
2779 | * |
2780 | * \since This function is available since SDL 3.2.0. |
2781 | */ |
2782 | extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr); |
2783 | |
2784 | /** |
2785 | * Search a wide string for the first instance of a specific substring. |
2786 | * |
2787 | * The search ends once it finds the requested substring, or a null terminator |
2788 | * byte to end the string. |
2789 | * |
2790 | * Note that this looks for strings of _wide characters_, not _codepoints_, so |
2791 | * it's legal to search for malformed and incomplete UTF-16 sequences. |
2792 | * |
2793 | * \param haystack the wide string to search. Must not be NULL. |
2794 | * \param needle the wide string to search for. Must not be NULL. |
2795 | * \returns a pointer to the first instance of `needle` in the string, or NULL |
2796 | * if not found. |
2797 | * |
2798 | * \threadsafety It is safe to call this function from any thread. |
2799 | * |
2800 | * \since This function is available since SDL 3.2.0. |
2801 | */ |
2802 | extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle); |
2803 | |
2804 | /** |
2805 | * Search a wide string, up to n wide chars, for the first instance of a |
2806 | * specific substring. |
2807 | * |
2808 | * The search ends once it finds the requested substring, or a null terminator |
2809 | * value to end the string, or `maxlen` wide character have been examined. It |
2810 | * is possible to use this function on a wide string without a null |
2811 | * terminator. |
2812 | * |
2813 | * Note that this looks for strings of _wide characters_, not _codepoints_, so |
2814 | * it's legal to search for malformed and incomplete UTF-16 sequences. |
2815 | * |
2816 | * \param haystack the wide string to search. Must not be NULL. |
2817 | * \param needle the wide string to search for. Must not be NULL. |
2818 | * \param maxlen the maximum number of wide characters to search in |
2819 | * `haystack`. |
2820 | * \returns a pointer to the first instance of `needle` in the string, or NULL |
2821 | * if not found. |
2822 | * |
2823 | * \threadsafety It is safe to call this function from any thread. |
2824 | * |
2825 | * \since This function is available since SDL 3.2.0. |
2826 | */ |
2827 | extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen); |
2828 | |
2829 | /** |
2830 | * Compare two null-terminated wide strings. |
2831 | * |
2832 | * This only compares wchar_t values until it hits a null-terminating |
2833 | * character; it does not care if the string is well-formed UTF-16 (or UTF-32, |
2834 | * depending on your platform's wchar_t size), or uses valid Unicode values. |
2835 | * |
2836 | * \param str1 the first string to compare. NULL is not permitted! |
2837 | * \param str2 the second string to compare. NULL is not permitted! |
2838 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
2839 | * str1 is "greater than" str2, and zero if the strings match |
2840 | * exactly. |
2841 | * |
2842 | * \threadsafety It is safe to call this function from any thread. |
2843 | * |
2844 | * \since This function is available since SDL 3.2.0. |
2845 | */ |
2846 | extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2); |
2847 | |
2848 | /** |
2849 | * Compare two wide strings up to a number of wchar_t values. |
2850 | * |
2851 | * This only compares wchar_t values; it does not care if the string is |
2852 | * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), |
2853 | * or uses valid Unicode values. |
2854 | * |
2855 | * Note that while this function is intended to be used with UTF-16 (or |
2856 | * UTF-32, depending on your platform's definition of wchar_t), it is |
2857 | * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies |
2858 | * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16 |
2859 | * sequence, it will only compare a portion of the final character. |
2860 | * |
2861 | * `maxlen` specifies a maximum number of wchar_t to compare; if the strings |
2862 | * match to this number of wide chars (or both have matched to a |
2863 | * null-terminator character before this count), they will be considered |
2864 | * equal. |
2865 | * |
2866 | * \param str1 the first string to compare. NULL is not permitted! |
2867 | * \param str2 the second string to compare. NULL is not permitted! |
2868 | * \param maxlen the maximum number of wchar_t to compare. |
2869 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
2870 | * str1 is "greater than" str2, and zero if the strings match |
2871 | * exactly. |
2872 | * |
2873 | * \threadsafety It is safe to call this function from any thread. |
2874 | * |
2875 | * \since This function is available since SDL 3.2.0. |
2876 | */ |
2877 | extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen); |
2878 | |
2879 | /** |
2880 | * Compare two null-terminated wide strings, case-insensitively. |
2881 | * |
2882 | * This will work with Unicode strings, using a technique called |
2883 | * "case-folding" to handle the vast majority of case-sensitive human |
2884 | * languages regardless of system locale. It can deal with expanding values: a |
2885 | * German Eszett character can compare against two ASCII 's' chars and be |
2886 | * considered a match, for example. A notable exception: it does not handle |
2887 | * the Turkish 'i' character; human language is complicated! |
2888 | * |
2889 | * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be |
2890 | * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this |
2891 | * handles Unicode, it expects the string to be well-formed and not a |
2892 | * null-terminated string of arbitrary bytes. Characters that are not valid |
2893 | * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT |
2894 | * CHARACTER), which is to say two strings of random bits may turn out to |
2895 | * match if they convert to the same amount of replacement characters. |
2896 | * |
2897 | * \param str1 the first string to compare. NULL is not permitted! |
2898 | * \param str2 the second string to compare. NULL is not permitted! |
2899 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
2900 | * str1 is "greater than" str2, and zero if the strings match |
2901 | * exactly. |
2902 | * |
2903 | * \threadsafety It is safe to call this function from any thread. |
2904 | * |
2905 | * \since This function is available since SDL 3.2.0. |
2906 | */ |
2907 | extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2); |
2908 | |
2909 | /** |
2910 | * Compare two wide strings, case-insensitively, up to a number of wchar_t. |
2911 | * |
2912 | * This will work with Unicode strings, using a technique called |
2913 | * "case-folding" to handle the vast majority of case-sensitive human |
2914 | * languages regardless of system locale. It can deal with expanding values: a |
2915 | * German Eszett character can compare against two ASCII 's' chars and be |
2916 | * considered a match, for example. A notable exception: it does not handle |
2917 | * the Turkish 'i' character; human language is complicated! |
2918 | * |
2919 | * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be |
2920 | * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this |
2921 | * handles Unicode, it expects the string to be well-formed and not a |
2922 | * null-terminated string of arbitrary bytes. Characters that are not valid |
2923 | * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT |
2924 | * CHARACTER), which is to say two strings of random bits may turn out to |
2925 | * match if they convert to the same amount of replacement characters. |
2926 | * |
2927 | * Note that while this function might deal with variable-sized characters, |
2928 | * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a |
2929 | * multi-byte UTF-16 sequence, it may convert a portion of the final character |
2930 | * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not |
2931 | * to overflow a buffer. |
2932 | * |
2933 | * `maxlen` specifies a maximum number of wchar_t values to compare; if the |
2934 | * strings match to this number of wchar_t (or both have matched to a |
2935 | * null-terminator character before this number of bytes), they will be |
2936 | * considered equal. |
2937 | * |
2938 | * \param str1 the first string to compare. NULL is not permitted! |
2939 | * \param str2 the second string to compare. NULL is not permitted! |
2940 | * \param maxlen the maximum number of wchar_t values to compare. |
2941 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
2942 | * str1 is "greater than" str2, and zero if the strings match |
2943 | * exactly. |
2944 | * |
2945 | * \threadsafety It is safe to call this function from any thread. |
2946 | * |
2947 | * \since This function is available since SDL 3.2.0. |
2948 | */ |
2949 | extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen); |
2950 | |
2951 | /** |
2952 | * Parse a `long` from a wide string. |
2953 | * |
2954 | * If `str` starts with whitespace, then those whitespace characters are |
2955 | * skipped before attempting to parse the number. |
2956 | * |
2957 | * If the parsed number does not fit inside a `long`, the result is clamped to |
2958 | * the minimum and maximum representable `long` values. |
2959 | * |
2960 | * \param str The null-terminated wide string to read. Must not be NULL. |
2961 | * \param endp If not NULL, the address of the first invalid wide character |
2962 | * (i.e. the next character after the parsed number) will be |
2963 | * written to this pointer. |
2964 | * \param base The base of the integer to read. Supported values are 0 and 2 |
2965 | * to 36 inclusive. If 0, the base will be inferred from the |
2966 | * number's prefix (0x for hexadecimal, 0 for octal, decimal |
2967 | * otherwise). |
2968 | * \returns the parsed `long`, or 0 if no number could be parsed. |
2969 | * |
2970 | * \threadsafety It is safe to call this function from any thread. |
2971 | * |
2972 | * \since This function is available since SDL 3.2.0. |
2973 | * |
2974 | * \sa SDL_strtol |
2975 | */ |
2976 | extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base); |
2977 | |
2978 | /** |
2979 | * This works exactly like strlen() but doesn't require access to a C runtime. |
2980 | * |
2981 | * Counts the bytes in `str`, excluding the null terminator. |
2982 | * |
2983 | * If you need the length of a UTF-8 string, consider using SDL_utf8strlen(). |
2984 | * |
2985 | * \param str The null-terminated string to read. Must not be NULL. |
2986 | * \returns the length (in bytes, excluding the null terminator) of `src`. |
2987 | * |
2988 | * \threadsafety It is safe to call this function from any thread. |
2989 | * |
2990 | * \since This function is available since SDL 3.2.0. |
2991 | * |
2992 | * \sa SDL_strnlen |
2993 | * \sa SDL_utf8strlen |
2994 | * \sa SDL_utf8strnlen |
2995 | */ |
2996 | extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str); |
2997 | |
2998 | /** |
2999 | * This works exactly like strnlen() but doesn't require access to a C |
3000 | * runtime. |
3001 | * |
3002 | * Counts up to a maximum of `maxlen` bytes in `str`, excluding the null |
3003 | * terminator. |
3004 | * |
3005 | * If you need the length of a UTF-8 string, consider using SDL_utf8strnlen(). |
3006 | * |
3007 | * \param str The null-terminated string to read. Must not be NULL. |
3008 | * \param maxlen The maximum amount of bytes to count. |
3009 | * \returns the length (in bytes, excluding the null terminator) of `src` but |
3010 | * never more than `maxlen`. |
3011 | * |
3012 | * \threadsafety It is safe to call this function from any thread. |
3013 | * |
3014 | * \since This function is available since SDL 3.2.0. |
3015 | * |
3016 | * \sa SDL_strlen |
3017 | * \sa SDL_utf8strlen |
3018 | * \sa SDL_utf8strnlen |
3019 | */ |
3020 | extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen); |
3021 | |
3022 | /** |
3023 | * Copy a string. |
3024 | * |
3025 | * This function copies up to `maxlen` - 1 characters from `src` to `dst`, |
3026 | * then appends a null terminator. |
3027 | * |
3028 | * If `maxlen` is 0, no characters are copied and no null terminator is |
3029 | * written. |
3030 | * |
3031 | * If you want to copy an UTF-8 string but need to ensure that multi-byte |
3032 | * sequences are not truncated, consider using SDL_utf8strlcpy(). |
3033 | * |
3034 | * \param dst The destination buffer. Must not be NULL, and must not overlap |
3035 | * with `src`. |
3036 | * \param src The null-terminated string to copy. Must not be NULL, and must |
3037 | * not overlap with `dst`. |
3038 | * \param maxlen The length (in characters) of the destination buffer. |
3039 | * \returns the length (in characters, excluding the null terminator) of |
3040 | * `src`. |
3041 | * |
3042 | * \threadsafety It is safe to call this function from any thread. |
3043 | * |
3044 | * \since This function is available since SDL 3.2.0. |
3045 | * |
3046 | * \sa SDL_strlcat |
3047 | * \sa SDL_utf8strlcpy |
3048 | */ |
3049 | extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen); |
3050 | |
3051 | /** |
3052 | * Copy an UTF-8 string. |
3053 | * |
3054 | * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while |
3055 | * also ensuring that the string written to `dst` does not end in a truncated |
3056 | * multi-byte sequence. Finally, it appends a null terminator. |
3057 | * |
3058 | * `src` and `dst` must not overlap. |
3059 | * |
3060 | * Note that unlike SDL_strlcpy(), this function returns the number of bytes |
3061 | * written, not the length of `src`. |
3062 | * |
3063 | * \param dst The destination buffer. Must not be NULL, and must not overlap |
3064 | * with `src`. |
3065 | * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and |
3066 | * must not overlap with `dst`. |
3067 | * \param dst_bytes The length (in bytes) of the destination buffer. Must not |
3068 | * be 0. |
3069 | * \returns the number of bytes written, excluding the null terminator. |
3070 | * |
3071 | * \threadsafety It is safe to call this function from any thread. |
3072 | * |
3073 | * \since This function is available since SDL 3.2.0. |
3074 | * |
3075 | * \sa SDL_strlcpy |
3076 | */ |
3077 | extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes); |
3078 | |
3079 | /** |
3080 | * Concatenate strings. |
3081 | * |
3082 | * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from |
3083 | * `src` to the end of the string in `dst`, then appends a null terminator. |
3084 | * |
3085 | * `src` and `dst` must not overlap. |
3086 | * |
3087 | * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is |
3088 | * unmodified. |
3089 | * |
3090 | * \param dst The destination buffer already containing the first |
3091 | * null-terminated string. Must not be NULL and must not overlap |
3092 | * with `src`. |
3093 | * \param src The second null-terminated string. Must not be NULL, and must |
3094 | * not overlap with `dst`. |
3095 | * \param maxlen The length (in characters) of the destination buffer. |
3096 | * \returns the length (in characters, excluding the null terminator) of the |
3097 | * string in `dst` plus the length of `src`. |
3098 | * |
3099 | * \threadsafety It is safe to call this function from any thread. |
3100 | * |
3101 | * \since This function is available since SDL 3.2.0. |
3102 | * |
3103 | * \sa SDL_strlcpy |
3104 | */ |
3105 | extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen); |
3106 | |
3107 | /** |
3108 | * Allocate a copy of a string. |
3109 | * |
3110 | * This allocates enough space for a null-terminated copy of `str`, using |
3111 | * SDL_malloc, and then makes a copy of the string into this space. |
3112 | * |
3113 | * The returned string is owned by the caller, and should be passed to |
3114 | * SDL_free when no longer needed. |
3115 | * |
3116 | * \param str the string to copy. |
3117 | * \returns a pointer to the newly-allocated string. |
3118 | * |
3119 | * \threadsafety It is safe to call this function from any thread. |
3120 | * |
3121 | * \since This function is available since SDL 3.2.0. |
3122 | */ |
3123 | extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str); |
3124 | |
3125 | /** |
3126 | * Allocate a copy of a string, up to n characters. |
3127 | * |
3128 | * This allocates enough space for a null-terminated copy of `str`, up to |
3129 | * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into |
3130 | * this space. |
3131 | * |
3132 | * If the string is longer than `maxlen` bytes, the returned string will be |
3133 | * `maxlen` bytes long, plus a null-terminator character that isn't included |
3134 | * in the count. |
3135 | * |
3136 | * The returned string is owned by the caller, and should be passed to |
3137 | * SDL_free when no longer needed. |
3138 | * |
3139 | * \param str the string to copy. |
3140 | * \param maxlen the maximum length of the copied string, not counting the |
3141 | * null-terminator character. |
3142 | * \returns a pointer to the newly-allocated string. |
3143 | * |
3144 | * \threadsafety It is safe to call this function from any thread. |
3145 | * |
3146 | * \since This function is available since SDL 3.2.0. |
3147 | */ |
3148 | extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen); |
3149 | |
3150 | /** |
3151 | * Reverse a string's contents. |
3152 | * |
3153 | * This reverses a null-terminated string in-place. Only the content of the |
3154 | * string is reversed; the null-terminator character remains at the end of the |
3155 | * reversed string. |
3156 | * |
3157 | * **WARNING**: This function reverses the _bytes_ of the string, not the |
3158 | * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this |
3159 | * will ruin the string data. You should only use this function on strings |
3160 | * that are completely comprised of low ASCII characters. |
3161 | * |
3162 | * \param str the string to reverse. |
3163 | * \returns `str`. |
3164 | * |
3165 | * \threadsafety It is safe to call this function from any thread. |
3166 | * |
3167 | * \since This function is available since SDL 3.2.0. |
3168 | */ |
3169 | extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str); |
3170 | |
3171 | /** |
3172 | * Convert a string to uppercase. |
3173 | * |
3174 | * **WARNING**: Regardless of system locale, this will only convert ASCII |
3175 | * values 'A' through 'Z' to uppercase. |
3176 | * |
3177 | * This function operates on a null-terminated string of bytes--even if it is |
3178 | * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their |
3179 | * uppercase equivalents in-place, returning the original `str` pointer. |
3180 | * |
3181 | * \param str the string to convert in-place. Can not be NULL. |
3182 | * \returns the `str` pointer passed into this function. |
3183 | * |
3184 | * \threadsafety It is safe to call this function from any thread. |
3185 | * |
3186 | * \since This function is available since SDL 3.2.0. |
3187 | * |
3188 | * \sa SDL_strlwr |
3189 | */ |
3190 | extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str); |
3191 | |
3192 | /** |
3193 | * Convert a string to lowercase. |
3194 | * |
3195 | * **WARNING**: Regardless of system locale, this will only convert ASCII |
3196 | * values 'A' through 'Z' to lowercase. |
3197 | * |
3198 | * This function operates on a null-terminated string of bytes--even if it is |
3199 | * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their |
3200 | * lowercase equivalents in-place, returning the original `str` pointer. |
3201 | * |
3202 | * \param str the string to convert in-place. Can not be NULL. |
3203 | * \returns the `str` pointer passed into this function. |
3204 | * |
3205 | * \threadsafety It is safe to call this function from any thread. |
3206 | * |
3207 | * \since This function is available since SDL 3.2.0. |
3208 | * |
3209 | * \sa SDL_strupr |
3210 | */ |
3211 | extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str); |
3212 | |
3213 | /** |
3214 | * Search a string for the first instance of a specific byte. |
3215 | * |
3216 | * The search ends once it finds the requested byte value, or a null |
3217 | * terminator byte to end the string. |
3218 | * |
3219 | * Note that this looks for _bytes_, not _characters_, so you cannot match |
3220 | * against a Unicode codepoint > 255, regardless of character encoding. |
3221 | * |
3222 | * \param str the string to search. Must not be NULL. |
3223 | * \param c the byte value to search for. |
3224 | * \returns a pointer to the first instance of `c` in the string, or NULL if |
3225 | * not found. |
3226 | * |
3227 | * \threadsafety It is safe to call this function from any thread. |
3228 | * |
3229 | * \since This function is available since SDL 3.2.0. |
3230 | */ |
3231 | extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c); |
3232 | |
3233 | /** |
3234 | * Search a string for the last instance of a specific byte. |
3235 | * |
3236 | * The search must go until it finds a null terminator byte to end the string. |
3237 | * |
3238 | * Note that this looks for _bytes_, not _characters_, so you cannot match |
3239 | * against a Unicode codepoint > 255, regardless of character encoding. |
3240 | * |
3241 | * \param str the string to search. Must not be NULL. |
3242 | * \param c the byte value to search for. |
3243 | * \returns a pointer to the last instance of `c` in the string, or NULL if |
3244 | * not found. |
3245 | * |
3246 | * \threadsafety It is safe to call this function from any thread. |
3247 | * |
3248 | * \since This function is available since SDL 3.2.0. |
3249 | */ |
3250 | extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c); |
3251 | |
3252 | /** |
3253 | * Search a string for the first instance of a specific substring. |
3254 | * |
3255 | * The search ends once it finds the requested substring, or a null terminator |
3256 | * byte to end the string. |
3257 | * |
3258 | * Note that this looks for strings of _bytes_, not _characters_, so it's |
3259 | * legal to search for malformed and incomplete UTF-8 sequences. |
3260 | * |
3261 | * \param haystack the string to search. Must not be NULL. |
3262 | * \param needle the string to search for. Must not be NULL. |
3263 | * \returns a pointer to the first instance of `needle` in the string, or NULL |
3264 | * if not found. |
3265 | * |
3266 | * \threadsafety It is safe to call this function from any thread. |
3267 | * |
3268 | * \since This function is available since SDL 3.2.0. |
3269 | */ |
3270 | extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle); |
3271 | |
3272 | /** |
3273 | * Search a string, up to n bytes, for the first instance of a specific |
3274 | * substring. |
3275 | * |
3276 | * The search ends once it finds the requested substring, or a null terminator |
3277 | * byte to end the string, or `maxlen` bytes have been examined. It is |
3278 | * possible to use this function on a string without a null terminator. |
3279 | * |
3280 | * Note that this looks for strings of _bytes_, not _characters_, so it's |
3281 | * legal to search for malformed and incomplete UTF-8 sequences. |
3282 | * |
3283 | * \param haystack the string to search. Must not be NULL. |
3284 | * \param needle the string to search for. Must not be NULL. |
3285 | * \param maxlen the maximum number of bytes to search in `haystack`. |
3286 | * \returns a pointer to the first instance of `needle` in the string, or NULL |
3287 | * if not found. |
3288 | * |
3289 | * \threadsafety It is safe to call this function from any thread. |
3290 | * |
3291 | * \since This function is available since SDL 3.2.0. |
3292 | */ |
3293 | extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen); |
3294 | |
3295 | /** |
3296 | * Search a UTF-8 string for the first instance of a specific substring, |
3297 | * case-insensitively. |
3298 | * |
3299 | * This will work with Unicode strings, using a technique called |
3300 | * "case-folding" to handle the vast majority of case-sensitive human |
3301 | * languages regardless of system locale. It can deal with expanding values: a |
3302 | * German Eszett character can compare against two ASCII 's' chars and be |
3303 | * considered a match, for example. A notable exception: it does not handle |
3304 | * the Turkish 'i' character; human language is complicated! |
3305 | * |
3306 | * Since this handles Unicode, it expects the strings to be well-formed UTF-8 |
3307 | * and not a null-terminated string of arbitrary bytes. Bytes that are not |
3308 | * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT |
3309 | * CHARACTER), which is to say two strings of random bits may turn out to |
3310 | * match if they convert to the same amount of replacement characters. |
3311 | * |
3312 | * \param haystack the string to search. Must not be NULL. |
3313 | * \param needle the string to search for. Must not be NULL. |
3314 | * \returns a pointer to the first instance of `needle` in the string, or NULL |
3315 | * if not found. |
3316 | * |
3317 | * \threadsafety It is safe to call this function from any thread. |
3318 | * |
3319 | * \since This function is available since SDL 3.2.0. |
3320 | */ |
3321 | extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle); |
3322 | |
3323 | /** |
3324 | * This works exactly like strtok_r() but doesn't require access to a C |
3325 | * runtime. |
3326 | * |
3327 | * Break a string up into a series of tokens. |
3328 | * |
3329 | * To start tokenizing a new string, `str` should be the non-NULL address of |
3330 | * the string to start tokenizing. Future calls to get the next token from the |
3331 | * same string should specify a NULL. |
3332 | * |
3333 | * Note that this function will overwrite pieces of `str` with null chars to |
3334 | * split it into tokens. This function cannot be used with const/read-only |
3335 | * strings! |
3336 | * |
3337 | * `saveptr` just needs to point to a `char *` that can be overwritten; SDL |
3338 | * will use this to save tokenizing state between calls. It is initialized if |
3339 | * `str` is non-NULL, and used to resume tokenizing when `str` is NULL. |
3340 | * |
3341 | * \param str the string to tokenize, or NULL to continue tokenizing. |
3342 | * \param delim the delimiter string that separates tokens. |
3343 | * \param saveptr pointer to a char *, used for ongoing state. |
3344 | * \returns A pointer to the next token, or NULL if no tokens remain. |
3345 | * |
3346 | * \threadsafety It is safe to call this function from any thread. |
3347 | * |
3348 | * \since This function is available since SDL 3.2.0. |
3349 | */ |
3350 | extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr); |
3351 | |
3352 | /** |
3353 | * Count the number of codepoints in a UTF-8 string. |
3354 | * |
3355 | * Counts the _codepoints_, not _bytes_, in `str`, excluding the null |
3356 | * terminator. |
3357 | * |
3358 | * If you need to count the bytes in a string instead, consider using |
3359 | * SDL_strlen(). |
3360 | * |
3361 | * Since this handles Unicode, it expects the strings to be well-formed UTF-8 |
3362 | * and not a null-terminated string of arbitrary bytes. Bytes that are not |
3363 | * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT |
3364 | * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the |
3365 | * count by several replacement characters. |
3366 | * |
3367 | * \param str The null-terminated UTF-8 string to read. Must not be NULL. |
3368 | * \returns The length (in codepoints, excluding the null terminator) of |
3369 | * `src`. |
3370 | * |
3371 | * \threadsafety It is safe to call this function from any thread. |
3372 | * |
3373 | * \since This function is available since SDL 3.2.0. |
3374 | * |
3375 | * \sa SDL_utf8strnlen |
3376 | * \sa SDL_strlen |
3377 | */ |
3378 | extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str); |
3379 | |
3380 | /** |
3381 | * Count the number of codepoints in a UTF-8 string, up to n bytes. |
3382 | * |
3383 | * Counts the _codepoints_, not _bytes_, in `str`, excluding the null |
3384 | * terminator. |
3385 | * |
3386 | * If you need to count the bytes in a string instead, consider using |
3387 | * SDL_strnlen(). |
3388 | * |
3389 | * The counting stops at `bytes` bytes (not codepoints!). This seems |
3390 | * counterintuitive, but makes it easy to express the total size of the |
3391 | * string's buffer. |
3392 | * |
3393 | * Since this handles Unicode, it expects the strings to be well-formed UTF-8 |
3394 | * and not a null-terminated string of arbitrary bytes. Bytes that are not |
3395 | * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT |
3396 | * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the |
3397 | * count by several replacement characters. |
3398 | * |
3399 | * \param str The null-terminated UTF-8 string to read. Must not be NULL. |
3400 | * \param bytes The maximum amount of bytes to count. |
3401 | * \returns The length (in codepoints, excluding the null terminator) of `src` |
3402 | * but never more than `maxlen`. |
3403 | * |
3404 | * \threadsafety It is safe to call this function from any thread. |
3405 | * |
3406 | * \since This function is available since SDL 3.2.0. |
3407 | * |
3408 | * \sa SDL_utf8strlen |
3409 | * \sa SDL_strnlen |
3410 | */ |
3411 | extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes); |
3412 | |
3413 | /** |
3414 | * Convert an integer into a string. |
3415 | * |
3416 | * This requires a radix to specified for string format. Specifying 10 |
3417 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3418 | * to 36. |
3419 | * |
3420 | * Note that this function will overflow a buffer if `str` is not large enough |
3421 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3422 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3423 | * much more space than you expect to use (and don't forget possible negative |
3424 | * signs, null terminator bytes, etc). |
3425 | * |
3426 | * \param value the integer to convert. |
3427 | * \param str the buffer to write the string into. |
3428 | * \param radix the radix to use for string generation. |
3429 | * \returns `str`. |
3430 | * |
3431 | * \threadsafety It is safe to call this function from any thread. |
3432 | * |
3433 | * \since This function is available since SDL 3.2.0. |
3434 | * |
3435 | * \sa SDL_uitoa |
3436 | * \sa SDL_ltoa |
3437 | * \sa SDL_lltoa |
3438 | */ |
3439 | extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix); |
3440 | |
3441 | /** |
3442 | * Convert an unsigned integer into a string. |
3443 | * |
3444 | * This requires a radix to specified for string format. Specifying 10 |
3445 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3446 | * to 36. |
3447 | * |
3448 | * Note that this function will overflow a buffer if `str` is not large enough |
3449 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3450 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3451 | * much more space than you expect to use (and don't forget null terminator |
3452 | * bytes, etc). |
3453 | * |
3454 | * \param value the unsigned integer to convert. |
3455 | * \param str the buffer to write the string into. |
3456 | * \param radix the radix to use for string generation. |
3457 | * \returns `str`. |
3458 | * |
3459 | * \threadsafety It is safe to call this function from any thread. |
3460 | * |
3461 | * \since This function is available since SDL 3.2.0. |
3462 | * |
3463 | * \sa SDL_itoa |
3464 | * \sa SDL_ultoa |
3465 | * \sa SDL_ulltoa |
3466 | */ |
3467 | extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix); |
3468 | |
3469 | /** |
3470 | * Convert a long integer into a string. |
3471 | * |
3472 | * This requires a radix to specified for string format. Specifying 10 |
3473 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3474 | * to 36. |
3475 | * |
3476 | * Note that this function will overflow a buffer if `str` is not large enough |
3477 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3478 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3479 | * much more space than you expect to use (and don't forget possible negative |
3480 | * signs, null terminator bytes, etc). |
3481 | * |
3482 | * \param value the long integer to convert. |
3483 | * \param str the buffer to write the string into. |
3484 | * \param radix the radix to use for string generation. |
3485 | * \returns `str`. |
3486 | * |
3487 | * \threadsafety It is safe to call this function from any thread. |
3488 | * |
3489 | * \since This function is available since SDL 3.2.0. |
3490 | * |
3491 | * \sa SDL_ultoa |
3492 | * \sa SDL_itoa |
3493 | * \sa SDL_lltoa |
3494 | */ |
3495 | extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix); |
3496 | |
3497 | /** |
3498 | * Convert an unsigned long integer into a string. |
3499 | * |
3500 | * This requires a radix to specified for string format. Specifying 10 |
3501 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3502 | * to 36. |
3503 | * |
3504 | * Note that this function will overflow a buffer if `str` is not large enough |
3505 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3506 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3507 | * much more space than you expect to use (and don't forget null terminator |
3508 | * bytes, etc). |
3509 | * |
3510 | * \param value the unsigned long integer to convert. |
3511 | * \param str the buffer to write the string into. |
3512 | * \param radix the radix to use for string generation. |
3513 | * \returns `str`. |
3514 | * |
3515 | * \threadsafety It is safe to call this function from any thread. |
3516 | * |
3517 | * \since This function is available since SDL 3.2.0. |
3518 | * |
3519 | * \sa SDL_ltoa |
3520 | * \sa SDL_uitoa |
3521 | * \sa SDL_ulltoa |
3522 | */ |
3523 | extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix); |
3524 | |
3525 | #ifndef SDL_NOLONGLONG |
3526 | |
3527 | /** |
3528 | * Convert a long long integer into a string. |
3529 | * |
3530 | * This requires a radix to specified for string format. Specifying 10 |
3531 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3532 | * to 36. |
3533 | * |
3534 | * Note that this function will overflow a buffer if `str` is not large enough |
3535 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3536 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3537 | * much more space than you expect to use (and don't forget possible negative |
3538 | * signs, null terminator bytes, etc). |
3539 | * |
3540 | * \param value the long long integer to convert. |
3541 | * \param str the buffer to write the string into. |
3542 | * \param radix the radix to use for string generation. |
3543 | * \returns `str`. |
3544 | * |
3545 | * \threadsafety It is safe to call this function from any thread. |
3546 | * |
3547 | * \since This function is available since SDL 3.2.0. |
3548 | * |
3549 | * \sa SDL_ulltoa |
3550 | * \sa SDL_itoa |
3551 | * \sa SDL_ltoa |
3552 | */ |
3553 | extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix); |
3554 | |
3555 | /** |
3556 | * Convert an unsigned long long integer into a string. |
3557 | * |
3558 | * This requires a radix to specified for string format. Specifying 10 |
3559 | * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2 |
3560 | * to 36. |
3561 | * |
3562 | * Note that this function will overflow a buffer if `str` is not large enough |
3563 | * to hold the output! It may be safer to use SDL_snprintf to clamp output, or |
3564 | * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate |
3565 | * much more space than you expect to use (and don't forget null terminator |
3566 | * bytes, etc). |
3567 | * |
3568 | * \param value the unsigned long long integer to convert. |
3569 | * \param str the buffer to write the string into. |
3570 | * \param radix the radix to use for string generation. |
3571 | * \returns `str`. |
3572 | * |
3573 | * \threadsafety It is safe to call this function from any thread. |
3574 | * |
3575 | * \since This function is available since SDL 3.2.0. |
3576 | * |
3577 | * \sa SDL_lltoa |
3578 | * \sa SDL_uitoa |
3579 | * \sa SDL_ultoa |
3580 | */ |
3581 | extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix); |
3582 | #endif |
3583 | |
3584 | /** |
3585 | * Parse an `int` from a string. |
3586 | * |
3587 | * The result of calling `SDL_atoi(str)` is equivalent to |
3588 | * `(int)SDL_strtol(str, NULL, 10)`. |
3589 | * |
3590 | * \param str The null-terminated string to read. Must not be NULL. |
3591 | * \returns the parsed `int`. |
3592 | * |
3593 | * \threadsafety It is safe to call this function from any thread. |
3594 | * |
3595 | * \since This function is available since SDL 3.2.0. |
3596 | * |
3597 | * \sa SDL_atof |
3598 | * \sa SDL_strtol |
3599 | * \sa SDL_strtoul |
3600 | * \sa SDL_strtoll |
3601 | * \sa SDL_strtoull |
3602 | * \sa SDL_strtod |
3603 | * \sa SDL_itoa |
3604 | */ |
3605 | extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str); |
3606 | |
3607 | /** |
3608 | * Parse a `double` from a string. |
3609 | * |
3610 | * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str, |
3611 | * NULL)`. |
3612 | * |
3613 | * \param str The null-terminated string to read. Must not be NULL. |
3614 | * \returns the parsed `double`. |
3615 | * |
3616 | * \threadsafety It is safe to call this function from any thread. |
3617 | * |
3618 | * \since This function is available since SDL 3.2.0. |
3619 | * |
3620 | * \sa SDL_atoi |
3621 | * \sa SDL_strtol |
3622 | * \sa SDL_strtoul |
3623 | * \sa SDL_strtoll |
3624 | * \sa SDL_strtoull |
3625 | * \sa SDL_strtod |
3626 | */ |
3627 | extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str); |
3628 | |
3629 | /** |
3630 | * Parse a `long` from a string. |
3631 | * |
3632 | * If `str` starts with whitespace, then those whitespace characters are |
3633 | * skipped before attempting to parse the number. |
3634 | * |
3635 | * If the parsed number does not fit inside a `long`, the result is clamped to |
3636 | * the minimum and maximum representable `long` values. |
3637 | * |
3638 | * \param str The null-terminated string to read. Must not be NULL. |
3639 | * \param endp If not NULL, the address of the first invalid character (i.e. |
3640 | * the next character after the parsed number) will be written to |
3641 | * this pointer. |
3642 | * \param base The base of the integer to read. Supported values are 0 and 2 |
3643 | * to 36 inclusive. If 0, the base will be inferred from the |
3644 | * number's prefix (0x for hexadecimal, 0 for octal, decimal |
3645 | * otherwise). |
3646 | * \returns the parsed `long`, or 0 if no number could be parsed. |
3647 | * |
3648 | * \threadsafety It is safe to call this function from any thread. |
3649 | * |
3650 | * \since This function is available since SDL 3.2.0. |
3651 | * |
3652 | * \sa SDL_atoi |
3653 | * \sa SDL_atof |
3654 | * \sa SDL_strtoul |
3655 | * \sa SDL_strtoll |
3656 | * \sa SDL_strtoull |
3657 | * \sa SDL_strtod |
3658 | * \sa SDL_ltoa |
3659 | * \sa SDL_wcstol |
3660 | */ |
3661 | extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base); |
3662 | |
3663 | /** |
3664 | * Parse an `unsigned long` from a string. |
3665 | * |
3666 | * If `str` starts with whitespace, then those whitespace characters are |
3667 | * skipped before attempting to parse the number. |
3668 | * |
3669 | * If the parsed number does not fit inside an `unsigned long`, the result is |
3670 | * clamped to the maximum representable `unsigned long` value. |
3671 | * |
3672 | * \param str The null-terminated string to read. Must not be NULL. |
3673 | * \param endp If not NULL, the address of the first invalid character (i.e. |
3674 | * the next character after the parsed number) will be written to |
3675 | * this pointer. |
3676 | * \param base The base of the integer to read. Supported values are 0 and 2 |
3677 | * to 36 inclusive. If 0, the base will be inferred from the |
3678 | * number's prefix (0x for hexadecimal, 0 for octal, decimal |
3679 | * otherwise). |
3680 | * \returns the parsed `unsigned long`, or 0 if no number could be parsed. |
3681 | * |
3682 | * \threadsafety It is safe to call this function from any thread. |
3683 | * |
3684 | * \since This function is available since SDL 3.2.0. |
3685 | * |
3686 | * \sa SDL_atoi |
3687 | * \sa SDL_atof |
3688 | * \sa SDL_strtol |
3689 | * \sa SDL_strtoll |
3690 | * \sa SDL_strtoull |
3691 | * \sa SDL_strtod |
3692 | * \sa SDL_ultoa |
3693 | */ |
3694 | extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base); |
3695 | |
3696 | #ifndef SDL_NOLONGLONG |
3697 | |
3698 | /** |
3699 | * Parse a `long long` from a string. |
3700 | * |
3701 | * If `str` starts with whitespace, then those whitespace characters are |
3702 | * skipped before attempting to parse the number. |
3703 | * |
3704 | * If the parsed number does not fit inside a `long long`, the result is |
3705 | * clamped to the minimum and maximum representable `long long` values. |
3706 | * |
3707 | * \param str The null-terminated string to read. Must not be NULL. |
3708 | * \param endp If not NULL, the address of the first invalid character (i.e. |
3709 | * the next character after the parsed number) will be written to |
3710 | * this pointer. |
3711 | * \param base The base of the integer to read. Supported values are 0 and 2 |
3712 | * to 36 inclusive. If 0, the base will be inferred from the |
3713 | * number's prefix (0x for hexadecimal, 0 for octal, decimal |
3714 | * otherwise). |
3715 | * \returns the parsed `long long`, or 0 if no number could be parsed. |
3716 | * |
3717 | * \threadsafety It is safe to call this function from any thread. |
3718 | * |
3719 | * \since This function is available since SDL 3.2.0. |
3720 | * |
3721 | * \sa SDL_atoi |
3722 | * \sa SDL_atof |
3723 | * \sa SDL_strtol |
3724 | * \sa SDL_strtoul |
3725 | * \sa SDL_strtoull |
3726 | * \sa SDL_strtod |
3727 | * \sa SDL_lltoa |
3728 | */ |
3729 | extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base); |
3730 | |
3731 | /** |
3732 | * Parse an `unsigned long long` from a string. |
3733 | * |
3734 | * If `str` starts with whitespace, then those whitespace characters are |
3735 | * skipped before attempting to parse the number. |
3736 | * |
3737 | * If the parsed number does not fit inside an `unsigned long long`, the |
3738 | * result is clamped to the maximum representable `unsigned long long` value. |
3739 | * |
3740 | * \param str The null-terminated string to read. Must not be NULL. |
3741 | * \param endp If not NULL, the address of the first invalid character (i.e. |
3742 | * the next character after the parsed number) will be written to |
3743 | * this pointer. |
3744 | * \param base The base of the integer to read. Supported values are 0 and 2 |
3745 | * to 36 inclusive. If 0, the base will be inferred from the |
3746 | * number's prefix (0x for hexadecimal, 0 for octal, decimal |
3747 | * otherwise). |
3748 | * \returns the parsed `unsigned long long`, or 0 if no number could be |
3749 | * parsed. |
3750 | * |
3751 | * \threadsafety It is safe to call this function from any thread. |
3752 | * |
3753 | * \since This function is available since SDL 3.2.0. |
3754 | * |
3755 | * \sa SDL_atoi |
3756 | * \sa SDL_atof |
3757 | * \sa SDL_strtol |
3758 | * \sa SDL_strtoll |
3759 | * \sa SDL_strtoul |
3760 | * \sa SDL_strtod |
3761 | * \sa SDL_ulltoa |
3762 | */ |
3763 | extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base); |
3764 | #endif |
3765 | |
3766 | /** |
3767 | * Parse a `double` from a string. |
3768 | * |
3769 | * This function makes fewer guarantees than the C runtime `strtod`: |
3770 | * |
3771 | * - Only decimal notation is guaranteed to be supported. The handling of |
3772 | * scientific and hexadecimal notation is unspecified. |
3773 | * - Whether or not INF and NAN can be parsed is unspecified. |
3774 | * - The precision of the result is unspecified. |
3775 | * |
3776 | * \param str the null-terminated string to read. Must not be NULL. |
3777 | * \param endp if not NULL, the address of the first invalid character (i.e. |
3778 | * the next character after the parsed number) will be written to |
3779 | * this pointer. |
3780 | * \returns the parsed `double`, or 0 if no number could be parsed. |
3781 | * |
3782 | * \threadsafety It is safe to call this function from any thread. |
3783 | * |
3784 | * \since This function is available since SDL 3.2.0. |
3785 | * |
3786 | * \sa SDL_atoi |
3787 | * \sa SDL_atof |
3788 | * \sa SDL_strtol |
3789 | * \sa SDL_strtoll |
3790 | * \sa SDL_strtoul |
3791 | * \sa SDL_strtoull |
3792 | */ |
3793 | extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp); |
3794 | |
3795 | /** |
3796 | * Compare two null-terminated UTF-8 strings. |
3797 | * |
3798 | * Due to the nature of UTF-8 encoding, this will work with Unicode strings, |
3799 | * since effectively this function just compares bytes until it hits a |
3800 | * null-terminating character. Also due to the nature of UTF-8, this can be |
3801 | * used with SDL_qsort() to put strings in (roughly) alphabetical order. |
3802 | * |
3803 | * \param str1 the first string to compare. NULL is not permitted! |
3804 | * \param str2 the second string to compare. NULL is not permitted! |
3805 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
3806 | * str1 is "greater than" str2, and zero if the strings match |
3807 | * exactly. |
3808 | * |
3809 | * \threadsafety It is safe to call this function from any thread. |
3810 | * |
3811 | * \since This function is available since SDL 3.2.0. |
3812 | */ |
3813 | extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); |
3814 | |
3815 | /** |
3816 | * Compare two UTF-8 strings up to a number of bytes. |
3817 | * |
3818 | * Due to the nature of UTF-8 encoding, this will work with Unicode strings, |
3819 | * since effectively this function just compares bytes until it hits a |
3820 | * null-terminating character. Also due to the nature of UTF-8, this can be |
3821 | * used with SDL_qsort() to put strings in (roughly) alphabetical order. |
3822 | * |
3823 | * Note that while this function is intended to be used with UTF-8, it is |
3824 | * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the |
3825 | * limit lands in the middle of a multi-byte UTF-8 sequence, it will only |
3826 | * compare a portion of the final character. |
3827 | * |
3828 | * `maxlen` specifies a maximum number of bytes to compare; if the strings |
3829 | * match to this number of bytes (or both have matched to a null-terminator |
3830 | * character before this number of bytes), they will be considered equal. |
3831 | * |
3832 | * \param str1 the first string to compare. NULL is not permitted! |
3833 | * \param str2 the second string to compare. NULL is not permitted! |
3834 | * \param maxlen the maximum number of _bytes_ to compare. |
3835 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
3836 | * str1 is "greater than" str2, and zero if the strings match |
3837 | * exactly. |
3838 | * |
3839 | * \threadsafety It is safe to call this function from any thread. |
3840 | * |
3841 | * \since This function is available since SDL 3.2.0. |
3842 | */ |
3843 | extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); |
3844 | |
3845 | /** |
3846 | * Compare two null-terminated UTF-8 strings, case-insensitively. |
3847 | * |
3848 | * This will work with Unicode strings, using a technique called |
3849 | * "case-folding" to handle the vast majority of case-sensitive human |
3850 | * languages regardless of system locale. It can deal with expanding values: a |
3851 | * German Eszett character can compare against two ASCII 's' chars and be |
3852 | * considered a match, for example. A notable exception: it does not handle |
3853 | * the Turkish 'i' character; human language is complicated! |
3854 | * |
3855 | * Since this handles Unicode, it expects the string to be well-formed UTF-8 |
3856 | * and not a null-terminated string of arbitrary bytes. Bytes that are not |
3857 | * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT |
3858 | * CHARACTER), which is to say two strings of random bits may turn out to |
3859 | * match if they convert to the same amount of replacement characters. |
3860 | * |
3861 | * \param str1 the first string to compare. NULL is not permitted! |
3862 | * \param str2 the second string to compare. NULL is not permitted! |
3863 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
3864 | * str1 is "greater than" str2, and zero if the strings match |
3865 | * exactly. |
3866 | * |
3867 | * \threadsafety It is safe to call this function from any thread. |
3868 | * |
3869 | * \since This function is available since SDL 3.2.0. |
3870 | */ |
3871 | extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); |
3872 | |
3873 | |
3874 | /** |
3875 | * Compare two UTF-8 strings, case-insensitively, up to a number of bytes. |
3876 | * |
3877 | * This will work with Unicode strings, using a technique called |
3878 | * "case-folding" to handle the vast majority of case-sensitive human |
3879 | * languages regardless of system locale. It can deal with expanding values: a |
3880 | * German Eszett character can compare against two ASCII 's' chars and be |
3881 | * considered a match, for example. A notable exception: it does not handle |
3882 | * the Turkish 'i' character; human language is complicated! |
3883 | * |
3884 | * Since this handles Unicode, it expects the string to be well-formed UTF-8 |
3885 | * and not a null-terminated string of arbitrary bytes. Bytes that are not |
3886 | * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT |
3887 | * CHARACTER), which is to say two strings of random bits may turn out to |
3888 | * match if they convert to the same amount of replacement characters. |
3889 | * |
3890 | * Note that while this function is intended to be used with UTF-8, `maxlen` |
3891 | * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte |
3892 | * UTF-8 sequence, it may convert a portion of the final character to one or |
3893 | * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow |
3894 | * a buffer. |
3895 | * |
3896 | * `maxlen` specifies a maximum number of bytes to compare; if the strings |
3897 | * match to this number of bytes (or both have matched to a null-terminator |
3898 | * character before this number of bytes), they will be considered equal. |
3899 | * |
3900 | * \param str1 the first string to compare. NULL is not permitted! |
3901 | * \param str2 the second string to compare. NULL is not permitted! |
3902 | * \param maxlen the maximum number of bytes to compare. |
3903 | * \returns less than zero if str1 is "less than" str2, greater than zero if |
3904 | * str1 is "greater than" str2, and zero if the strings match |
3905 | * exactly. |
3906 | * |
3907 | * \threadsafety It is safe to call this function from any thread. |
3908 | * |
3909 | * \since This function is available since SDL 3.2.0. |
3910 | */ |
3911 | extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen); |
3912 | |
3913 | /** |
3914 | * Searches a string for the first occurence of any character contained in a |
3915 | * breakset, and returns a pointer from the string to that character. |
3916 | * |
3917 | * \param str The null-terminated string to be searched. Must not be NULL, and |
3918 | * must not overlap with `breakset`. |
3919 | * \param breakset A null-terminated string containing the list of characters |
3920 | * to look for. Must not be NULL, and must not overlap with |
3921 | * `str`. |
3922 | * \returns A pointer to the location, in str, of the first occurence of a |
3923 | * character present in the breakset, or NULL if none is found. |
3924 | * |
3925 | * \threadsafety It is safe to call this function from any thread. |
3926 | * |
3927 | * \since This function is available since SDL 3.2.0. |
3928 | */ |
3929 | extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset); |
3930 | |
3931 | /** |
3932 | * The Unicode REPLACEMENT CHARACTER codepoint. |
3933 | * |
3934 | * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they |
3935 | * encounter a UTF-8 string with encoding errors. |
3936 | * |
3937 | * This tends to render as something like a question mark in most places. |
3938 | * |
3939 | * \since This macro is available since SDL 3.2.0. |
3940 | * |
3941 | * \sa SDL_StepBackUTF8 |
3942 | * \sa SDL_StepUTF8 |
3943 | */ |
3944 | #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD |
3945 | |
3946 | /** |
3947 | * Decode a UTF-8 string, one Unicode codepoint at a time. |
3948 | * |
3949 | * This will return the first Unicode codepoint in the UTF-8 encoded string in |
3950 | * `*pstr`, and then advance `*pstr` past any consumed bytes before returning. |
3951 | * |
3952 | * It will not access more than `*pslen` bytes from the string. `*pslen` will |
3953 | * be adjusted, as well, subtracting the number of bytes consumed. |
3954 | * |
3955 | * `pslen` is allowed to be NULL, in which case the string _must_ be |
3956 | * NULL-terminated, as the function will blindly read until it sees the NULL |
3957 | * char. |
3958 | * |
3959 | * if `*pslen` is zero, it assumes the end of string is reached and returns a |
3960 | * zero codepoint regardless of the contents of the string buffer. |
3961 | * |
3962 | * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is |
3963 | * zero, it will not advance `*pstr` or `*pslen` at all. |
3964 | * |
3965 | * Generally this function is called in a loop until it returns zero, |
3966 | * adjusting its parameters each iteration. |
3967 | * |
3968 | * If an invalid UTF-8 sequence is encountered, this function returns |
3969 | * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte |
3970 | * (which is to say, a multibyte sequence might produce several |
3971 | * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid |
3972 | * UTF-8 sequence). |
3973 | * |
3974 | * Several things can generate invalid UTF-8 sequences, including overlong |
3975 | * encodings, the use of UTF-16 surrogate values, and truncated data. Please |
3976 | * refer to |
3977 | * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt) |
3978 | * for details. |
3979 | * |
3980 | * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted. |
3981 | * \param pslen a pointer to the number of bytes in the string, to be read and |
3982 | * adjusted. NULL is allowed. |
3983 | * \returns the first Unicode codepoint in the string. |
3984 | * |
3985 | * \threadsafety It is safe to call this function from any thread. |
3986 | * |
3987 | * \since This function is available since SDL 3.2.0. |
3988 | */ |
3989 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen); |
3990 | |
3991 | /** |
3992 | * Decode a UTF-8 string in reverse, one Unicode codepoint at a time. |
3993 | * |
3994 | * This will go to the start of the previous Unicode codepoint in the string, |
3995 | * move `*pstr` to that location and return that codepoint. |
3996 | * |
3997 | * If `*pstr` is already at the start of the string), it will not advance |
3998 | * `*pstr` at all. |
3999 | * |
4000 | * Generally this function is called in a loop until it returns zero, |
4001 | * adjusting its parameter each iteration. |
4002 | * |
4003 | * If an invalid UTF-8 sequence is encountered, this function returns |
4004 | * SDL_INVALID_UNICODE_CODEPOINT. |
4005 | * |
4006 | * Several things can generate invalid UTF-8 sequences, including overlong |
4007 | * encodings, the use of UTF-16 surrogate values, and truncated data. Please |
4008 | * refer to |
4009 | * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt) |
4010 | * for details. |
4011 | * |
4012 | * \param start a pointer to the beginning of the UTF-8 string. |
4013 | * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted. |
4014 | * \returns the previous Unicode codepoint in the string. |
4015 | * |
4016 | * \threadsafety It is safe to call this function from any thread. |
4017 | * |
4018 | * \since This function is available since SDL 3.2.0. |
4019 | */ |
4020 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr); |
4021 | |
4022 | /** |
4023 | * Convert a single Unicode codepoint to UTF-8. |
4024 | * |
4025 | * The buffer pointed to by `dst` must be at least 4 bytes long, as this |
4026 | * function may generate between 1 and 4 bytes of output. |
4027 | * |
4028 | * This function returns the first byte _after_ the newly-written UTF-8 |
4029 | * sequence, which is useful for encoding multiple codepoints in a loop, or |
4030 | * knowing where to write a NULL-terminator character to end the string (in |
4031 | * either case, plan to have a buffer of _more_ than 4 bytes!). |
4032 | * |
4033 | * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16 |
4034 | * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the |
4035 | * codepoint instead, and not set an error. |
4036 | * |
4037 | * If `dst` is NULL, this returns NULL immediately without writing to the |
4038 | * pointer and without setting an error. |
4039 | * |
4040 | * \param codepoint a Unicode codepoint to convert to UTF-8. |
4041 | * \param dst the location to write the encoded UTF-8. Must point to at least |
4042 | * 4 bytes! |
4043 | * \returns the first byte past the newly-written UTF-8 sequence. |
4044 | * |
4045 | * \threadsafety It is safe to call this function from any thread. |
4046 | * |
4047 | * \since This function is available since SDL 3.2.0. |
4048 | */ |
4049 | extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst); |
4050 | |
4051 | /** |
4052 | * This works exactly like sscanf() but doesn't require access to a C runtime. |
4053 | * |
4054 | * Scan a string, matching a format string, converting each '%' item and |
4055 | * storing it to pointers provided through variable arguments. |
4056 | * |
4057 | * \param text the string to scan. Must not be NULL. |
4058 | * \param fmt a printf-style format string. Must not be NULL. |
4059 | * \param ... a list of pointers to values to be filled in with scanned items. |
4060 | * \returns the number of items that matched the format string. |
4061 | * |
4062 | * \threadsafety It is safe to call this function from any thread. |
4063 | * |
4064 | * \since This function is available since SDL 3.2.0. |
4065 | */ |
4066 | extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2); |
4067 | |
4068 | /** |
4069 | * This works exactly like vsscanf() but doesn't require access to a C |
4070 | * runtime. |
4071 | * |
4072 | * Functions identically to SDL_sscanf(), except it takes a `va_list` instead |
4073 | * of using `...` variable arguments. |
4074 | * |
4075 | * \param text the string to scan. Must not be NULL. |
4076 | * \param fmt a printf-style format string. Must not be NULL. |
4077 | * \param ap a `va_list` of pointers to values to be filled in with scanned |
4078 | * items. |
4079 | * \returns the number of items that matched the format string. |
4080 | * |
4081 | * \threadsafety It is safe to call this function from any thread. |
4082 | * |
4083 | * \since This function is available since SDL 3.2.0. |
4084 | */ |
4085 | extern SDL_DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2); |
4086 | |
4087 | /** |
4088 | * This works exactly like snprintf() but doesn't require access to a C |
4089 | * runtime. |
4090 | * |
4091 | * Format a string of up to `maxlen`-1 bytes, converting each '%' item with |
4092 | * values provided through variable arguments. |
4093 | * |
4094 | * While some C runtimes differ on how to deal with too-large strings, this |
4095 | * function null-terminates the output, by treating the null-terminator as |
4096 | * part of the `maxlen` count. Note that if `maxlen` is zero, however, no |
4097 | * bytes will be written at all. |
4098 | * |
4099 | * This function returns the number of _bytes_ (not _characters_) that should |
4100 | * be written, excluding the null-terminator character. If this returns a |
4101 | * number >= `maxlen`, it means the output string was truncated. A negative |
4102 | * return value means an error occurred. |
4103 | * |
4104 | * Referencing the output string's pointer with a format item is undefined |
4105 | * behavior. |
4106 | * |
4107 | * \param text the buffer to write the string into. Must not be NULL. |
4108 | * \param maxlen the maximum bytes to write, including the null-terminator. |
4109 | * \param fmt a printf-style format string. Must not be NULL. |
4110 | * \param ... a list of values to be used with the format string. |
4111 | * \returns the number of bytes that should be written, not counting the |
4112 | * null-terminator char, or a negative value on error. |
4113 | * |
4114 | * \threadsafety It is safe to call this function from any thread. |
4115 | * |
4116 | * \since This function is available since SDL 3.2.0. |
4117 | */ |
4118 | extern SDL_DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3); |
4119 | |
4120 | /** |
4121 | * This works exactly like swprintf() but doesn't require access to a C |
4122 | * runtime. |
4123 | * |
4124 | * Format a wide string of up to `maxlen`-1 wchar_t values, converting each |
4125 | * '%' item with values provided through variable arguments. |
4126 | * |
4127 | * While some C runtimes differ on how to deal with too-large strings, this |
4128 | * function null-terminates the output, by treating the null-terminator as |
4129 | * part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide |
4130 | * characters will be written at all. |
4131 | * |
4132 | * This function returns the number of _wide characters_ (not _codepoints_) |
4133 | * that should be written, excluding the null-terminator character. If this |
4134 | * returns a number >= `maxlen`, it means the output string was truncated. A |
4135 | * negative return value means an error occurred. |
4136 | * |
4137 | * Referencing the output string's pointer with a format item is undefined |
4138 | * behavior. |
4139 | * |
4140 | * \param text the buffer to write the wide string into. Must not be NULL. |
4141 | * \param maxlen the maximum wchar_t values to write, including the |
4142 | * null-terminator. |
4143 | * \param fmt a printf-style format string. Must not be NULL. |
4144 | * \param ... a list of values to be used with the format string. |
4145 | * \returns the number of wide characters that should be written, not counting |
4146 | * the null-terminator char, or a negative value on error. |
4147 | * |
4148 | * \threadsafety It is safe to call this function from any thread. |
4149 | * |
4150 | * \since This function is available since SDL 3.2.0. |
4151 | */ |
4152 | extern SDL_DECLSPEC int SDLCALL SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(3); |
4153 | |
4154 | /** |
4155 | * This works exactly like vsnprintf() but doesn't require access to a C |
4156 | * runtime. |
4157 | * |
4158 | * Functions identically to SDL_snprintf(), except it takes a `va_list` |
4159 | * instead of using `...` variable arguments. |
4160 | * |
4161 | * \param text the buffer to write the string into. Must not be NULL. |
4162 | * \param maxlen the maximum bytes to write, including the null-terminator. |
4163 | * \param fmt a printf-style format string. Must not be NULL. |
4164 | * \param ap a `va_list` values to be used with the format string. |
4165 | * \returns the number of bytes that should be written, not counting the |
4166 | * null-terminator char, or a negative value on error. |
4167 | * |
4168 | * \threadsafety It is safe to call this function from any thread. |
4169 | * |
4170 | * \since This function is available since SDL 3.2.0. |
4171 | */ |
4172 | extern SDL_DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3); |
4173 | |
4174 | /** |
4175 | * This works exactly like vswprintf() but doesn't require access to a C |
4176 | * runtime. |
4177 | * |
4178 | * Functions identically to SDL_swprintf(), except it takes a `va_list` |
4179 | * instead of using `...` variable arguments. |
4180 | * |
4181 | * \param text the buffer to write the string into. Must not be NULL. |
4182 | * \param maxlen the maximum wide characters to write, including the |
4183 | * null-terminator. |
4184 | * \param fmt a printf-style format wide string. Must not be NULL. |
4185 | * \param ap a `va_list` values to be used with the format string. |
4186 | * \returns the number of wide characters that should be written, not counting |
4187 | * the null-terminator char, or a negative value on error. |
4188 | * |
4189 | * \threadsafety It is safe to call this function from any thread. |
4190 | * |
4191 | * \since This function is available since SDL 3.2.0. |
4192 | */ |
4193 | extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3); |
4194 | |
4195 | /** |
4196 | * This works exactly like asprintf() but doesn't require access to a C |
4197 | * runtime. |
4198 | * |
4199 | * Functions identically to SDL_snprintf(), except it allocates a buffer large |
4200 | * enough to hold the output string on behalf of the caller. |
4201 | * |
4202 | * On success, this function returns the number of bytes (not characters) |
4203 | * comprising the output string, not counting the null-terminator character, |
4204 | * and sets `*strp` to the newly-allocated string. |
4205 | * |
4206 | * On error, this function returns a negative number, and the value of `*strp` |
4207 | * is undefined. |
4208 | * |
4209 | * The returned string is owned by the caller, and should be passed to |
4210 | * SDL_free when no longer needed. |
4211 | * |
4212 | * \param strp on output, is set to the new string. Must not be NULL. |
4213 | * \param fmt a printf-style format string. Must not be NULL. |
4214 | * \param ... a list of values to be used with the format string. |
4215 | * \returns the number of bytes in the newly-allocated string, not counting |
4216 | * the null-terminator char, or a negative value on error. |
4217 | * |
4218 | * \threadsafety It is safe to call this function from any thread. |
4219 | * |
4220 | * \since This function is available since SDL 3.2.0. |
4221 | */ |
4222 | extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2); |
4223 | |
4224 | /** |
4225 | * This works exactly like vasprintf() but doesn't require access to a C |
4226 | * runtime. |
4227 | * |
4228 | * Functions identically to SDL_asprintf(), except it takes a `va_list` |
4229 | * instead of using `...` variable arguments. |
4230 | * |
4231 | * \param strp on output, is set to the new string. Must not be NULL. |
4232 | * \param fmt a printf-style format string. Must not be NULL. |
4233 | * \param ap a `va_list` values to be used with the format string. |
4234 | * \returns the number of bytes in the newly-allocated string, not counting |
4235 | * the null-terminator char, or a negative value on error. |
4236 | * |
4237 | * \threadsafety It is safe to call this function from any thread. |
4238 | * |
4239 | * \since This function is available since SDL 3.2.0. |
4240 | */ |
4241 | extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2); |
4242 | |
4243 | /** |
4244 | * Seeds the pseudo-random number generator. |
4245 | * |
4246 | * Reusing the seed number will cause SDL_rand() to repeat the same stream of |
4247 | * 'random' numbers. |
4248 | * |
4249 | * \param seed the value to use as a random number seed, or 0 to use |
4250 | * SDL_GetPerformanceCounter(). |
4251 | * |
4252 | * \threadsafety This should be called on the same thread that calls |
4253 | * SDL_rand() |
4254 | * |
4255 | * \since This function is available since SDL 3.2.0. |
4256 | * |
4257 | * \sa SDL_rand |
4258 | * \sa SDL_rand_bits |
4259 | * \sa SDL_randf |
4260 | */ |
4261 | extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed); |
4262 | |
4263 | /** |
4264 | * Generate a pseudo-random number less than n for positive n |
4265 | * |
4266 | * The method used is faster and of better quality than `rand() % n`. Odds are |
4267 | * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and |
4268 | * much worse as n gets bigger. |
4269 | * |
4270 | * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to |
4271 | * 1..6 |
4272 | * |
4273 | * If you want to generate a pseudo-random number in the full range of Sint32, |
4274 | * you should use: (Sint32)SDL_rand_bits() |
4275 | * |
4276 | * If you want reproducible output, be sure to initialize with SDL_srand() |
4277 | * first. |
4278 | * |
4279 | * There are no guarantees as to the quality of the random sequence produced, |
4280 | * and this should not be used for security (cryptography, passwords) or where |
4281 | * money is on the line (loot-boxes, casinos). There are many random number |
4282 | * libraries available with different characteristics and you should pick one |
4283 | * of those to meet any serious needs. |
4284 | * |
4285 | * \param n the number of possible outcomes. n must be positive. |
4286 | * \returns a random value in the range of [0 .. n-1]. |
4287 | * |
4288 | * \threadsafety All calls should be made from a single thread |
4289 | * |
4290 | * \since This function is available since SDL 3.2.0. |
4291 | * |
4292 | * \sa SDL_srand |
4293 | * \sa SDL_randf |
4294 | */ |
4295 | extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n); |
4296 | |
4297 | /** |
4298 | * Generate a uniform pseudo-random floating point number less than 1.0 |
4299 | * |
4300 | * If you want reproducible output, be sure to initialize with SDL_srand() |
4301 | * first. |
4302 | * |
4303 | * There are no guarantees as to the quality of the random sequence produced, |
4304 | * and this should not be used for security (cryptography, passwords) or where |
4305 | * money is on the line (loot-boxes, casinos). There are many random number |
4306 | * libraries available with different characteristics and you should pick one |
4307 | * of those to meet any serious needs. |
4308 | * |
4309 | * \returns a random value in the range of [0.0, 1.0). |
4310 | * |
4311 | * \threadsafety All calls should be made from a single thread |
4312 | * |
4313 | * \since This function is available since SDL 3.2.0. |
4314 | * |
4315 | * \sa SDL_srand |
4316 | * \sa SDL_rand |
4317 | */ |
4318 | extern SDL_DECLSPEC float SDLCALL SDL_randf(void); |
4319 | |
4320 | /** |
4321 | * Generate 32 pseudo-random bits. |
4322 | * |
4323 | * You likely want to use SDL_rand() to get a psuedo-random number instead. |
4324 | * |
4325 | * There are no guarantees as to the quality of the random sequence produced, |
4326 | * and this should not be used for security (cryptography, passwords) or where |
4327 | * money is on the line (loot-boxes, casinos). There are many random number |
4328 | * libraries available with different characteristics and you should pick one |
4329 | * of those to meet any serious needs. |
4330 | * |
4331 | * \returns a random value in the range of [0-SDL_MAX_UINT32]. |
4332 | * |
4333 | * \threadsafety All calls should be made from a single thread |
4334 | * |
4335 | * \since This function is available since SDL 3.2.0. |
4336 | * |
4337 | * \sa SDL_rand |
4338 | * \sa SDL_randf |
4339 | * \sa SDL_srand |
4340 | */ |
4341 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void); |
4342 | |
4343 | /** |
4344 | * Generate a pseudo-random number less than n for positive n |
4345 | * |
4346 | * The method used is faster and of better quality than `rand() % n`. Odds are |
4347 | * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and |
4348 | * much worse as n gets bigger. |
4349 | * |
4350 | * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts |
4351 | * 0..5 to 1..6 |
4352 | * |
4353 | * If you want to generate a pseudo-random number in the full range of Sint32, |
4354 | * you should use: (Sint32)SDL_rand_bits_r(state) |
4355 | * |
4356 | * There are no guarantees as to the quality of the random sequence produced, |
4357 | * and this should not be used for security (cryptography, passwords) or where |
4358 | * money is on the line (loot-boxes, casinos). There are many random number |
4359 | * libraries available with different characteristics and you should pick one |
4360 | * of those to meet any serious needs. |
4361 | * |
4362 | * \param state a pointer to the current random number state, this may not be |
4363 | * NULL. |
4364 | * \param n the number of possible outcomes. n must be positive. |
4365 | * \returns a random value in the range of [0 .. n-1]. |
4366 | * |
4367 | * \threadsafety This function is thread-safe, as long as the state pointer |
4368 | * isn't shared between threads. |
4369 | * |
4370 | * \since This function is available since SDL 3.2.0. |
4371 | * |
4372 | * \sa SDL_rand |
4373 | * \sa SDL_rand_bits_r |
4374 | * \sa SDL_randf_r |
4375 | */ |
4376 | extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n); |
4377 | |
4378 | /** |
4379 | * Generate a uniform pseudo-random floating point number less than 1.0 |
4380 | * |
4381 | * If you want reproducible output, be sure to initialize with SDL_srand() |
4382 | * first. |
4383 | * |
4384 | * There are no guarantees as to the quality of the random sequence produced, |
4385 | * and this should not be used for security (cryptography, passwords) or where |
4386 | * money is on the line (loot-boxes, casinos). There are many random number |
4387 | * libraries available with different characteristics and you should pick one |
4388 | * of those to meet any serious needs. |
4389 | * |
4390 | * \param state a pointer to the current random number state, this may not be |
4391 | * NULL. |
4392 | * \returns a random value in the range of [0.0, 1.0). |
4393 | * |
4394 | * \threadsafety This function is thread-safe, as long as the state pointer |
4395 | * isn't shared between threads. |
4396 | * |
4397 | * \since This function is available since SDL 3.2.0. |
4398 | * |
4399 | * \sa SDL_rand_bits_r |
4400 | * \sa SDL_rand_r |
4401 | * \sa SDL_randf |
4402 | */ |
4403 | extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state); |
4404 | |
4405 | /** |
4406 | * Generate 32 pseudo-random bits. |
4407 | * |
4408 | * You likely want to use SDL_rand_r() to get a psuedo-random number instead. |
4409 | * |
4410 | * There are no guarantees as to the quality of the random sequence produced, |
4411 | * and this should not be used for security (cryptography, passwords) or where |
4412 | * money is on the line (loot-boxes, casinos). There are many random number |
4413 | * libraries available with different characteristics and you should pick one |
4414 | * of those to meet any serious needs. |
4415 | * |
4416 | * \param state a pointer to the current random number state, this may not be |
4417 | * NULL. |
4418 | * \returns a random value in the range of [0-SDL_MAX_UINT32]. |
4419 | * |
4420 | * \threadsafety This function is thread-safe, as long as the state pointer |
4421 | * isn't shared between threads. |
4422 | * |
4423 | * \since This function is available since SDL 3.2.0. |
4424 | * |
4425 | * \sa SDL_rand_r |
4426 | * \sa SDL_randf_r |
4427 | */ |
4428 | extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state); |
4429 | |
4430 | #ifndef SDL_PI_D |
4431 | |
4432 | /** |
4433 | * The value of Pi, as a double-precision floating point literal. |
4434 | * |
4435 | * \since This macro is available since SDL 3.2.0. |
4436 | * |
4437 | * \sa SDL_PI_F |
4438 | */ |
4439 | #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */ |
4440 | #endif |
4441 | |
4442 | #ifndef SDL_PI_F |
4443 | |
4444 | /** |
4445 | * The value of Pi, as a single-precision floating point literal. |
4446 | * |
4447 | * \since This macro is available since SDL 3.2.0. |
4448 | * |
4449 | * \sa SDL_PI_D |
4450 | */ |
4451 | #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */ |
4452 | #endif |
4453 | |
4454 | /** |
4455 | * Compute the arc cosine of `x`. |
4456 | * |
4457 | * The definition of `y = acos(x)` is `x = cos(y)`. |
4458 | * |
4459 | * Domain: `-1 <= x <= 1` |
4460 | * |
4461 | * Range: `0 <= y <= Pi` |
4462 | * |
4463 | * This function operates on double-precision floating point values, use |
4464 | * SDL_acosf for single-precision floats. |
4465 | * |
4466 | * This function may use a different approximation across different versions, |
4467 | * platforms and configurations. i.e, it can return a different value given |
4468 | * the same input on different machines or operating systems, or if SDL is |
4469 | * updated. |
4470 | * |
4471 | * \param x floating point value. |
4472 | * \returns arc cosine of `x`, in radians. |
4473 | * |
4474 | * \threadsafety It is safe to call this function from any thread. |
4475 | * |
4476 | * \since This function is available since SDL 3.2.0. |
4477 | * |
4478 | * \sa SDL_acosf |
4479 | * \sa SDL_asin |
4480 | * \sa SDL_cos |
4481 | */ |
4482 | extern SDL_DECLSPEC double SDLCALL SDL_acos(double x); |
4483 | |
4484 | /** |
4485 | * Compute the arc cosine of `x`. |
4486 | * |
4487 | * The definition of `y = acos(x)` is `x = cos(y)`. |
4488 | * |
4489 | * Domain: `-1 <= x <= 1` |
4490 | * |
4491 | * Range: `0 <= y <= Pi` |
4492 | * |
4493 | * This function operates on single-precision floating point values, use |
4494 | * SDL_acos for double-precision floats. |
4495 | * |
4496 | * This function may use a different approximation across different versions, |
4497 | * platforms and configurations. i.e, it can return a different value given |
4498 | * the same input on different machines or operating systems, or if SDL is |
4499 | * updated. |
4500 | * |
4501 | * \param x floating point value. |
4502 | * \returns arc cosine of `x`, in radians. |
4503 | * |
4504 | * \threadsafety It is safe to call this function from any thread. |
4505 | * |
4506 | * \since This function is available since SDL 3.2.0. |
4507 | * |
4508 | * \sa SDL_acos |
4509 | * \sa SDL_asinf |
4510 | * \sa SDL_cosf |
4511 | */ |
4512 | extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x); |
4513 | |
4514 | /** |
4515 | * Compute the arc sine of `x`. |
4516 | * |
4517 | * The definition of `y = asin(x)` is `x = sin(y)`. |
4518 | * |
4519 | * Domain: `-1 <= x <= 1` |
4520 | * |
4521 | * Range: `-Pi/2 <= y <= Pi/2` |
4522 | * |
4523 | * This function operates on double-precision floating point values, use |
4524 | * SDL_asinf for single-precision floats. |
4525 | * |
4526 | * This function may use a different approximation across different versions, |
4527 | * platforms and configurations. i.e, it can return a different value given |
4528 | * the same input on different machines or operating systems, or if SDL is |
4529 | * updated. |
4530 | * |
4531 | * \param x floating point value. |
4532 | * \returns arc sine of `x`, in radians. |
4533 | * |
4534 | * \threadsafety It is safe to call this function from any thread. |
4535 | * |
4536 | * \since This function is available since SDL 3.2.0. |
4537 | * |
4538 | * \sa SDL_asinf |
4539 | * \sa SDL_acos |
4540 | * \sa SDL_sin |
4541 | */ |
4542 | extern SDL_DECLSPEC double SDLCALL SDL_asin(double x); |
4543 | |
4544 | /** |
4545 | * Compute the arc sine of `x`. |
4546 | * |
4547 | * The definition of `y = asin(x)` is `x = sin(y)`. |
4548 | * |
4549 | * Domain: `-1 <= x <= 1` |
4550 | * |
4551 | * Range: `-Pi/2 <= y <= Pi/2` |
4552 | * |
4553 | * This function operates on single-precision floating point values, use |
4554 | * SDL_asin for double-precision floats. |
4555 | * |
4556 | * This function may use a different approximation across different versions, |
4557 | * platforms and configurations. i.e, it can return a different value given |
4558 | * the same input on different machines or operating systems, or if SDL is |
4559 | * updated. |
4560 | * |
4561 | * \param x floating point value. |
4562 | * \returns arc sine of `x`, in radians. |
4563 | * |
4564 | * \threadsafety It is safe to call this function from any thread. |
4565 | * |
4566 | * \since This function is available since SDL 3.2.0. |
4567 | * |
4568 | * \sa SDL_asin |
4569 | * \sa SDL_acosf |
4570 | * \sa SDL_sinf |
4571 | */ |
4572 | extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x); |
4573 | |
4574 | /** |
4575 | * Compute the arc tangent of `x`. |
4576 | * |
4577 | * The definition of `y = atan(x)` is `x = tan(y)`. |
4578 | * |
4579 | * Domain: `-INF <= x <= INF` |
4580 | * |
4581 | * Range: `-Pi/2 <= y <= Pi/2` |
4582 | * |
4583 | * This function operates on double-precision floating point values, use |
4584 | * SDL_atanf for single-precision floats. |
4585 | * |
4586 | * To calculate the arc tangent of y / x, use SDL_atan2. |
4587 | * |
4588 | * This function may use a different approximation across different versions, |
4589 | * platforms and configurations. i.e, it can return a different value given |
4590 | * the same input on different machines or operating systems, or if SDL is |
4591 | * updated. |
4592 | * |
4593 | * \param x floating point value. |
4594 | * \returns arc tangent of of `x` in radians, or 0 if `x = 0`. |
4595 | * |
4596 | * \threadsafety It is safe to call this function from any thread. |
4597 | * |
4598 | * \since This function is available since SDL 3.2.0. |
4599 | * |
4600 | * \sa SDL_atanf |
4601 | * \sa SDL_atan2 |
4602 | * \sa SDL_tan |
4603 | */ |
4604 | extern SDL_DECLSPEC double SDLCALL SDL_atan(double x); |
4605 | |
4606 | /** |
4607 | * Compute the arc tangent of `x`. |
4608 | * |
4609 | * The definition of `y = atan(x)` is `x = tan(y)`. |
4610 | * |
4611 | * Domain: `-INF <= x <= INF` |
4612 | * |
4613 | * Range: `-Pi/2 <= y <= Pi/2` |
4614 | * |
4615 | * This function operates on single-precision floating point values, use |
4616 | * SDL_atan for dboule-precision floats. |
4617 | * |
4618 | * To calculate the arc tangent of y / x, use SDL_atan2f. |
4619 | * |
4620 | * This function may use a different approximation across different versions, |
4621 | * platforms and configurations. i.e, it can return a different value given |
4622 | * the same input on different machines or operating systems, or if SDL is |
4623 | * updated. |
4624 | * |
4625 | * \param x floating point value. |
4626 | * \returns arc tangent of of `x` in radians, or 0 if `x = 0`. |
4627 | * |
4628 | * \threadsafety It is safe to call this function from any thread. |
4629 | * |
4630 | * \since This function is available since SDL 3.2.0. |
4631 | * |
4632 | * \sa SDL_atan |
4633 | * \sa SDL_atan2f |
4634 | * \sa SDL_tanf |
4635 | */ |
4636 | extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x); |
4637 | |
4638 | /** |
4639 | * Compute the arc tangent of `y / x`, using the signs of x and y to adjust |
4640 | * the result's quadrant. |
4641 | * |
4642 | * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant |
4643 | * of z is determined based on the signs of x and y. |
4644 | * |
4645 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF` |
4646 | * |
4647 | * Range: `-Pi/2 <= y <= Pi/2` |
4648 | * |
4649 | * This function operates on double-precision floating point values, use |
4650 | * SDL_atan2f for single-precision floats. |
4651 | * |
4652 | * To calculate the arc tangent of a single value, use SDL_atan. |
4653 | * |
4654 | * This function may use a different approximation across different versions, |
4655 | * platforms and configurations. i.e, it can return a different value given |
4656 | * the same input on different machines or operating systems, or if SDL is |
4657 | * updated. |
4658 | * |
4659 | * \param y floating point value of the numerator (y coordinate). |
4660 | * \param x floating point value of the denominator (x coordinate). |
4661 | * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either |
4662 | * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`. |
4663 | * |
4664 | * \threadsafety It is safe to call this function from any thread. |
4665 | * |
4666 | * \since This function is available since SDL 3.2.0. |
4667 | * |
4668 | * \sa SDL_atan2f |
4669 | * \sa SDL_atan |
4670 | * \sa SDL_tan |
4671 | */ |
4672 | extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x); |
4673 | |
4674 | /** |
4675 | * Compute the arc tangent of `y / x`, using the signs of x and y to adjust |
4676 | * the result's quadrant. |
4677 | * |
4678 | * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant |
4679 | * of z is determined based on the signs of x and y. |
4680 | * |
4681 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF` |
4682 | * |
4683 | * Range: `-Pi/2 <= y <= Pi/2` |
4684 | * |
4685 | * This function operates on single-precision floating point values, use |
4686 | * SDL_atan2 for double-precision floats. |
4687 | * |
4688 | * To calculate the arc tangent of a single value, use SDL_atanf. |
4689 | * |
4690 | * This function may use a different approximation across different versions, |
4691 | * platforms and configurations. i.e, it can return a different value given |
4692 | * the same input on different machines or operating systems, or if SDL is |
4693 | * updated. |
4694 | * |
4695 | * \param y floating point value of the numerator (y coordinate). |
4696 | * \param x floating point value of the denominator (x coordinate). |
4697 | * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either |
4698 | * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`. |
4699 | * |
4700 | * \threadsafety It is safe to call this function from any thread. |
4701 | * |
4702 | * \since This function is available since SDL 3.2.0. |
4703 | * |
4704 | * \sa SDL_atan2 |
4705 | * \sa SDL_atan |
4706 | * \sa SDL_tan |
4707 | */ |
4708 | extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x); |
4709 | |
4710 | /** |
4711 | * Compute the ceiling of `x`. |
4712 | * |
4713 | * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x` |
4714 | * rounded up to the nearest integer. |
4715 | * |
4716 | * Domain: `-INF <= x <= INF` |
4717 | * |
4718 | * Range: `-INF <= y <= INF`, y integer |
4719 | * |
4720 | * This function operates on double-precision floating point values, use |
4721 | * SDL_ceilf for single-precision floats. |
4722 | * |
4723 | * \param x floating point value. |
4724 | * \returns the ceiling of `x`. |
4725 | * |
4726 | * \threadsafety It is safe to call this function from any thread. |
4727 | * |
4728 | * \since This function is available since SDL 3.2.0. |
4729 | * |
4730 | * \sa SDL_ceilf |
4731 | * \sa SDL_floor |
4732 | * \sa SDL_trunc |
4733 | * \sa SDL_round |
4734 | * \sa SDL_lround |
4735 | */ |
4736 | extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x); |
4737 | |
4738 | /** |
4739 | * Compute the ceiling of `x`. |
4740 | * |
4741 | * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x` |
4742 | * rounded up to the nearest integer. |
4743 | * |
4744 | * Domain: `-INF <= x <= INF` |
4745 | * |
4746 | * Range: `-INF <= y <= INF`, y integer |
4747 | * |
4748 | * This function operates on single-precision floating point values, use |
4749 | * SDL_ceil for double-precision floats. |
4750 | * |
4751 | * \param x floating point value. |
4752 | * \returns the ceiling of `x`. |
4753 | * |
4754 | * \threadsafety It is safe to call this function from any thread. |
4755 | * |
4756 | * \since This function is available since SDL 3.2.0. |
4757 | * |
4758 | * \sa SDL_ceil |
4759 | * \sa SDL_floorf |
4760 | * \sa SDL_truncf |
4761 | * \sa SDL_roundf |
4762 | * \sa SDL_lroundf |
4763 | */ |
4764 | extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x); |
4765 | |
4766 | /** |
4767 | * Copy the sign of one floating-point value to another. |
4768 | * |
4769 | * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``. |
4770 | * |
4771 | * Domain: `-INF <= x <= INF`, ``-INF <= y <= f`` |
4772 | * |
4773 | * Range: `-INF <= z <= INF` |
4774 | * |
4775 | * This function operates on double-precision floating point values, use |
4776 | * SDL_copysignf for single-precision floats. |
4777 | * |
4778 | * \param x floating point value to use as the magnitude. |
4779 | * \param y floating point value to use as the sign. |
4780 | * \returns the floating point value with the sign of y and the magnitude of |
4781 | * x. |
4782 | * |
4783 | * \threadsafety It is safe to call this function from any thread. |
4784 | * |
4785 | * \since This function is available since SDL 3.2.0. |
4786 | * |
4787 | * \sa SDL_copysignf |
4788 | * \sa SDL_fabs |
4789 | */ |
4790 | extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y); |
4791 | |
4792 | /** |
4793 | * Copy the sign of one floating-point value to another. |
4794 | * |
4795 | * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``. |
4796 | * |
4797 | * Domain: `-INF <= x <= INF`, ``-INF <= y <= f`` |
4798 | * |
4799 | * Range: `-INF <= z <= INF` |
4800 | * |
4801 | * This function operates on single-precision floating point values, use |
4802 | * SDL_copysign for double-precision floats. |
4803 | * |
4804 | * \param x floating point value to use as the magnitude. |
4805 | * \param y floating point value to use as the sign. |
4806 | * \returns the floating point value with the sign of y and the magnitude of |
4807 | * x. |
4808 | * |
4809 | * \threadsafety It is safe to call this function from any thread. |
4810 | * |
4811 | * \since This function is available since SDL 3.2.0. |
4812 | * |
4813 | * \sa SDL_copysign |
4814 | * \sa SDL_fabsf |
4815 | */ |
4816 | extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y); |
4817 | |
4818 | /** |
4819 | * Compute the cosine of `x`. |
4820 | * |
4821 | * Domain: `-INF <= x <= INF` |
4822 | * |
4823 | * Range: `-1 <= y <= 1` |
4824 | * |
4825 | * This function operates on double-precision floating point values, use |
4826 | * SDL_cosf for single-precision floats. |
4827 | * |
4828 | * This function may use a different approximation across different versions, |
4829 | * platforms and configurations. i.e, it can return a different value given |
4830 | * the same input on different machines or operating systems, or if SDL is |
4831 | * updated. |
4832 | * |
4833 | * \param x floating point value, in radians. |
4834 | * \returns cosine of `x`. |
4835 | * |
4836 | * \threadsafety It is safe to call this function from any thread. |
4837 | * |
4838 | * \since This function is available since SDL 3.2.0. |
4839 | * |
4840 | * \sa SDL_cosf |
4841 | * \sa SDL_acos |
4842 | * \sa SDL_sin |
4843 | */ |
4844 | extern SDL_DECLSPEC double SDLCALL SDL_cos(double x); |
4845 | |
4846 | /** |
4847 | * Compute the cosine of `x`. |
4848 | * |
4849 | * Domain: `-INF <= x <= INF` |
4850 | * |
4851 | * Range: `-1 <= y <= 1` |
4852 | * |
4853 | * This function operates on single-precision floating point values, use |
4854 | * SDL_cos for double-precision floats. |
4855 | * |
4856 | * This function may use a different approximation across different versions, |
4857 | * platforms and configurations. i.e, it can return a different value given |
4858 | * the same input on different machines or operating systems, or if SDL is |
4859 | * updated. |
4860 | * |
4861 | * \param x floating point value, in radians. |
4862 | * \returns cosine of `x`. |
4863 | * |
4864 | * \threadsafety It is safe to call this function from any thread. |
4865 | * |
4866 | * \since This function is available since SDL 3.2.0. |
4867 | * |
4868 | * \sa SDL_cos |
4869 | * \sa SDL_acosf |
4870 | * \sa SDL_sinf |
4871 | */ |
4872 | extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x); |
4873 | |
4874 | /** |
4875 | * Compute the exponential of `x`. |
4876 | * |
4877 | * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the |
4878 | * natural logarithm. The inverse is the natural logarithm, SDL_log. |
4879 | * |
4880 | * Domain: `-INF <= x <= INF` |
4881 | * |
4882 | * Range: `0 <= y <= INF` |
4883 | * |
4884 | * The output will overflow if `exp(x)` is too large to be represented. |
4885 | * |
4886 | * This function operates on double-precision floating point values, use |
4887 | * SDL_expf for single-precision floats. |
4888 | * |
4889 | * This function may use a different approximation across different versions, |
4890 | * platforms and configurations. i.e, it can return a different value given |
4891 | * the same input on different machines or operating systems, or if SDL is |
4892 | * updated. |
4893 | * |
4894 | * \param x floating point value. |
4895 | * \returns value of `e^x`. |
4896 | * |
4897 | * \threadsafety It is safe to call this function from any thread. |
4898 | * |
4899 | * \since This function is available since SDL 3.2.0. |
4900 | * |
4901 | * \sa SDL_expf |
4902 | * \sa SDL_log |
4903 | */ |
4904 | extern SDL_DECLSPEC double SDLCALL SDL_exp(double x); |
4905 | |
4906 | /** |
4907 | * Compute the exponential of `x`. |
4908 | * |
4909 | * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the |
4910 | * natural logarithm. The inverse is the natural logarithm, SDL_logf. |
4911 | * |
4912 | * Domain: `-INF <= x <= INF` |
4913 | * |
4914 | * Range: `0 <= y <= INF` |
4915 | * |
4916 | * The output will overflow if `exp(x)` is too large to be represented. |
4917 | * |
4918 | * This function operates on single-precision floating point values, use |
4919 | * SDL_exp for double-precision floats. |
4920 | * |
4921 | * This function may use a different approximation across different versions, |
4922 | * platforms and configurations. i.e, it can return a different value given |
4923 | * the same input on different machines or operating systems, or if SDL is |
4924 | * updated. |
4925 | * |
4926 | * \param x floating point value. |
4927 | * \returns value of `e^x`. |
4928 | * |
4929 | * \threadsafety It is safe to call this function from any thread. |
4930 | * |
4931 | * \since This function is available since SDL 3.2.0. |
4932 | * |
4933 | * \sa SDL_exp |
4934 | * \sa SDL_logf |
4935 | */ |
4936 | extern SDL_DECLSPEC float SDLCALL SDL_expf(float x); |
4937 | |
4938 | /** |
4939 | * Compute the absolute value of `x` |
4940 | * |
4941 | * Domain: `-INF <= x <= INF` |
4942 | * |
4943 | * Range: `0 <= y <= INF` |
4944 | * |
4945 | * This function operates on double-precision floating point values, use |
4946 | * SDL_fabsf for single-precision floats. |
4947 | * |
4948 | * \param x floating point value to use as the magnitude. |
4949 | * \returns the absolute value of `x`. |
4950 | * |
4951 | * \threadsafety It is safe to call this function from any thread. |
4952 | * |
4953 | * \since This function is available since SDL 3.2.0. |
4954 | * |
4955 | * \sa SDL_fabsf |
4956 | */ |
4957 | extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x); |
4958 | |
4959 | /** |
4960 | * Compute the absolute value of `x` |
4961 | * |
4962 | * Domain: `-INF <= x <= INF` |
4963 | * |
4964 | * Range: `0 <= y <= INF` |
4965 | * |
4966 | * This function operates on single-precision floating point values, use |
4967 | * SDL_fabs for double-precision floats. |
4968 | * |
4969 | * \param x floating point value to use as the magnitude. |
4970 | * \returns the absolute value of `x`. |
4971 | * |
4972 | * \threadsafety It is safe to call this function from any thread. |
4973 | * |
4974 | * \since This function is available since SDL 3.2.0. |
4975 | * |
4976 | * \sa SDL_fabs |
4977 | */ |
4978 | extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x); |
4979 | |
4980 | /** |
4981 | * Compute the floor of `x`. |
4982 | * |
4983 | * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x` |
4984 | * rounded down to the nearest integer. |
4985 | * |
4986 | * Domain: `-INF <= x <= INF` |
4987 | * |
4988 | * Range: `-INF <= y <= INF`, y integer |
4989 | * |
4990 | * This function operates on double-precision floating point values, use |
4991 | * SDL_floorf for single-precision floats. |
4992 | * |
4993 | * \param x floating point value. |
4994 | * \returns the floor of `x`. |
4995 | * |
4996 | * \threadsafety It is safe to call this function from any thread. |
4997 | * |
4998 | * \since This function is available since SDL 3.2.0. |
4999 | * |
5000 | * \sa SDL_floorf |
5001 | * \sa SDL_ceil |
5002 | * \sa SDL_trunc |
5003 | * \sa SDL_round |
5004 | * \sa SDL_lround |
5005 | */ |
5006 | extern SDL_DECLSPEC double SDLCALL SDL_floor(double x); |
5007 | |
5008 | /** |
5009 | * Compute the floor of `x`. |
5010 | * |
5011 | * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x` |
5012 | * rounded down to the nearest integer. |
5013 | * |
5014 | * Domain: `-INF <= x <= INF` |
5015 | * |
5016 | * Range: `-INF <= y <= INF`, y integer |
5017 | * |
5018 | * This function operates on single-precision floating point values, use |
5019 | * SDL_floor for double-precision floats. |
5020 | * |
5021 | * \param x floating point value. |
5022 | * \returns the floor of `x`. |
5023 | * |
5024 | * \threadsafety It is safe to call this function from any thread. |
5025 | * |
5026 | * \since This function is available since SDL 3.2.0. |
5027 | * |
5028 | * \sa SDL_floor |
5029 | * \sa SDL_ceilf |
5030 | * \sa SDL_truncf |
5031 | * \sa SDL_roundf |
5032 | * \sa SDL_lroundf |
5033 | */ |
5034 | extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x); |
5035 | |
5036 | /** |
5037 | * Truncate `x` to an integer. |
5038 | * |
5039 | * Rounds `x` to the next closest integer to 0. This is equivalent to removing |
5040 | * the fractional part of `x`, leaving only the integer part. |
5041 | * |
5042 | * Domain: `-INF <= x <= INF` |
5043 | * |
5044 | * Range: `-INF <= y <= INF`, y integer |
5045 | * |
5046 | * This function operates on double-precision floating point values, use |
5047 | * SDL_truncf for single-precision floats. |
5048 | * |
5049 | * \param x floating point value. |
5050 | * \returns `x` truncated to an integer. |
5051 | * |
5052 | * \threadsafety It is safe to call this function from any thread. |
5053 | * |
5054 | * \since This function is available since SDL 3.2.0. |
5055 | * |
5056 | * \sa SDL_truncf |
5057 | * \sa SDL_fmod |
5058 | * \sa SDL_ceil |
5059 | * \sa SDL_floor |
5060 | * \sa SDL_round |
5061 | * \sa SDL_lround |
5062 | */ |
5063 | extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x); |
5064 | |
5065 | /** |
5066 | * Truncate `x` to an integer. |
5067 | * |
5068 | * Rounds `x` to the next closest integer to 0. This is equivalent to removing |
5069 | * the fractional part of `x`, leaving only the integer part. |
5070 | * |
5071 | * Domain: `-INF <= x <= INF` |
5072 | * |
5073 | * Range: `-INF <= y <= INF`, y integer |
5074 | * |
5075 | * This function operates on single-precision floating point values, use |
5076 | * SDL_trunc for double-precision floats. |
5077 | * |
5078 | * \param x floating point value. |
5079 | * \returns `x` truncated to an integer. |
5080 | * |
5081 | * \threadsafety It is safe to call this function from any thread. |
5082 | * |
5083 | * \since This function is available since SDL 3.2.0. |
5084 | * |
5085 | * \sa SDL_trunc |
5086 | * \sa SDL_fmodf |
5087 | * \sa SDL_ceilf |
5088 | * \sa SDL_floorf |
5089 | * \sa SDL_roundf |
5090 | * \sa SDL_lroundf |
5091 | */ |
5092 | extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x); |
5093 | |
5094 | /** |
5095 | * Return the floating-point remainder of `x / y` |
5096 | * |
5097 | * Divides `x` by `y`, and returns the remainder. |
5098 | * |
5099 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0` |
5100 | * |
5101 | * Range: `-y <= z <= y` |
5102 | * |
5103 | * This function operates on double-precision floating point values, use |
5104 | * SDL_fmodf for single-precision floats. |
5105 | * |
5106 | * \param x the numerator. |
5107 | * \param y the denominator. Must not be 0. |
5108 | * \returns the remainder of `x / y`. |
5109 | * |
5110 | * \threadsafety It is safe to call this function from any thread. |
5111 | * |
5112 | * \since This function is available since SDL 3.2.0. |
5113 | * |
5114 | * \sa SDL_fmodf |
5115 | * \sa SDL_modf |
5116 | * \sa SDL_trunc |
5117 | * \sa SDL_ceil |
5118 | * \sa SDL_floor |
5119 | * \sa SDL_round |
5120 | * \sa SDL_lround |
5121 | */ |
5122 | extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y); |
5123 | |
5124 | /** |
5125 | * Return the floating-point remainder of `x / y` |
5126 | * |
5127 | * Divides `x` by `y`, and returns the remainder. |
5128 | * |
5129 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0` |
5130 | * |
5131 | * Range: `-y <= z <= y` |
5132 | * |
5133 | * This function operates on single-precision floating point values, use |
5134 | * SDL_fmod for double-precision floats. |
5135 | * |
5136 | * \param x the numerator. |
5137 | * \param y the denominator. Must not be 0. |
5138 | * \returns the remainder of `x / y`. |
5139 | * |
5140 | * \threadsafety It is safe to call this function from any thread. |
5141 | * |
5142 | * \since This function is available since SDL 3.2.0. |
5143 | * |
5144 | * \sa SDL_fmod |
5145 | * \sa SDL_truncf |
5146 | * \sa SDL_modff |
5147 | * \sa SDL_ceilf |
5148 | * \sa SDL_floorf |
5149 | * \sa SDL_roundf |
5150 | * \sa SDL_lroundf |
5151 | */ |
5152 | extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y); |
5153 | |
5154 | /** |
5155 | * Return whether the value is infinity. |
5156 | * |
5157 | * \param x double-precision floating point value. |
5158 | * \returns non-zero if the value is infinity, 0 otherwise. |
5159 | * |
5160 | * \threadsafety It is safe to call this function from any thread. |
5161 | * |
5162 | * \since This function is available since SDL 3.2.0. |
5163 | * |
5164 | * \sa SDL_isinff |
5165 | */ |
5166 | extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x); |
5167 | |
5168 | /** |
5169 | * Return whether the value is infinity. |
5170 | * |
5171 | * \param x floating point value. |
5172 | * \returns non-zero if the value is infinity, 0 otherwise. |
5173 | * |
5174 | * \threadsafety It is safe to call this function from any thread. |
5175 | * |
5176 | * \since This function is available since SDL 3.2.0. |
5177 | * |
5178 | * \sa SDL_isinf |
5179 | */ |
5180 | extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x); |
5181 | |
5182 | /** |
5183 | * Return whether the value is NaN. |
5184 | * |
5185 | * \param x double-precision floating point value. |
5186 | * \returns non-zero if the value is NaN, 0 otherwise. |
5187 | * |
5188 | * \threadsafety It is safe to call this function from any thread. |
5189 | * |
5190 | * \since This function is available since SDL 3.2.0. |
5191 | * |
5192 | * \sa SDL_isnanf |
5193 | */ |
5194 | extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x); |
5195 | |
5196 | /** |
5197 | * Return whether the value is NaN. |
5198 | * |
5199 | * \param x floating point value. |
5200 | * \returns non-zero if the value is NaN, 0 otherwise. |
5201 | * |
5202 | * \threadsafety It is safe to call this function from any thread. |
5203 | * |
5204 | * \since This function is available since SDL 3.2.0. |
5205 | * |
5206 | * \sa SDL_isnan |
5207 | */ |
5208 | extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x); |
5209 | |
5210 | /** |
5211 | * Compute the natural logarithm of `x`. |
5212 | * |
5213 | * Domain: `0 < x <= INF` |
5214 | * |
5215 | * Range: `-INF <= y <= INF` |
5216 | * |
5217 | * It is an error for `x` to be less than or equal to 0. |
5218 | * |
5219 | * This function operates on double-precision floating point values, use |
5220 | * SDL_logf for single-precision floats. |
5221 | * |
5222 | * This function may use a different approximation across different versions, |
5223 | * platforms and configurations. i.e, it can return a different value given |
5224 | * the same input on different machines or operating systems, or if SDL is |
5225 | * updated. |
5226 | * |
5227 | * \param x floating point value. Must be greater than 0. |
5228 | * \returns the natural logarithm of `x`. |
5229 | * |
5230 | * \threadsafety It is safe to call this function from any thread. |
5231 | * |
5232 | * \since This function is available since SDL 3.2.0. |
5233 | * |
5234 | * \sa SDL_logf |
5235 | * \sa SDL_log10 |
5236 | * \sa SDL_exp |
5237 | */ |
5238 | extern SDL_DECLSPEC double SDLCALL SDL_log(double x); |
5239 | |
5240 | /** |
5241 | * Compute the natural logarithm of `x`. |
5242 | * |
5243 | * Domain: `0 < x <= INF` |
5244 | * |
5245 | * Range: `-INF <= y <= INF` |
5246 | * |
5247 | * It is an error for `x` to be less than or equal to 0. |
5248 | * |
5249 | * This function operates on single-precision floating point values, use |
5250 | * SDL_log for double-precision floats. |
5251 | * |
5252 | * This function may use a different approximation across different versions, |
5253 | * platforms and configurations. i.e, it can return a different value given |
5254 | * the same input on different machines or operating systems, or if SDL is |
5255 | * updated. |
5256 | * |
5257 | * \param x floating point value. Must be greater than 0. |
5258 | * \returns the natural logarithm of `x`. |
5259 | * |
5260 | * \threadsafety It is safe to call this function from any thread. |
5261 | * |
5262 | * \since This function is available since SDL 3.2.0. |
5263 | * |
5264 | * \sa SDL_log |
5265 | * \sa SDL_expf |
5266 | */ |
5267 | extern SDL_DECLSPEC float SDLCALL SDL_logf(float x); |
5268 | |
5269 | /** |
5270 | * Compute the base-10 logarithm of `x`. |
5271 | * |
5272 | * Domain: `0 < x <= INF` |
5273 | * |
5274 | * Range: `-INF <= y <= INF` |
5275 | * |
5276 | * It is an error for `x` to be less than or equal to 0. |
5277 | * |
5278 | * This function operates on double-precision floating point values, use |
5279 | * SDL_log10f for single-precision floats. |
5280 | * |
5281 | * This function may use a different approximation across different versions, |
5282 | * platforms and configurations. i.e, it can return a different value given |
5283 | * the same input on different machines or operating systems, or if SDL is |
5284 | * updated. |
5285 | * |
5286 | * \param x floating point value. Must be greater than 0. |
5287 | * \returns the logarithm of `x`. |
5288 | * |
5289 | * \threadsafety It is safe to call this function from any thread. |
5290 | * |
5291 | * \since This function is available since SDL 3.2.0. |
5292 | * |
5293 | * \sa SDL_log10f |
5294 | * \sa SDL_log |
5295 | * \sa SDL_pow |
5296 | */ |
5297 | extern SDL_DECLSPEC double SDLCALL SDL_log10(double x); |
5298 | |
5299 | /** |
5300 | * Compute the base-10 logarithm of `x`. |
5301 | * |
5302 | * Domain: `0 < x <= INF` |
5303 | * |
5304 | * Range: `-INF <= y <= INF` |
5305 | * |
5306 | * It is an error for `x` to be less than or equal to 0. |
5307 | * |
5308 | * This function operates on single-precision floating point values, use |
5309 | * SDL_log10 for double-precision floats. |
5310 | * |
5311 | * This function may use a different approximation across different versions, |
5312 | * platforms and configurations. i.e, it can return a different value given |
5313 | * the same input on different machines or operating systems, or if SDL is |
5314 | * updated. |
5315 | * |
5316 | * \param x floating point value. Must be greater than 0. |
5317 | * \returns the logarithm of `x`. |
5318 | * |
5319 | * \threadsafety It is safe to call this function from any thread. |
5320 | * |
5321 | * \since This function is available since SDL 3.2.0. |
5322 | * |
5323 | * \sa SDL_log10 |
5324 | * \sa SDL_logf |
5325 | * \sa SDL_powf |
5326 | */ |
5327 | extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x); |
5328 | |
5329 | /** |
5330 | * Split `x` into integer and fractional parts |
5331 | * |
5332 | * This function operates on double-precision floating point values, use |
5333 | * SDL_modff for single-precision floats. |
5334 | * |
5335 | * \param x floating point value. |
5336 | * \param y output pointer to store the integer part of `x`. |
5337 | * \returns the fractional part of `x`. |
5338 | * |
5339 | * \threadsafety It is safe to call this function from any thread. |
5340 | * |
5341 | * \since This function is available since SDL 3.2.0. |
5342 | * |
5343 | * \sa SDL_modff |
5344 | * \sa SDL_trunc |
5345 | * \sa SDL_fmod |
5346 | */ |
5347 | extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y); |
5348 | |
5349 | /** |
5350 | * Split `x` into integer and fractional parts |
5351 | * |
5352 | * This function operates on single-precision floating point values, use |
5353 | * SDL_modf for double-precision floats. |
5354 | * |
5355 | * \param x floating point value. |
5356 | * \param y output pointer to store the integer part of `x`. |
5357 | * \returns the fractional part of `x`. |
5358 | * |
5359 | * \threadsafety It is safe to call this function from any thread. |
5360 | * |
5361 | * \since This function is available since SDL 3.2.0. |
5362 | * |
5363 | * \sa SDL_modf |
5364 | * \sa SDL_truncf |
5365 | * \sa SDL_fmodf |
5366 | */ |
5367 | extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y); |
5368 | |
5369 | /** |
5370 | * Raise `x` to the power `y` |
5371 | * |
5372 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF` |
5373 | * |
5374 | * Range: `-INF <= z <= INF` |
5375 | * |
5376 | * If `y` is the base of the natural logarithm (e), consider using SDL_exp |
5377 | * instead. |
5378 | * |
5379 | * This function operates on double-precision floating point values, use |
5380 | * SDL_powf for single-precision floats. |
5381 | * |
5382 | * This function may use a different approximation across different versions, |
5383 | * platforms and configurations. i.e, it can return a different value given |
5384 | * the same input on different machines or operating systems, or if SDL is |
5385 | * updated. |
5386 | * |
5387 | * \param x the base. |
5388 | * \param y the exponent. |
5389 | * \returns `x` raised to the power `y`. |
5390 | * |
5391 | * \threadsafety It is safe to call this function from any thread. |
5392 | * |
5393 | * \since This function is available since SDL 3.2.0. |
5394 | * |
5395 | * \sa SDL_powf |
5396 | * \sa SDL_exp |
5397 | * \sa SDL_log |
5398 | */ |
5399 | extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y); |
5400 | |
5401 | /** |
5402 | * Raise `x` to the power `y` |
5403 | * |
5404 | * Domain: `-INF <= x <= INF`, `-INF <= y <= INF` |
5405 | * |
5406 | * Range: `-INF <= z <= INF` |
5407 | * |
5408 | * If `y` is the base of the natural logarithm (e), consider using SDL_exp |
5409 | * instead. |
5410 | * |
5411 | * This function operates on single-precision floating point values, use |
5412 | * SDL_pow for double-precision floats. |
5413 | * |
5414 | * This function may use a different approximation across different versions, |
5415 | * platforms and configurations. i.e, it can return a different value given |
5416 | * the same input on different machines or operating systems, or if SDL is |
5417 | * updated. |
5418 | * |
5419 | * \param x the base. |
5420 | * \param y the exponent. |
5421 | * \returns `x` raised to the power `y`. |
5422 | * |
5423 | * \threadsafety It is safe to call this function from any thread. |
5424 | * |
5425 | * \since This function is available since SDL 3.2.0. |
5426 | * |
5427 | * \sa SDL_pow |
5428 | * \sa SDL_expf |
5429 | * \sa SDL_logf |
5430 | */ |
5431 | extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y); |
5432 | |
5433 | /** |
5434 | * Round `x` to the nearest integer. |
5435 | * |
5436 | * Rounds `x` to the nearest integer. Values halfway between integers will be |
5437 | * rounded away from zero. |
5438 | * |
5439 | * Domain: `-INF <= x <= INF` |
5440 | * |
5441 | * Range: `-INF <= y <= INF`, y integer |
5442 | * |
5443 | * This function operates on double-precision floating point values, use |
5444 | * SDL_roundf for single-precision floats. To get the result as an integer |
5445 | * type, use SDL_lround. |
5446 | * |
5447 | * \param x floating point value. |
5448 | * \returns the nearest integer to `x`. |
5449 | * |
5450 | * \threadsafety It is safe to call this function from any thread. |
5451 | * |
5452 | * \since This function is available since SDL 3.2.0. |
5453 | * |
5454 | * \sa SDL_roundf |
5455 | * \sa SDL_lround |
5456 | * \sa SDL_floor |
5457 | * \sa SDL_ceil |
5458 | * \sa SDL_trunc |
5459 | */ |
5460 | extern SDL_DECLSPEC double SDLCALL SDL_round(double x); |
5461 | |
5462 | /** |
5463 | * Round `x` to the nearest integer. |
5464 | * |
5465 | * Rounds `x` to the nearest integer. Values halfway between integers will be |
5466 | * rounded away from zero. |
5467 | * |
5468 | * Domain: `-INF <= x <= INF` |
5469 | * |
5470 | * Range: `-INF <= y <= INF`, y integer |
5471 | * |
5472 | * This function operates on single-precision floating point values, use |
5473 | * SDL_round for double-precision floats. To get the result as an integer |
5474 | * type, use SDL_lroundf. |
5475 | * |
5476 | * \param x floating point value. |
5477 | * \returns the nearest integer to `x`. |
5478 | * |
5479 | * \threadsafety It is safe to call this function from any thread. |
5480 | * |
5481 | * \since This function is available since SDL 3.2.0. |
5482 | * |
5483 | * \sa SDL_round |
5484 | * \sa SDL_lroundf |
5485 | * \sa SDL_floorf |
5486 | * \sa SDL_ceilf |
5487 | * \sa SDL_truncf |
5488 | */ |
5489 | extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x); |
5490 | |
5491 | /** |
5492 | * Round `x` to the nearest integer representable as a long |
5493 | * |
5494 | * Rounds `x` to the nearest integer. Values halfway between integers will be |
5495 | * rounded away from zero. |
5496 | * |
5497 | * Domain: `-INF <= x <= INF` |
5498 | * |
5499 | * Range: `MIN_LONG <= y <= MAX_LONG` |
5500 | * |
5501 | * This function operates on double-precision floating point values, use |
5502 | * SDL_lroundf for single-precision floats. To get the result as a |
5503 | * floating-point type, use SDL_round. |
5504 | * |
5505 | * \param x floating point value. |
5506 | * \returns the nearest integer to `x`. |
5507 | * |
5508 | * \threadsafety It is safe to call this function from any thread. |
5509 | * |
5510 | * \since This function is available since SDL 3.2.0. |
5511 | * |
5512 | * \sa SDL_lroundf |
5513 | * \sa SDL_round |
5514 | * \sa SDL_floor |
5515 | * \sa SDL_ceil |
5516 | * \sa SDL_trunc |
5517 | */ |
5518 | extern SDL_DECLSPEC long SDLCALL SDL_lround(double x); |
5519 | |
5520 | /** |
5521 | * Round `x` to the nearest integer representable as a long |
5522 | * |
5523 | * Rounds `x` to the nearest integer. Values halfway between integers will be |
5524 | * rounded away from zero. |
5525 | * |
5526 | * Domain: `-INF <= x <= INF` |
5527 | * |
5528 | * Range: `MIN_LONG <= y <= MAX_LONG` |
5529 | * |
5530 | * This function operates on single-precision floating point values, use |
5531 | * SDL_lround for double-precision floats. To get the result as a |
5532 | * floating-point type, use SDL_roundf. |
5533 | * |
5534 | * \param x floating point value. |
5535 | * \returns the nearest integer to `x`. |
5536 | * |
5537 | * \threadsafety It is safe to call this function from any thread. |
5538 | * |
5539 | * \since This function is available since SDL 3.2.0. |
5540 | * |
5541 | * \sa SDL_lround |
5542 | * \sa SDL_roundf |
5543 | * \sa SDL_floorf |
5544 | * \sa SDL_ceilf |
5545 | * \sa SDL_truncf |
5546 | */ |
5547 | extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x); |
5548 | |
5549 | /** |
5550 | * Scale `x` by an integer power of two. |
5551 | * |
5552 | * Multiplies `x` by the `n`th power of the floating point radix (always 2). |
5553 | * |
5554 | * Domain: `-INF <= x <= INF`, `n` integer |
5555 | * |
5556 | * Range: `-INF <= y <= INF` |
5557 | * |
5558 | * This function operates on double-precision floating point values, use |
5559 | * SDL_scalbnf for single-precision floats. |
5560 | * |
5561 | * \param x floating point value to be scaled. |
5562 | * \param n integer exponent. |
5563 | * \returns `x * 2^n`. |
5564 | * |
5565 | * \threadsafety It is safe to call this function from any thread. |
5566 | * |
5567 | * \since This function is available since SDL 3.2.0. |
5568 | * |
5569 | * \sa SDL_scalbnf |
5570 | * \sa SDL_pow |
5571 | */ |
5572 | extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n); |
5573 | |
5574 | /** |
5575 | * Scale `x` by an integer power of two. |
5576 | * |
5577 | * Multiplies `x` by the `n`th power of the floating point radix (always 2). |
5578 | * |
5579 | * Domain: `-INF <= x <= INF`, `n` integer |
5580 | * |
5581 | * Range: `-INF <= y <= INF` |
5582 | * |
5583 | * This function operates on single-precision floating point values, use |
5584 | * SDL_scalbn for double-precision floats. |
5585 | * |
5586 | * \param x floating point value to be scaled. |
5587 | * \param n integer exponent. |
5588 | * \returns `x * 2^n`. |
5589 | * |
5590 | * \threadsafety It is safe to call this function from any thread. |
5591 | * |
5592 | * \since This function is available since SDL 3.2.0. |
5593 | * |
5594 | * \sa SDL_scalbn |
5595 | * \sa SDL_powf |
5596 | */ |
5597 | extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n); |
5598 | |
5599 | /** |
5600 | * Compute the sine of `x`. |
5601 | * |
5602 | * Domain: `-INF <= x <= INF` |
5603 | * |
5604 | * Range: `-1 <= y <= 1` |
5605 | * |
5606 | * This function operates on double-precision floating point values, use |
5607 | * SDL_sinf for single-precision floats. |
5608 | * |
5609 | * This function may use a different approximation across different versions, |
5610 | * platforms and configurations. i.e, it can return a different value given |
5611 | * the same input on different machines or operating systems, or if SDL is |
5612 | * updated. |
5613 | * |
5614 | * \param x floating point value, in radians. |
5615 | * \returns sine of `x`. |
5616 | * |
5617 | * \threadsafety It is safe to call this function from any thread. |
5618 | * |
5619 | * \since This function is available since SDL 3.2.0. |
5620 | * |
5621 | * \sa SDL_sinf |
5622 | * \sa SDL_asin |
5623 | * \sa SDL_cos |
5624 | */ |
5625 | extern SDL_DECLSPEC double SDLCALL SDL_sin(double x); |
5626 | |
5627 | /** |
5628 | * Compute the sine of `x`. |
5629 | * |
5630 | * Domain: `-INF <= x <= INF` |
5631 | * |
5632 | * Range: `-1 <= y <= 1` |
5633 | * |
5634 | * This function operates on single-precision floating point values, use |
5635 | * SDL_sin for double-precision floats. |
5636 | * |
5637 | * This function may use a different approximation across different versions, |
5638 | * platforms and configurations. i.e, it can return a different value given |
5639 | * the same input on different machines or operating systems, or if SDL is |
5640 | * updated. |
5641 | * |
5642 | * \param x floating point value, in radians. |
5643 | * \returns sine of `x`. |
5644 | * |
5645 | * \threadsafety It is safe to call this function from any thread. |
5646 | * |
5647 | * \since This function is available since SDL 3.2.0. |
5648 | * |
5649 | * \sa SDL_sin |
5650 | * \sa SDL_asinf |
5651 | * \sa SDL_cosf |
5652 | */ |
5653 | extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x); |
5654 | |
5655 | /** |
5656 | * Compute the square root of `x`. |
5657 | * |
5658 | * Domain: `0 <= x <= INF` |
5659 | * |
5660 | * Range: `0 <= y <= INF` |
5661 | * |
5662 | * This function operates on double-precision floating point values, use |
5663 | * SDL_sqrtf for single-precision floats. |
5664 | * |
5665 | * This function may use a different approximation across different versions, |
5666 | * platforms and configurations. i.e, it can return a different value given |
5667 | * the same input on different machines or operating systems, or if SDL is |
5668 | * updated. |
5669 | * |
5670 | * \param x floating point value. Must be greater than or equal to 0. |
5671 | * \returns square root of `x`. |
5672 | * |
5673 | * \threadsafety It is safe to call this function from any thread. |
5674 | * |
5675 | * \since This function is available since SDL 3.2.0. |
5676 | * |
5677 | * \sa SDL_sqrtf |
5678 | */ |
5679 | extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x); |
5680 | |
5681 | /** |
5682 | * Compute the square root of `x`. |
5683 | * |
5684 | * Domain: `0 <= x <= INF` |
5685 | * |
5686 | * Range: `0 <= y <= INF` |
5687 | * |
5688 | * This function operates on single-precision floating point values, use |
5689 | * SDL_sqrt for double-precision floats. |
5690 | * |
5691 | * This function may use a different approximation across different versions, |
5692 | * platforms and configurations. i.e, it can return a different value given |
5693 | * the same input on different machines or operating systems, or if SDL is |
5694 | * updated. |
5695 | * |
5696 | * \param x floating point value. Must be greater than or equal to 0. |
5697 | * \returns square root of `x`. |
5698 | * |
5699 | * \threadsafety It is safe to call this function from any thread. |
5700 | * |
5701 | * \since This function is available since SDL 3.2.0. |
5702 | * |
5703 | * \sa SDL_sqrt |
5704 | */ |
5705 | extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x); |
5706 | |
5707 | /** |
5708 | * Compute the tangent of `x`. |
5709 | * |
5710 | * Domain: `-INF <= x <= INF` |
5711 | * |
5712 | * Range: `-INF <= y <= INF` |
5713 | * |
5714 | * This function operates on double-precision floating point values, use |
5715 | * SDL_tanf for single-precision floats. |
5716 | * |
5717 | * This function may use a different approximation across different versions, |
5718 | * platforms and configurations. i.e, it can return a different value given |
5719 | * the same input on different machines or operating systems, or if SDL is |
5720 | * updated. |
5721 | * |
5722 | * \param x floating point value, in radians. |
5723 | * \returns tangent of `x`. |
5724 | * |
5725 | * \threadsafety It is safe to call this function from any thread. |
5726 | * |
5727 | * \since This function is available since SDL 3.2.0. |
5728 | * |
5729 | * \sa SDL_tanf |
5730 | * \sa SDL_sin |
5731 | * \sa SDL_cos |
5732 | * \sa SDL_atan |
5733 | * \sa SDL_atan2 |
5734 | */ |
5735 | extern SDL_DECLSPEC double SDLCALL SDL_tan(double x); |
5736 | |
5737 | /** |
5738 | * Compute the tangent of `x`. |
5739 | * |
5740 | * Domain: `-INF <= x <= INF` |
5741 | * |
5742 | * Range: `-INF <= y <= INF` |
5743 | * |
5744 | * This function operates on single-precision floating point values, use |
5745 | * SDL_tan for double-precision floats. |
5746 | * |
5747 | * This function may use a different approximation across different versions, |
5748 | * platforms and configurations. i.e, it can return a different value given |
5749 | * the same input on different machines or operating systems, or if SDL is |
5750 | * updated. |
5751 | * |
5752 | * \param x floating point value, in radians. |
5753 | * \returns tangent of `x`. |
5754 | * |
5755 | * \threadsafety It is safe to call this function from any thread. |
5756 | * |
5757 | * \since This function is available since SDL 3.2.0. |
5758 | * |
5759 | * \sa SDL_tan |
5760 | * \sa SDL_sinf |
5761 | * \sa SDL_cosf |
5762 | * \sa SDL_atanf |
5763 | * \sa SDL_atan2f |
5764 | */ |
5765 | extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x); |
5766 | |
5767 | /** |
5768 | * An opaque handle representing string encoding conversion state. |
5769 | * |
5770 | * \since This datatype is available since SDL 3.2.0. |
5771 | * |
5772 | * \sa SDL_iconv_open |
5773 | */ |
5774 | typedef struct SDL_iconv_data_t *SDL_iconv_t; |
5775 | |
5776 | /** |
5777 | * This function allocates a context for the specified character set |
5778 | * conversion. |
5779 | * |
5780 | * \param tocode The target character encoding, must not be NULL. |
5781 | * \param fromcode The source character encoding, must not be NULL. |
5782 | * \returns a handle that must be freed with SDL_iconv_close, or |
5783 | * SDL_ICONV_ERROR on failure. |
5784 | * |
5785 | * \since This function is available since SDL 3.2.0. |
5786 | * |
5787 | * \sa SDL_iconv |
5788 | * \sa SDL_iconv_close |
5789 | * \sa SDL_iconv_string |
5790 | */ |
5791 | extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, |
5792 | const char *fromcode); |
5793 | |
5794 | /** |
5795 | * This function frees a context used for character set conversion. |
5796 | * |
5797 | * \param cd The character set conversion handle. |
5798 | * \returns 0 on success, or -1 on failure. |
5799 | * |
5800 | * \since This function is available since SDL 3.2.0. |
5801 | * |
5802 | * \sa SDL_iconv |
5803 | * \sa SDL_iconv_open |
5804 | * \sa SDL_iconv_string |
5805 | */ |
5806 | extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); |
5807 | |
5808 | /** |
5809 | * This function converts text between encodings, reading from and writing to |
5810 | * a buffer. |
5811 | * |
5812 | * It returns the number of succesful conversions on success. On error, |
5813 | * SDL_ICONV_E2BIG is returned when the output buffer is too small, or |
5814 | * SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered, |
5815 | * or SDL_ICONV_EINVAL is returned when an incomplete input sequence is |
5816 | * encountered. |
5817 | * |
5818 | * On exit: |
5819 | * |
5820 | * - inbuf will point to the beginning of the next multibyte sequence. On |
5821 | * error, this is the location of the problematic input sequence. On |
5822 | * success, this is the end of the input sequence. |
5823 | * - inbytesleft will be set to the number of bytes left to convert, which |
5824 | * will be 0 on success. |
5825 | * - outbuf will point to the location where to store the next output byte. |
5826 | * - outbytesleft will be set to the number of bytes left in the output |
5827 | * buffer. |
5828 | * |
5829 | * \param cd The character set conversion context, created in |
5830 | * SDL_iconv_open(). |
5831 | * \param inbuf Address of variable that points to the first character of the |
5832 | * input sequence. |
5833 | * \param inbytesleft The number of bytes in the input buffer. |
5834 | * \param outbuf Address of variable that points to the output buffer. |
5835 | * \param outbytesleft The number of bytes in the output buffer. |
5836 | * \returns the number of conversions on success, or a negative error code. |
5837 | * |
5838 | * \since This function is available since SDL 3.2.0. |
5839 | * |
5840 | * \sa SDL_iconv_open |
5841 | * \sa SDL_iconv_close |
5842 | * \sa SDL_iconv_string |
5843 | */ |
5844 | extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, |
5845 | size_t *inbytesleft, char **outbuf, |
5846 | size_t *outbytesleft); |
5847 | |
5848 | #define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */ |
5849 | #define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */ |
5850 | #define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */ |
5851 | #define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */ |
5852 | |
5853 | |
5854 | /** |
5855 | * Helper function to convert a string's encoding in one call. |
5856 | * |
5857 | * This function converts a buffer or string between encodings in one pass. |
5858 | * |
5859 | * The string does not need to be NULL-terminated; this function operates on |
5860 | * the number of bytes specified in `inbytesleft` whether there is a NULL |
5861 | * character anywhere in the buffer. |
5862 | * |
5863 | * The returned string is owned by the caller, and should be passed to |
5864 | * SDL_free when no longer needed. |
5865 | * |
5866 | * \param tocode the character encoding of the output string. Examples are |
5867 | * "UTF-8", "UCS-4", etc. |
5868 | * \param fromcode the character encoding of data in `inbuf`. |
5869 | * \param inbuf the string to convert to a different encoding. |
5870 | * \param inbytesleft the size of the input string _in bytes_. |
5871 | * \returns a new string, converted to the new encoding, or NULL on error. |
5872 | * |
5873 | * \since This function is available since SDL 3.2.0. |
5874 | * |
5875 | * \sa SDL_iconv_open |
5876 | * \sa SDL_iconv_close |
5877 | * \sa SDL_iconv |
5878 | */ |
5879 | extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, |
5880 | const char *fromcode, |
5881 | const char *inbuf, |
5882 | size_t inbytesleft); |
5883 | |
5884 | /* Some helper macros for common SDL_iconv_string cases... */ |
5885 | |
5886 | /** |
5887 | * Convert a UTF-8 string to the current locale's character encoding. |
5888 | * |
5889 | * This is a helper macro that might be more clear than calling |
5890 | * SDL_iconv_string directly. However, it double-evaluates its parameter, so |
5891 | * do not use an expression with side-effects here. |
5892 | * |
5893 | * \param S the string to convert. |
5894 | * \returns a new string, converted to the new encoding, or NULL on error. |
5895 | * |
5896 | * \since This macro is available since SDL 3.2.0. |
5897 | */ |
5898 | #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1) |
5899 | |
5900 | /** |
5901 | * Convert a UTF-8 string to UCS-2. |
5902 | * |
5903 | * This is a helper macro that might be more clear than calling |
5904 | * SDL_iconv_string directly. However, it double-evaluates its parameter, so |
5905 | * do not use an expression with side-effects here. |
5906 | * |
5907 | * \param S the string to convert. |
5908 | * \returns a new string, converted to the new encoding, or NULL on error. |
5909 | * |
5910 | * \since This macro is available since SDL 3.2.0. |
5911 | */ |
5912 | #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1) |
5913 | |
5914 | /** |
5915 | * Convert a UTF-8 string to UCS-4. |
5916 | * |
5917 | * This is a helper macro that might be more clear than calling |
5918 | * SDL_iconv_string directly. However, it double-evaluates its parameter, so |
5919 | * do not use an expression with side-effects here. |
5920 | * |
5921 | * \param S the string to convert. |
5922 | * \returns a new string, converted to the new encoding, or NULL on error. |
5923 | * |
5924 | * \since This macro is available since SDL 3.2.0. |
5925 | */ |
5926 | #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1) |
5927 | |
5928 | /** |
5929 | * Convert a wchar_t string to UTF-8. |
5930 | * |
5931 | * This is a helper macro that might be more clear than calling |
5932 | * SDL_iconv_string directly. However, it double-evaluates its parameter, so |
5933 | * do not use an expression with side-effects here. |
5934 | * |
5935 | * \param S the string to convert. |
5936 | * \returns a new string, converted to the new encoding, or NULL on error. |
5937 | * |
5938 | * \since This macro is available since SDL 3.2.0. |
5939 | */ |
5940 | #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t)) |
5941 | |
5942 | |
5943 | /* force builds using Clang's static analysis tools to use literal C runtime |
5944 | here, since there are possibly tests that are ineffective otherwise. */ |
5945 | #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) |
5946 | |
5947 | /* The analyzer knows about strlcpy even when the system doesn't provide it */ |
5948 | #if !defined(HAVE_STRLCPY) && !defined(strlcpy) |
5949 | size_t strlcpy(char *dst, const char *src, size_t size); |
5950 | #endif |
5951 | |
5952 | /* The analyzer knows about strlcat even when the system doesn't provide it */ |
5953 | #if !defined(HAVE_STRLCAT) && !defined(strlcat) |
5954 | size_t strlcat(char *dst, const char *src, size_t size); |
5955 | #endif |
5956 | |
5957 | #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy) |
5958 | size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size); |
5959 | #endif |
5960 | |
5961 | #if !defined(HAVE_WCSLCAT) && !defined(wcslcat) |
5962 | size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size); |
5963 | #endif |
5964 | |
5965 | /* strdup is not ANSI but POSIX, and its prototype might be hidden... */ |
5966 | char *strdup(const char *str); |
5967 | |
5968 | /* Starting LLVM 16, the analyser errors out if these functions do not have |
5969 | their prototype defined (clang-diagnostic-implicit-function-declaration) */ |
5970 | #include <stdio.h> |
5971 | #include <stdlib.h> |
5972 | |
5973 | #define SDL_malloc malloc |
5974 | #define SDL_calloc calloc |
5975 | #define SDL_realloc realloc |
5976 | #define SDL_free free |
5977 | #ifndef SDL_memcpy |
5978 | #define SDL_memcpy memcpy |
5979 | #endif |
5980 | #ifndef SDL_memmove |
5981 | #define SDL_memmove memmove |
5982 | #endif |
5983 | #ifndef SDL_memset |
5984 | #define SDL_memset memset |
5985 | #endif |
5986 | #define SDL_memcmp memcmp |
5987 | #define SDL_strlcpy strlcpy |
5988 | #define SDL_strlcat strlcat |
5989 | #define SDL_strlen strlen |
5990 | #define SDL_wcslen wcslen |
5991 | #define SDL_wcslcpy wcslcpy |
5992 | #define SDL_wcslcat wcslcat |
5993 | #define SDL_strdup strdup |
5994 | #define SDL_wcsdup wcsdup |
5995 | #define SDL_strchr strchr |
5996 | #define SDL_strrchr strrchr |
5997 | #define SDL_strstr strstr |
5998 | #define SDL_wcsstr wcsstr |
5999 | #define SDL_strtok_r strtok_r |
6000 | #define SDL_strcmp strcmp |
6001 | #define SDL_wcscmp wcscmp |
6002 | #define SDL_strncmp strncmp |
6003 | #define SDL_wcsncmp wcsncmp |
6004 | #define SDL_strcasecmp strcasecmp |
6005 | #define SDL_strncasecmp strncasecmp |
6006 | #define SDL_strpbrk strpbrk |
6007 | #define SDL_sscanf sscanf |
6008 | #define SDL_vsscanf vsscanf |
6009 | #define SDL_snprintf snprintf |
6010 | #define SDL_vsnprintf vsnprintf |
6011 | #endif |
6012 | |
6013 | /** |
6014 | * Multiply two integers, checking for overflow. |
6015 | * |
6016 | * If `a * b` would overflow, return false. |
6017 | * |
6018 | * Otherwise store `a * b` via ret and return true. |
6019 | * |
6020 | * \param a the multiplicand. |
6021 | * \param b the multiplier. |
6022 | * \param ret on non-overflow output, stores the multiplication result, may |
6023 | * not be NULL. |
6024 | * \returns false on overflow, true if result is multiplied without overflow. |
6025 | * |
6026 | * \threadsafety It is safe to call this function from any thread. |
6027 | * |
6028 | * \since This function is available since SDL 3.2.0. |
6029 | */ |
6030 | SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret) |
6031 | { |
6032 | if (a != 0 && b > SDL_SIZE_MAX / a) { |
6033 | return false; |
6034 | } |
6035 | *ret = a * b; |
6036 | return true; |
6037 | } |
6038 | |
6039 | #ifndef SDL_WIKI_DOCUMENTATION_SECTION |
6040 | #if SDL_HAS_BUILTIN(__builtin_mul_overflow) |
6041 | /* This needs to be wrapped in an inline rather than being a direct #define, |
6042 | * because __builtin_mul_overflow() is type-generic, but we want to be |
6043 | * consistent about interpreting a and b as size_t. */ |
6044 | SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret) |
6045 | { |
6046 | return (__builtin_mul_overflow(a, b, ret) == 0); |
6047 | } |
6048 | #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret) |
6049 | #endif |
6050 | #endif |
6051 | |
6052 | /** |
6053 | * Add two integers, checking for overflow. |
6054 | * |
6055 | * If `a + b` would overflow, return false. |
6056 | * |
6057 | * Otherwise store `a + b` via ret and return true. |
6058 | * |
6059 | * \param a the first addend. |
6060 | * \param b the second addend. |
6061 | * \param ret on non-overflow output, stores the addition result, may not be |
6062 | * NULL. |
6063 | * \returns false on overflow, true if result is added without overflow. |
6064 | * |
6065 | * \threadsafety It is safe to call this function from any thread. |
6066 | * |
6067 | * \since This function is available since SDL 3.2.0. |
6068 | */ |
6069 | SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret) |
6070 | { |
6071 | if (b > SDL_SIZE_MAX - a) { |
6072 | return false; |
6073 | } |
6074 | *ret = a + b; |
6075 | return true; |
6076 | } |
6077 | |
6078 | #ifndef SDL_WIKI_DOCUMENTATION_SECTION |
6079 | #if SDL_HAS_BUILTIN(__builtin_add_overflow) |
6080 | /* This needs to be wrapped in an inline rather than being a direct #define, |
6081 | * the same as the call to __builtin_mul_overflow() above. */ |
6082 | SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret) |
6083 | { |
6084 | return (__builtin_add_overflow(a, b, ret) == 0); |
6085 | } |
6086 | #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret) |
6087 | #endif |
6088 | #endif |
6089 | |
6090 | /* This is a generic function pointer which should be cast to the type you expect */ |
6091 | #ifdef SDL_WIKI_DOCUMENTATION_SECTION |
6092 | |
6093 | /** |
6094 | * A generic function pointer. |
6095 | * |
6096 | * In theory, generic function pointers should use this, instead of `void *`, |
6097 | * since some platforms could treat code addresses differently than data |
6098 | * addresses. Although in current times no popular platforms make this |
6099 | * distinction, it is more correct and portable to use the correct type for a |
6100 | * generic pointer. |
6101 | * |
6102 | * If for some reason you need to force this typedef to be an actual `void *`, |
6103 | * perhaps to work around a compiler or existing code, you can define |
6104 | * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers. |
6105 | * |
6106 | * \since This datatype is available since SDL 3.2.0. |
6107 | */ |
6108 | typedef void (*SDL_FunctionPointer)(void); |
6109 | #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER) |
6110 | typedef void *SDL_FunctionPointer; |
6111 | #else |
6112 | typedef void (*SDL_FunctionPointer)(void); |
6113 | #endif |
6114 | |
6115 | /* Ends C function definitions when using C++ */ |
6116 | #ifdef __cplusplus |
6117 | } |
6118 | #endif |
6119 | #include <SDL3/SDL_close_code.h> |
6120 | |
6121 | #endif /* SDL_stdinc_h_ */ |
6122 | |