Files
kaizen/include/SDL3/SDL_stdinc.h
Simone 51245fc0c5 Squashed 'external/SDL/' changes from b736285053..8ec576ddab
8ec576ddab tray, windows: fix logic error from commit 1167cf54e1572
748f0b3201 Improved Steam Controller detection on iOS
ba1a980535 wayland: Only apply the toplevel bounds when initially mapping the window
28389f1c38 wayland: Apply toplevel bounds to windows
ef52a4d4df Fixed warning C4389: '==': signed/unsigned mismatch
8d8649b33f Fixed error: returning 'SDL_TrayEntry **' from a function with incompatible return type 'const SDL_TrayEntry **'
f8b13dadd7 Enabled warning level 4 on Visual Studio
1167cf54e1 Fixed warning C4706: assignment within conditional expression
8a9b7ae8d1 Switched nEntries to int, to avoid signed/unsigned comparison warnings
fb4ec07119 Fixed warning C4701: potentially uninitialized local variable 'previous_context' used
b674b715f5 fix integer overflow ub in testautomation_sdltest
1e1442ed4a README-migration.md: Note the GL/EGL library environment variable removals.
d8c7006a42 README-migration.md: Removed obsolete documentation.
6473de59b7 SDL_keyboard.h: Note that SDL_GetKeyName() returns uppercase letters.
c7584df999 Sync SDL3 wiki -> header
1f54b228ff video: Convert some EGL environment variables to SDL hints.
7c9f6c6313 Remove debug logging
19ddb29d2d Sync SDL3 wiki -> header
d16f76e3d4 wasapi: Don't crash/hang if transitioning to/from a Remote Desktop Connection.
742f2a2fad SDL_render.h: Improve SDL_ConvertEventToRenderCoordinates documentation.
2b375d9704 wayland: Don't enable the text-input protocol when using Fcitx
dcc645e413 Fix HTML examples template tabs
ece6a6ed8f Sync SDL3 wiki -> header
7f9ee31024 include: Fill in more category documentation.
16ad3e5af6 cmake: consider X11 as not available when xext.h is not found
0ae57f1d90 tray: unix: Shutdown the GTK thread when not in use
6a0405b933 testautomation: Added a test to stdlib_swprintf that previously would fail.
9f2186ad52 Removed outdated comment in AndroidManifest.xml
181995b44f stdlib: Reworked SDL_vswprintf to be more efficient and return correct values.
8509041a09 video: Fix SDL_GL_GetAttribute depth/stencil size when 0
344e394bf4 camera: Favor v4l2 over pipewire, for now.
d8c679416b Sync SDL3 wiki -> header
b6dc44b133 Support dark theme for tray menus on Windows
7673b84f52 Make SDL_GetTrayEntires() NULL-terminated
a58bc3eaf4 [GPU] Fix crash in nvidia user-mode win32 driver when game window is minimized during swapchain resize (#11848)
0a5d2f3da2 Handle pen eraser button as a second button
3519ef3b3b SDL_asyncio.h: Fixed various datatype's `\since` documentation.
56d7cc7a02 SDL_video.h: Added a note about platform quirks to SDL_DestroyWindow docs.
04f3bdb118 Sync SDL3 wiki -> header
18c6958cae SDL_vulkan.h: Improve SDL_Vulkan_LoadLibrary/SDL_Vulkan_UnloadLibrary docs.
522682cd6e Add detailed documentation on building with MinGW64 (#11780)
a4cd17cce5 Fixed building on macOS with the dialog subsystem disabled
efba42a67b tests: avoid undefined signed overflow
156b3b4a8c Fixed language detection on iOS
53aaf8c26b cmake: custom generate-XXX targets must depend on outputs
9b40d43b1f Sync SDL3 wiki -> header
85851459d6 docs: Note that using the Wayland display scaling mode can have imprecision when positioning due to unit conversion and rounding
db97da4ccb ci: bump FreeBSD to 14.2
5579010b6a wayland: Adjust the scaled popup position even if the dimensions didn't change
2d37903323 pen: implement pen support for Windows.
ef21ccf080 Create a separate metal shader for NV12 textures
49663bfb58 Make Windows dialogs DPI aware
a8c41135aa Enable themed Windows dialogs when building with Visual Studio
8b83a57847 Check that dll's built by MinGW do not link to unwanted runtime libraries
e484182765 testcamera: Log the camera backend in use.
011454b237 Sync SDL3 wiki -> header
efc390d7e2 Don't log SDL errors by default
c077b7a918 Fixed the version availability of SDL_HINT_JOYSTICK_ENHANCED_REPORTS
0b520cd4b4 Sync SDL3 wiki -> header
9f7b2c3595 Fixed incorrect error message when a joystick can't be opened
2c0a8363a5 Added SDL_HINT_JOYSTICK_ENHANCED_REPORTS
95d44f11c7 Sync SDL3 wiki -> header
16dfaca728 Sync SDL3 wiki -> header
32ab09ba21 Sync SDL3 wiki -> header
1461f893c3 video: Correct the window position property documentation
a63052db96 Sync SDL3 wiki -> header
dd6b484359 Document platform gamepad hotplug requirements
ecf8dd054d Show the display content scale in SDLTest_CommonDrawWindowInfo()
4797970bfa Enable SDL_HINT_JOYSTICK_THREAD by default
6b4b9b5f2b Improved XInput controller detection
8ea4b326b3 video: Fix focus when non-focused popup windows are hidden
67ea67f191 Fix mip generation for 2x1 textures on D3D12
c6b5c21aaf clipboard: Ensure SDL_ClearClipboardData clears data even when no data has been set
f8f8d87bfa ci: always create binary packages if build succeeded
b713e7581b stdlib: fix SDL_strtol of "0" with base 0
54752f8d1c SDL_malloc.c: replace FORCEINLINE usage with SDL_FORCE_INLINE
3842384a38 dynapi: trigger a breakpoint on a fatal error when SDL is built in debug mode
6cf6b160cd SDL_hashtable: don't use assert from libc
62bc2c4c92 SDL_malloc: don't define FORCEINLINE
4fccfb142e cmake: avoid security cookies in SDL_uclibc when building with -DSDL_LIBC=ON
4fbf59ac3a Implement __chkstk for arm64
578ac0ef52 SDL_malloc: disable malloc stats
31a4c92ee5 When building with libc enabled, we don't need to provide __chkstk ourselves
02e85a153f Use the expected plane size when capturing Android camera frames
9955e1dc0d Updated the Android gradle plugin to version 8.7.3
0281071243 Lock joysticks when they are connected/disconnected on emscripten
c68ed04a06 Sync SDL3 wiki -> header
2b1d809b21 video: Fix positioning and focusing popups parented to child toplevel windows
6d554a9ea3 Sync SDL3 wiki -> header
9fbc767d4f Fixed formatting of SDL_storage documentation
e43aa12b49 Updated copyright for 2025
c0e5901c42 Reverted accidentally committed work in progress
f2074d7af3 Updated copyright for 2025
3197e27b59 testcamera: fixed return codes
f18e023317 Added testclipboard
54d4e48539 Get the initial clipboard state at startup
6575b8157b Synchronize clipboard mime types with external clipboard updates
30a22d3fed Allow a NULL size parameter to retrieve null terminated text
d666c2d189 Use a consistent error message when video isn't initialized
196e2c6662 Fixed crash if num_mime_types is NULL
b902b0527b Renamed n_mime_types to num_mime_types
a767952617 Fixed spacing
54c555e394 Send supported mime types for external clipboard contents on Windows
8b155708ff Fixed clipboard memory leak on shutdown
1d417ab27f win32: Set the WS_THICKFRAME style on popup windows
643281d022 Revert "win32: Use the size in the WINDOWPOS data while handling popup windows in the WM_WINDOWPOSCHANGED message"
2be89f0dd1 Clarify migration for GetWindowData and SetWindowData
a37f993a07 Sync SDL3 wiki -> header
65e0fed5b3 gpu: Document why VertexID/InstanceID builtins are unreliable
dd83908109 keyboard: Check for both caps lock and shift when looking up a keycode by name
99ad53ec3f Sync SDL3 wiki -> header
df97ccf283 win32: Return 0 from WM_WINDOWPOSCHANGING if a resize is expected
4f0a056b95 win32: Use the size in the WINDOWPOS data while handling popup windows in the WM_WINDOWPOSCHANGED message
18fc13c20d Sync SDL3 wiki -> header
6d20b65a9e Sync SDL3 wiki -> header
3cd3c9317e storage: Add error messages when ReadIO/WriteIO lengths mismatch
6ca2a48595 Sync SDL3 wiki -> header
fa9c3331d5 main: Adjust how SDL_HINT_MAIN_CALLBACK_RATE works.
cd1bd0ac2e storage: Remove an outdated FIXME.
0be5b8070d Update SDL_asyncio.c
1c04ebe423 Renamed SDL_ASYNCIO_CANCELLED to SDL_ASYNCIO_CANCELED
d4d5faedab Added SDL_EVENT_FINGER_CANCELED
8704ab8422 Wait for a display resize event before sending orientation changes
60deaf5f0f Send display mode change events when the orientation changes
5340f2e3fe Updated to the latest version of gradle, with support for Android SDK 35
e91c37f4dd Added support for inset handling on Android 15
f3cbd04a81 Fix C99 trailing enum comma warning.
5f25691c85 Fix C23 empty initializer warning.
8cc4735d74 wayland: Don't override the min/max values when scaling to the screen
2d91f096ca Remove libc function from Windows tray
78c1dc3e2c Sync SDL3 wiki -> header
0410328b15 Fixed warning: ordered comparison of pointer with integer zero
d5f08b8f4b stdinc: use __has_include to detect <stdbool.h>
543f244965 tests: include SDL_build_config.h when HAVE_BUILD_CONFIG is defined
c2121dd9a2 testcamera: fix MSVC build failure due to C4244 warning.
5c84d38822 testcamera: don't pick a frame size larger than the maximum texture size
6e1177ac03 Include tray function prototypes
c030e6f782 examples/pen/01-drawing-lines: Match render target size to renderer output.
0ad3a18937 uikit: reworked Apple Pencil code.
f6143da617 uikit: Patched to compile, added to Xcode project.
774e38d073 uikit: Initial Apple Pencil support.
5acd7fe208 wayland: Prevent popup configure events from overwriting the current size with old data
c714b1a38b Fixed public header inclusion in the Xcode project
cf439d5c63 Fix dib-to-bmp logic in SDL_windowsclipboard.c
ec29d3fd66 Define NDEBUG in release Xcode builds
92b7054870 Add SDL_tray.h to the public framework headers
1a466b5548 Sync SDL3 wiki -> header
ec8a780ad4 tray, unix: fix -Wformat warnings
cc723c9e4b ci: run emscripten on Ubuntu 22.04
0cb4a94c88 cmake: really disable xrandr by default on Solaris
4ffcb8ebab Sync SDL3 wiki -> header
49153ebfc4 audio: Add NULL check to SDL_UnbindAudioStreams
1b99467c71 audio: Make SDL_Bind/UnbindAudioStreams take const arrays
0be6dc5734 cmake: disable xrandr by default on Solaris
4fbd6cba60 cmake: Solaris' SunPro has alternative way to link to pthread libraries
e25cc7a88f cmake: cocoa video backend needs IOKit framework
38dd6bcd32 docs: gradle needs package identifier + change example Activity class path
f1232de3d2 cmake: add_dependencies must have at least 2 arguments
2664d36faf cmake: avoid parallel generation of headers through intermediate target
609b147432 Sync SDL3 wiki -> header
cc24518c41 render: Update GPU backend to use the new present workflow
a0e537b9c0 examples: Fix dead links in app metadata
df1f1c2e12 cmake: don't create relocatable packages by default with non-MSVC toolchains
af3d97dcac Update build-scripts/build-release.py
bc448fa445 win32: Use the nearest monitor size for calculating maximized window dimensions
599b4ef254 win32: Fix maximizing borderless windows
1c52e290a3 video: Don't overwrite pending size values when setting the window min/max
9a4d29699d Don't use connection state from the Nintendo Switch Pro report
75a24116b5 testcontroller: show gamepad connection state
22f6eed1d9 Use the NVIDIA Shield home button as the guide button
c148837546 Added a Bluetooth mapping for the NVIDIA Shield Controller on Linux
82a1e9f6df Fixed the guide button for the NVIDIA Shield Controller on Linux
ba5cf2b152 x11: Don't overwrite popup window coordinates when changing the size
567b828e18 wayland: Use the proper popup coordinates if the position is set while the window is hidden
1701208f32 Sync SDL3 wiki -> header
622c3ebb94 Updated Xcode project with new tray files
0461180e25 SDL_EVENT_QUIT when no window nor tray
ff139fe71b Sync SDL3 wiki -> header
e9290eeedf Use `pthread_setname_np` also on Android
578509c326 windows/SDL_tray.c, video/windows/SDL_surface_utils.h: use SDL_windows.h
05932e05da tray, windows: replace ZeroMemory() with SDL_zero()
e2323c1367 Refactor Android input handling and add pen support
f5fbdf7ed5 Make onNativePen available for Android
a5e8fc21b2 Add SDL_androidpen
80c39f2ff4 Expose SDL_GetPenStatus for Android pen buttons
e3c99e3bd3 misc: Fixed typo in iOS error message.
1413bfb185 Don't overwrite non-CRC gamepad mapping with a new mapping that specifies a CRC
948b16533c testcamera: use the first available cameras
cd1bb6247b video/windows/SDL_surface_utils.c: replace ZeroMemory() with SDL_zero()
a773558517 Sync SDL3 wiki -> header
50fbae9302 tray, windows: define NOTIFYICON_VERSION_4 and NIF_SHOWTIP, if missing.
c744c8fc0b Document how to check for gamepad capabilities
a8d585aac3 Don't try to enumerate possible texture failure reasons.
ca17d19f90 Updated iOS file path documentation
7bbe6025be misc: Make SDL_OpenURL work with VisionOS, tvOS, etc.
ffed1c50c0 misc: Fix SDL_OpenURL on newer iOS releases.
1a6e139dde win32: Only recalculate the position on show for popup windows
cf220ea4f1 win32: Fix popup positioning
17ef0c1237 SDL_video.c: replace strlcpy with memcpy in SDL_ShowMessageBox()
8fde28813e SDL_tray.h: Filled in doxygen for a few minor missing things.
17df3fe836 Sync SDL3 wiki -> header
eb1be89e70 Cleaned up thread state handling and added thread object validation
7647f16ae1 Sync SDL3 wiki -> header
eadc64973a Reset text field content on text input stop
b2c2a483e8 GPU: Rename HDR10_ST2048 to HDR10_ST2084
fe39509b85 GPU: Doc touch ups
b8036bdd41 Sync SDL3 wiki -> header
ca4f5dd40d Added SDL_GetThreadState
b7dac5072b correct termination of windows openfiledialog filters
0becdad392 Add missing includes to SDL_tray.h
5bf742daa6 Fix documentation for SDL_sinf
bed16f77d1 cmake: define HAVE_MALLOC_H when malloc.h is found
b2178857dc Corrected CoreAudio surround sound channel layouts
f40a530fd9 subclass the builtin system message class instead
cf946e32ba Fix memory management for Windows dialog title
4c70aa33ae Sync SDL3 wiki -> header
76920a230f Fixed Xcode build
01b9b0edb7 Add system tray support (#10873)
17a029502a Sync SDL3 wiki -> header
a27c139b12 GPU: Explicitly check Metal hardware support on device creation
aa817a67d1 GPU: Document system requirements for each driver
8653a5821b Fixed mingw64 Windows build
60dce94583 Fixed building with older Windows SDKs
440d5754f8 build_configs: remove unused symbols_to_check, added Windows ones
052cb5773e build_configs: remove `HAVE_LIBUNWIND_H`
42c67756cc build_configs: fix spacing
286cc2ebd0 build_config: change unnecessary replacement variables to 1
c2508d5d99 Fix various `#if defined`s
f2b7495adc SDL_camera_pipewire: use `SDL_CAMERA_DRIVER_PIPEWIRE_DYNAMIC`
ade829d7ca build_config: fix `SDL_DEFAULT_ASSERT_LEVEL`
e73d98ad72 build_config: add missing macros
7f1c9c9053 build_config: move unconditionally defined macros
6f462e244f build_config: remove unused `SIZEOF_VOIDP`
ddd7d0f927 build_configs: remove unused macros
483e79bf82 Fixed mouse click count for relative mode and multiple mice
ed75d9d22a Document that the mouse ID is only valid in mouse relative mode
024e5da6fb Mouse events only get a mouse ID in relative mode
8a0f649363 windows: fix BITMAPINFOHEADER values when getting bitmap from Clipboard
af2dbbcb53 Merge SDL_wasapi_win32 into SDL_wasapi
4d301b88d6 Sync SDL3 wiki -> header
5a2eb60389 Only save the pending flags we will restore when hiding a window
969f03d9f0 Added SDL_PROP_RENDERER_GPU_DEVICE_POINTER
7a22076a7c Sync SDL3 wiki -> header
3a1810f9a9 Fixed the Linux mapping for the NVIDIA Controller v1.03
49610fd1e8 Leave mouse relative mode when losing focus
62124e2c28 GPU: Enable Metal validation in debug mode (#11691)
18115ef6bd Sync SDL3 wiki -> header
8691408baf Clarify that you shouldn't make any assumptions about the an SDL_FingerID value.
37b87f79fb Fixed Bluetooth Steam Controller detection on iOS and Android
9a43c08146 Allow rendering during the modal resize loop on macOS
225c0e2ad9 Removed unused function declaration
4add7e2005 Round the window size values when using fixed aspect ratio
3ac28bae6a Removed references to non-existent method SDL_GetAsyncIOTaskResult
da37e1541b Sync SDL3 wiki -> header
ecea3471f6 Sync SDL3 wiki -> header
f8d8bf8066 SDL_GetNumAllocations returns -1 when allocation counting is disabled
a33144fbc9 SDL_test: disable memory tracking if SDL does not count allocations
2e4dc9c109 Disable tracking memory allocation counts by default
80c1b1e1a0 Fix testautomation pixels_saveLoadBMP big endian issue
478ac0b9bf Sync SDL3 wiki -> header
03d6e4b69e Sync SDL3 wiki -> header
ca4ffc8a00 Fix missing parens in preprocessor defined op
8475c496b4 Fix typo
56cf8d8dc9 Sync SDL3 wiki -> header
f0fad41f2c include: Filled in all remaining missing documentation!
4d8f5758cf Sync SDL3 wiki -> header
c080bb8417 GPU: Fix non-triangle D3D12 primitive topology types
33442701ca Use the monitor as the client rect for maximized borderless windows
7e298f50fe Make windows resizable if we're about to maximize them programmatically
34974d4d2b Don't remove the resizable style for borderless windows
cadeec9cc9 SDL_SoftStretch() doesn't handle large pixel formats
f37eef948c Removed raw mouse events
d07bb0e679 Removed raw key events
c44fa5bb07 Updated raw input events to match SDL style
1025087c2e Sync SDL3 wiki -> header
a47b62d1fe Removed PS2 compiler definition
f3c194f39a Remove EXTRA_CFLAGS.
7e8576fd19 gpu: Xbox fixes for swapchain presentation
f7580374a1 include: Always declare SDL_GDKSuspendComplete.
232c2970d3 Sync SDL3 wiki -> header
5ec5f23fff tests: Print accurate enabled/disabled relative mode status in testrelative
b815123cf2 Sync SDL3 wiki -> header
819e1cc95b SDL_stdinc.h: A couple wikiheaders fixes.
b2eb23a617 SDL_filesystem.h: Fill in missing documentation.
0b401137d2 SDL_stdinc.h: Document more stuff.
b83dd793fd SDL_stdinc.h: Tons of documentation updates.
a0864799f2 GDK: Fix compile_shaders_xbox.bat build events
5d9ccb6296 gpu: Add explicit casts to D3D12 staging descriptor changes
e992522cb2 Xbox buildfixes for WarpCursor jitter fix, dark mode
b2c15a8c2a Sync SDL3 wiki -> header
0f9e86fe1c tests: Fix GPU tests crashing when window is minimized
c9e22d4672 Sync SDL3 wiki -> header
ff366fba87 include: Move SDL_HAS_BUILTIN to SDL_begin_code.h, document it.
e46d8756e5 tests: Update GPU tests to use new swapchain best practice
401c8f8e4e SDL_timer.h: Fixed doxygen typo.
2f9a45af60 Sync SDL3 wiki -> header
0c42891826 include: Filled in more documentation gaps.
3ce68f80bc wayland: Clean up the relative pointer if the seat capability is removed
7c8171da92 wayland: Handle the relative pointer manager appearing after the seat has been initialized
4bfc8f84f7 tests: Add a raw event mode to testrelative
8c849ecc6c wayland: Add support for the MOUSE_RAW_* events
fce922b66c wayland: Add support for the SDL_MOUSE_RELATIVE_SYSTEM_SCALE hint
d6a95ae198 Sync SDL3 wiki -> header
42de2ac6a9 Fixed typo
e08f34c3be Removed SDL_HINT_MOUSE_RELATIVE_MODE_WARP
6e0df0af24 Reduce the possibility of SDL_LockMutex getting called on a destroyed mutex after SDL_StopEventLoop
519923ea80 Sync SDL3 wiki -> header
624a4d5f26 include: Documented important SDL_begin_code symbols.
5c0f8dc179 add alternate raw mouse motion events with windows implementation (#10042)
345cab1e36 streamline cursor clipping logic on windows (#11237)
35a9d156a6 render: convert tmotion vectors to render basis
3739749404 Improve Win32 darkmode and fix title bar's context menu (#11543)
10f868abf4 Sync SDL3 wiki -> header
f81472d767 Document that you should read from processes before waiting for them to exit.
3001c61de0 x11: Use the master pointer device for absolute motion
835b6e0c1a Enable high refresh rates on iOS
da80b9bce5 Fixed an inaccuracy in the documentation for SDL_ConvertPixelsAndColorspace
2ce21d1fed Fixed an inaccuracy in the documentation for SDL_CancelGPUCommandBuffer
0ca8027205 Fixed an inaccuracy in the documentation for SDL_PenProximityEvent and SDL_PenMotionEvent
4d9e7a2a68 Sync SDL3 wiki -> header
b5eea03d1e GPU: Clarify presentation concerns in SDL_gpu.h
7dd523fbb1 Sync SDL3 wiki -> header
48a0adb2ac Sync SDL3 wiki -> header
4d4a2786bb render: Updates to format-string versions of SDL_RenderDebugText.
6abebca943 Fix format string in debug-text example
1d0e28a5b3 Add SDL_RenderDebugTextF & SDL_RenderDebugTextV
5608bf5866 Sync SDL3 wiki -> header
0fbcd0d586 GPU: Optimize usage of D3D12 staging descriptors (#11657)
e957840d34 include: Filling in some more documentation gaps.
684098fac3 Fix possible bug with Windows dialogs
bc9c86bcc2 Dialog: Add suffix to filters all the time
b58e6d7274 .wikiheaders-options: Include CPU intrinsics macros in quick reference.
c9ab8ad8d9 SDL_intrin.h: Added missing NEON and Altivec documentation.
d38c09e5c4 Sync SDL3 wiki -> header
6730cf7bed SDL_intrin.h: Add documentation.
2f68efda83 wikiheaders: Add underscore to the "big ascii" character table.
19bdc01b8c Sync SDL3 wiki -> header
eda0261c4e video: Drop size and position requests for windows in a fixed size/position state
6fa6297441 fix typo from commit b84f150d0669592f
b84f150d06 fix macOS builds with hidapi disabled
c52a96ca8e Sync SDL3 wiki -> header
080b3002c6 Fixed building with an older Windows SDK
d0d1414836 messagebox: Copy title and message up front, to protect SDL_GetError() strings.
a92eade183 Sync SDL3 wiki -> header
0bb42cb023 alsa: a few more minor formatting tweaks.
483ceb5355 alsa: Reenable SDL's internal channel map support when ALSA can't swizzle.
35360ec4d7 alsa: Use more hints for opening default devices.
576f13ac7c alsa: Put debug logging back into correct category and logging level.
ff96c59df4 alsa: Add back in code to guess the correct ALSA device prefix.
b108b54c6a alsa: Bring up to current SDL coding conventions and standards, other tweaks.
639855b7e5 alsa: Remove direct calls to memset
a4a1dff219 alsa: remove `loop` macro
b9c062c858 alsa: Pulled in latest changes from @sylware
76e7bc4c04 Added support for ALSA dmix audio output (thanks @sylware!)
3fa0537565 Sync SDL3 wiki -> header
79316ca36e Heavy work on improving category documentation.
9aca97f4e7 Sync SDL3 wiki -> header
c0803f7683 SDL_dialog.h: Improvements and fixes to the documentation.
a55686ce61 hints: Clarify when joystick hints should be set.
eb3fc0684c wayland: Don't close an externally owned display on init failure
6cc9ce183d SDL_internal: remove `#undef SDL_LEAN_AND_MEAN`
8b6d3c88cf Fix `#ifdef`s to have config flags either defined as 1 or undefined
313d522f39 wayland: Only require fifo-v1 for Wayland by default
ac2edad809 audio: Simplify and unify audio stream format updating when devices change.
9a9616894d wikiheaders: Fix uninitialized variable issue.
9628549c7c Xbox buildfixes
80b9986418 audio: Fixed potential NULL dereference.
1944bc7407 Fixed warning C4702: unreachable code
63a498c966 Fixed warning C4189: 'cqe': local variable is initialized but not referenced
ce9dddfde2 Don't free properties while modifying the property hashtable
43a61fec91 Removed external hashtable locking functions
61511c48a4 SDL_HashTable is now optionally thread-safe
e0cee83a3a emscriptenaudio: Removed comment about Firefox not supporting userActivation.
2635239bbc README-migration: some improvements to the audio section.
ce7cb10541 dialog/unix: create zenity argv on the main thread
cf59fc797f dialog/unix: deep copy args to avoid data race
af6c641b8c dialog/unix: stricter typing
4c86511035 dialog/unix: reduce string allocations
ff82238172 dialog/unix: remove /usr/bin/env indirection
c5acbef3bf GPU: Fix D3D12_INTERNAL_StrToWStr returning incorrect length
6fe09e3aa4 dynapi: Minor optimization to SDL_SetError wrapper.
a1e8d5c327 Sync SDL3 wiki -> header
3ee39f6c3f GPU: Revise swapchain acquisition (#11633)
bbd4eeb287 examples/audio/04-multiple-streams: Note about web browser audio in README.
f45ce45603 ngage: Remove Nokia N-Gage support.
3f425b6f20 examples/audio/04-multiple-streams: Patched to compile on Visual Studio.
1fbb8e1824 examples/audio/04-multiple-streams: Remove drag-and-drop support.
e6e468d0c4 Sync SDL3 wiki -> header
962268ca21 Fixed Chinese locales on PSP (thanks @ccawley2011!)
ac92af02ea wikiheaders: put a header on the quick reference pages.
be5fba963a wikiheaders: optionally generate a Quick Reference page.
7c5c88a3ad cocoa: Fix conditional coding style
d4225070ad cocoa: Toggle the fullscreen menu item to 'leave' when entering a fullscreen space
48b6b93fb6 cmake: make RelWithDebInfo the default configuration
5447cb6d38 video: Prefer the window manager supplied coordinates for selecting a fullscreen display
e4215a04d9 gpu: make macro's function-like using do-while-0
fb71b44231 gpu: define EXPAND_ARRAY_IF_NEEDED macro once and make it function-like
0370b92d80 gpu: SDL_ClaimWindowForGPUDevice must set an error message on failure
5c020b9930 GPU: Enable VK_ERROR_NATIVE_WINDOW_IN_USE_KHR to print
279836d259 GPU: Swapchain image count respects number of allowed frames in flight
1d5d948ccf Fix building SDL3 without dialog support
19cc04a162 Add build-release.py updates from satellite libraries
b5c05b6e29 wayland: pass actual empty strings to zenity
1e7c7c69c5 wayland: handle 0 extra buttons in message box
09428688b9 Added a reminder to sign the source archives when creating a release
972c6d0b82 Add `SetTextInputProperties` to video device API and fix iOS handling
5d09656afa Refactor iOS text input activation to better work with hardware keyboards
72895a6994 Remove unused `hardwareKeyboard` variable
f64e9a52dc Sync SDL3 wiki -> header
ddb1e66d90 Updated the release checklist documentation
caf0348b26 Enable ApplePressAndHoldEnabled
900627f7fc Enable the SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS hints on macOS
6d1dac1404 Removed unused math code from the Visual Studio projects
d25cdc0fef Sync SDL3 wiki -> header
df48af22d4 Removed unused math code from the Xcode project
08de6656fc Document the pixel layout of YUV format surfaces
2ac62d8c67 Sync SDL3 wiki -> header
846eb9a886 Added SDL_RenderTextureAffine() to the exported API
7278399366 Sync SDL3 wiki -> header
d0f1910918 add SDL_RenderTextureAffine
2c4fc2e549 Sync SDL3 wiki -> header
8d8578785c SDL_asyncio.h is a public header and should be included in the framework
fa5f84fb6e GPU: Add SetGPUAllowedFramesInFlight (#11599)
47429227ab examples: Handle newlines in README.txt better.
0f228de48a examples: Add some metadata to the generated webpages.
ffb9b30e84 The metal renderer doesn't actually support RGB texture formats
1a5b0796b4 examples: fix canvas size for small screens
d1b8fcd692 work around type redefinition errors in SDL_immdevice.h
9b82d46259 GPU: Use correct logging category
5229b520af GPU: Log D3D12 driver version
b79e3ac830 examples: Let the browser handle README.txt word wrapping.
90efb63e52 examples: Improve webpage generation in various ways, add thumbnails, etc.
e50dc7265b examples: Fix some window titles in the demos.
7ddda4fe18 Add system theme support for Emscripten
3060105cfa Don't filter out controllers when launched by Steam under Proton
2e5208f353 kmsdrm: Fix Vulkan type redefinition errors from commit 24ed947cc35ebb9f50ac0685f1b88ec164d46c6c
c49f4ceeb2 Sync SDL3 wiki -> header
23828b62d4 Added SDL_IsMainThread() and SDL_RunOnMainThread()
bc4185c685 Document that video and input functions should be called on the main thread.
fffa6c7a2b Add missing include of fcntl.h
235e5c6a6c Fixed crash if a device doesn't have a USB product or manufacturer string
9f8157f42c Sync SDL3 wiki -> header
a0b8b57afe examples: add empty placeholder image
951ca96dc9 asyncio: Added more category documentation.
58f8e259d1 examples: fixup URLs for project subfolder
56da4e81d8 examples: added homepage + categories pages + added CSS (similar to wiki)
9784e10a75 audio: Let emscripten update device->sample_frames at device open time.
5bfece34f9 ran gendynapi.pl after PR/11170.
045e31178f Added SDL_dialog.c to the Xcode project
a74693c9a5 Sync SDL3 wiki -> header
a4852f3a10 SDL_ShowFileDialogWithProperties with more options
dc5a2ddfd0 GPU: Forward D3D12 validation warnings to the SDL log
efb59bd0bf GPU: Fix validation warning in D3D12 blit code
45869d6177 GPU: Vulkan requires drawIndirectFirstInstance feature (#11583)
d8eb68a6c5 GPU: Clean up D3D12 blit shader compilation
24ed947cc3 kmsdrm: Fix an LTO type mismatch warning
31128b6cdd kmsdrm: Clean up GLES function definitions
123306b18c X11: support _NET_WM_SYNC_REQUEST
d320d7143d Fix rawmouse wrong timestamp (#11553)
830b132cd4 SDL_asyncio_liburing.c: replace __kernel_time64_t use with SDL's Sint64
4ac78706bf SDL_asyncio_liburing.c: replace size_t casts on pointers with intptr_t
2ad5836d02 Sync SDL3 wiki -> header
31d09909b6 Sync SDL3 wiki -> header
1377cdb3f2 Fix the Indonesian language code on Android
46f43c2e6e asyncio: Remove `SDL_AsyncIOTask` from the public API.
4745aa3324 asyncio: Windows IoRing support, other tweaks and fixes.
3ca629ceb5 asyncio: Allow file closes to request a flush/fsyncdata.
022a6a9f97 asyncio: Added Linux io_uring support.
e79ce2a200 asyncio: Added async i/o APIs.
7293c18314 Fixed an inaccuracy in the return parameter information in the SDL_ConvertPixels function
401187eb6c Removed extra sa in SDL_ConvertSurfaceAndColorspace
b7a31ead08 added "gpu" to the list of possible values of SDL_HINT_RENDER_DRIVER in SDL_hints.h
9fb8661684 Fixed an inaccuracy in the return parameter information in the SDL_SurfaceHasAlternateImages function
6aab5a089d Fixed potential buffer overflow
65c9a58f5e audio: Make sure a few bitflag checks convert to bools correctly.
ec2ef5f9b5 dynapi: order headers for reproducible behavior
2762644e96 video: Don't error when setting an unbounded max window size while a minimum is set
068d9cc7d6 Sync SDL3 wiki -> header
2f59a1ce44 SDL_audio.h: Fixed a documentation typo (thanks, @JBetz!).
acf0f09320 SDL_migration.cocci: Fixed up some SDL3 symbols that had changed.
3a1d76d298 Sync SDL3 wiki -> header
ce573b01f8 audio: Added SDL_IsAudioDevicePhysical and SDL_IsAudioDevicePlayback.
d53241a299 docs/README-main-functions.md: reformatted Best Practices section.
5cd188bdbc Sync SDL3 wiki -> header
7099de4ae8 Update README-main-functions.md
bf9fa38920 SDL_audio.h: Fixed two typos.
f5ad66ef4b audio: Allow channel maps to specify -1 to mute a channel.
3303e9843f Sync SDL3 wiki -> header
f852038384 filesystem: Added SDL_GetCurrentDirectory().
16113374ff cmake: Enable POSIX fsops code for PS2 and PSP.
c0f1fe8e7f Sync SDL3 wiki -> header
f022501d52 fnsince.pl: Deal with post-3.1.3 releases before 3.2.0.
b8233aff8e Vita: implement mousewheel and buttons 4/5
b8bbd29ce9 Sync SDL3 wiki -> header
bbc9c75618 x11: Fix memory leaks in clipboard event handler
5c8bed3780 GPU: Fix D3D12 tearing query
03d15c031b Sync SDL3 wiki -> header
d55e6dfc5e hint for which system cursor to use as default
3c13bae64f Sync SDL3 wiki -> header
e0e61775b8 Add missing SDL_WindowFlags to SDL_test_common.c
6fab61b69d hidapi: check each usage on a device before ignoring it completely
e9fdcf6c60 Sync SDL3 wiki -> header
1720fc77fe examples: Added input/02-joystick-events
a07a88c1b4 examples: added input/01-joystick-polling
c508396e33 Avoid usage of CreateEventEx in WASAPI code
7a3f5ef129 Speed up full-surface fills
10e2ce9ba4 examples: Added audio/04-multiple-streams
88926f2b73 emscripten: send drag and drop events
e14d939ead Sync SDL3 wiki -> header
bbe843fd80 Full configuration of SDL_INSTALL_CMAKEDIR_ROOT
79f6f766d4 Avoid usage of `CreateEventEx` in D3D12 GPU backend
fdafa266d8 (doc): make cmake build parallel on linux
61ba8010d3 examples: Emscripten builds should allow memory growth.
212f0dcdb1 examples: Fix output name of demos.
41b0d36a6c fix MSVC projects after commit 51637495
f9ddb0bdea examples/demo/04-bytepusher: No need to check NULL before destroying things.
7bf3cae02e examples: fix cmake after commit 51637495
51637495e4 examples: Rename "game" to "demo".
566f3dc138 Add BytePusher example
b02285d495 Sync SDL3 wiki -> header
97ddc9adf2 Fix outdated references to SDL symbols in docs. Fixes #11503
465881d560 android: patched to compile.
c135386f58 events: Add render category to SDL_EventCategory.
615c935d11 events: Added SDL_RenderEvent.
848fd1eab4 ci: don't do 'brew install pkg-config' anymore II
0007451222 ci: don't do 'brew install pkg-config' anymore
3a2b595c4f PSP: Add locale support
e94ba6e700 Sync SDL3 wiki -> header
631c30527b Sync SDL3 wiki -> header
2e70944c44 gpu: Added an initial FAQ to the category documentation.
df73cae2b0 cocoa: Clear the pending flags on non-spaces fullscreen transitions
a4006e654e Fixed typo in the name of the SDL_GetAppMetadataProperty function in the description of the SDL_SetAppMetadataProperty function
5ee4d176f1 Added support for the Razer Wolverine V3 Pro
a0591ec4a3 README-documentation-rules.md: Mention not listing types in param/returns docs.
fef001cb48 Sync SDL3 wiki -> header
e770b4e266 dialog: Clean up filter param documentation.
795ceae520 Sync SDL3 wiki -> header
ecae3789ab SDL_dialog.h: Remove verbose docs on callback param from several functions.
587384756f render: use nearest pixel scaling for debug text
2b744c7df3 cocoa: Refuse to SDL_Init(SDL_INIT_VIDEO) from background thread.
932bb968d7 Fixed infinite recursion when the microphone is unavailable
1413848f41 Fixed crash if a window ends up without a display
35e6c92c3c Added the ROG Ally X to the list of Xbox controllers
4fb955c80b cmake: fix sdlcpu.cmake for C89 compilers
aa352837d5 cocoa: Don't sync on a pending fullscreen event if the window is miniaturized
18b7a2315c cocoa: Restore fullscreen state on the window regaining key status
014196d98d cocoa: Fix minimizing fullscreen windows on Sequoia
7a074f582e Steam Controller handling improvements
d2dc0fa920 Sync SDL3 wiki -> header
0c53d9a1ee Implemented SendEffect for Steam Controllers
d8f8cf3e99 Added SDL_HINT_JOYSTICK_HIDAPI_STEAM_HOME_LED
184da780f5 Fixed a crash when unplugging a Steam Controller dongle
70fe38bcb2 wayland: Rename some display related variables to better reflect their purpose
e027b85cc4 Validate that pixel formats have the correct attributes
bd57cfdb55 ci: pin MSVC ARM Windows SDK version to 10.0.22621.0
0f9e551d71 joystick/gdk/SDL_gameinputjoystick.c: fix build errors due to -Wformat
af6ce629c4 Make sure pairing remains enabled for the entire time dongle pairing is active
2b10a040ff Fixed rare case of wireless Steam Controller not being detected at startup
572cc7af63 Sync SDL3 wiki -> header
7d7ee43ddb stdinc: document SDL_strnlen and SDL_strlen
e9f7a1b359 fix relative system scale function on Windows
25390d6c21 fix relative warp emulation broken by #11460
e0166256ff joystick: Fix connection type for Steam Controller and Xbox 360 dongles
8657fa8b3b Improved reliability of the Steam Controller driver
f8468d580d add brace for contitional
eaef956a9a fix errenous delta when warping
b54f6044a5 Removed Linux Steam Controller support
b43b333d25 Moved the GPU renderer to the bottom of the list
7f14eb33c6 snake: improve comment
b71151a697 Added support for pairing controllers to the Steam Controller dongle
e4778d53d3 testautomation_video: Another Emscripten test to be skipped.
d48d4c8c48 testautomation_video: Don't test window position on Emscripten.
f0b61c69e7 Fixed duplicate controllers showing up on the Steam Controller wireless dongle
fe3566ca46 Ignore Steam Controllers in the Linux driver if HIDAPI is handling them
7959b08a4d Fixed spacing
6ca8269b96 docs/README-raspberrypi.md: Corrected NEON information (thanks, @cmitu!).
0f9505256d Steam Controller support defaults off on mobile platforms
140aba9e5d Enable Steam Controller support by default
68c2cf84f6 hidapi: Add support for the Steam Controller wireless dongle
1a311bc638 hidapi: Add support for Steam controllers connected via USB
e67ae274a5 hidapi: Fix bus type in HIDAPI_IGNORE_DEVICE() on Linux
7c5a2cd462 Sync SDL3 wiki -> header
95c8a1cf7c iostream: Update docs about return values and SDL_GetIOStatus().
7007b4762b events: Fix a compiler warning.
6049ca4fb1 docs/README-raspberrypi.md: Initial updates.
c021c75737 Sync SDL3 wiki -> header
d20936b544 camera: Add some category docs about camera device warmup delays.
3877bf55a3 Sync SDL3 wiki -> header
c26dda10e0 Sync SDL3 wiki -> header
9a4ae4b9ed Fixed crash if SDL_GetVideoDisplayForWindow() returns NULL
20cd4290d7 Sync SDL3 wiki -> header
dcf6dd19c3 Sync SDL3 wiki -> header
6c99a4b783 Sync SDL3 wiki -> header
a85f0b49f4 GPU: Remove D3D11 shaders from testgpu_spinning_cube
5a74aadac9 GPU: Null check shader inputs in CreateGPUGraphicsPipeline
32cc92dceb pipewire: i/o callbacks should avoid higher-level iteration during device open.
119b4fa5f5 GPU: Remove D3D11 backend and allow D3D12 to ingest DXBC (#11456)
fc12cc6dfd ci: add linux-powerpc to test matrix
559223ff9d cmake: don't use uninitialized SDL_VERSION and use REVISION.txt
332fd824f0 GPU Vulkan: release submitted command buffer after defrag (#11430)
1ed1bc1d5d testautomation keyboard: use `space` instead of `a`
8a2cac7aaa Fix SDL_PRIs64 to use standard PRId64
54ff1f35bd Fixed audio dropouts when plenty of audio is queued on Android
37b49c98dc Fixed setting up surround sound on NVIDIA Shield TV
dbe82e685d Sync SDL3 wiki -> header
3e2ef64c98 Add SDL_SaveFile and SDL_SaveFile_IO functions
b0140fb1b4 Sync SDL3 wiki -> header
97dac37373 Added SDL_HINT_ANDROID_LOW_LATENCY_AUDIO
6836ef8fd2 Added logging for low latency audio state
908bd84c5e Fixed reopening a controller on Android
1ea4edddec Fixed Java exception if mConnection is null
588e32ea5a test: Change LoadContext() return value type from int to bool
ecfd143a26 testcontroller: update the controller name when it's opened as a gamepad
908b42f2b9 Fixed 8BitDo M30 mapping to match fighting game conventions and the layout in XInput mode
028194286c Added mappings for the various firmware versions of the 8BitDo SN30 Pro controller
0ef7a1d901 Show the guid of gamepads that are opened
ed943318e2 Support multiple joystick buttons bound to the same gamepad button
27b828754a Use HIDAPI to provide better names for DirectInput controllers
5a7b75607a Added the OpenVR license to openvr_capi.h
c1246e31a4 Added support for the PowerA OPS v1 and v3 Pro wireless controllers
d3b882b4f9 Added support for the PowerA Fusion Pro 4 and Fusion Pro Wireless controllers
fb2145f731 Sync SDL3 wiki -> header
96729e745a SDL_GetClosestFullscreenDisplayMode(): Rename parameter `mode` to `closest`
683991ab71 Get the full display bounds if the window doesn't fit in the usable bounds.
6823e3f005 Fixed gaps in scaled 9-grid texture rendering
458f616c53 wayland: Send a display removed event when a display is disconnected
73e0e8cf5b SDL_GetDisplayForPoint(), SDL_GetDisplayForRect(): Check argument for NULL.
8026866994 wayland: fixed memory leak at shutdown
cacfdc8cfa Sync SDL3 wiki -> header
7031b240df Added SDL_PROP_WINDOW_WAYLAND_VIEWPORT_POINTER
c56a3f60fe xcode+cmake: use SDL3.framework folder as IMPORTED_LOCATION
615d2dcd5b .wikiheader-options: Treat SDL int types (Uint64, etc) as API prefixes.
e001a309be create-release.py: use head of git ref as default commit
27f69c772c Updated the release checklist
87dade4421 Set SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER for the GPU renderer
0508f100e2 Sync SDL3 wiki -> header
927d297161 Updated to version 3.1.7 for development
78cc5c1734 Updated to version 3.1.6 for the preview release
19af3a2b34 Sync SDL3 wiki -> header
e31e3caece PSP: Fix building examples in parallel
c5f12b135d Fixed the D-pad on wireless Xbox 360 controllers
780578cd36 PSP: Allow building tests in parallel
8b48b70c6e Fixed return value setting state on combined Joy-Con controllers
77a0411dde Minor cleanup
68cc173d92 Sync SDL3 wiki -> header
7c968f1510 Update SDL_hints.h
e2857fc5a2 Update SDL_mouse.c
5699ba799e Add return to CHECK_VULKAN_ERROR_AND_RETURN macro
6c10446a6c Add version info when building CI/CD for apple platforms
d6b60bcc53 typo in player spawnpos, mov drawcall out of loop
09495059df Fixed the PS5 controller face buttons on Amazon Fire TV, Android 11
c099d0525e sort_controllers.py: fixed parsing SDL_PRIVATE_GAMEPAD_DEFINITIONS
24bdbb8bf4 Supress Metal warning when compiling against macOS 10.11-10.13
2a05b63580 Mark generate.py as executable
51628034d9 Don't offset the view if there's no text input rect
c8a04eec06 Autorelease keys should go down when pressed.
f543faf837 Allow in-tree build
6647345be0 Sync SDL3 wiki -> header
b4dff42dcd GPU: Add SDL_CancelGPUCommandBuffer (#11316)
94d110edd5 Specify C source file in example VC projects
415abf2ea2 Rename variables for readability
bdf16628fb Added 03-infinite-monkeys example game
2b92dc9baa Minor updates to woodeneye-008.c from template.c
a93ec0c679 Added Visual Studio project for 02-woodeneye-008
9a77ee2008 Added instructions for creating Visual Studio projects for examples
014b473bcc GPU D3D12: Fix depth texture sampling
ff14a1781f GPU D3D12: Fix indirect buffers not being refcounted
149ecffd6f SDL_vulkan.h: undefine VK_DEFINE_HANDLER and VK_DEFINE_NON_DISPATCHABLE_HANDLE
35e53f76a9 metal: check success of device creation (#11367)
feb10434a1 Order by subsystem
b2f216f9e2 Add GPU to iOS build config
54836050c9 metal: Add availability checks
8f9a562969 wayland: Remove vestigial struct member
152bcce85f Add examples to `SDL.sln` (#11255)
1e7c186461 Splitcreen FPS example with multiple mouse and keyboard (#11317)
5c5235fb51 ci: Add Steam Linux Runtime (Sniper) task
36c209080c wayland: Refactor some shell surface related names
2b7dc55364 wayland: Check the WM capabilities before sending a minimize event
1abbd13414 wayland: Throttle interactive user resize events
e0d019c941 Sync SDL3 wiki -> header
cb0c7c9680 SDL_CreateDirectory(): directory tree creation for absolute paths for non-Windows platforms
a10578acbd SDL_SYS_RenamePath(): Fix error message.
3922bcec95 Sync SDL3 wiki -> header
04a478b6a9 SDL_Enumerate[Storage]Directory() comments: Use enum constant names instead of integers.
5c3d42aade Update README-linux.md for openSUSE Tumbleweed dependencies
8468c372b2 SDL_EnumerateDirectory(): (posix) Fix return value when directory is invalid
97b924f985 typo: maxOS -> macOS
a851c5b648 create-release.py uses python3
47411d8007 build-release.py uses python3
4f160d69a6 Closes #10318 - implement Android prerotation in the Vulkan renderer
93471cf78d video/openvr: minor clean-up:
8bf1a84200 ci: add include headers of build directory to ci artifacts
590e1196d0 snake: check allocated memory before use
20e01c6fbe android: add (disabled) android.permission.INTERNET to AndroidManifest.xml
850158f83f testcontroller: fixed incorrect usage of memcpy()
344546b4ea cocoa: Make sure GL context destruction happens on the main thread.
dcd4ddb043 Sync SDL3 wiki -> header
8d3bec99a7 audio: Make SDL_GetAudioStreamProperties() thread safe.
10e52e1899 docs: Added more '\threadsafety` tags.
731853077a Send drop complete events when the drop leaves the window on Cocoa, Wayland, and X11
db4e2ccbac Allow redefinition of only one macro SDL_SINT64_C SDL_UINT64_C
c0bad724a7 README-ios.md: Add info about UIApplicationSupportsIndirectInputEvents on iOS 17
4ea26a7771 emscripten: scale mousewheel X coordinates correctly, not just Y coordinates.
d0cf2c19d1 Allow defining custom SDL_SINT64_C and SDL_UINT64_C macros (#11315)
7108291d0b video: Change SDL_GLattr to SDL_GLAttr.
c0e9205a92 video: Change capitalization on various OpenGL attribute typedefs.
3c506630c3 video: Turn several OpenGL attribute enums into integer typedefs.
a04fda211c Sync SDL3 wiki -> header
4e33440c04 Sync SDL3 wiki -> header
e8b69b03fe cmake: fail configuring when no X11 or wayland could be found (#11310)
540db0d164 Bumped version of macro 'main' to 3.1.3
370521363a Sync SDL3 wiki -> header
924f719b97 wayland: Get the window content scale from the backend
299587fa64 Sync SDL3 wiki -> header
5e855d82e3 Manually bump versions of non-function identifiers introduced after 3.1.3 to 3.2.0
22bc430bbb Set error using function hresult
6eca02a0e7 evdev: correctly handle composite devices
ba1412cb9f evdev: fixed devices not being removed on disconnect
370c0426ce testspriteminimal: only quit when escape is pressed
acfc223e15 Sync SDL3 wiki -> header
423337796c GPU Vulkan: Use dedicated allocation for download buffers (#11298)
24b376ef18 Sync SDL3 wiki -> header
1c1706a00b fnsince: update `\since` policy for documentation.
21c91d5535 examples now using SDL_ALPHA_OPAQUE(_FLOAT) for opaque alpha value
63ef5a2369 Sync SDL3 wiki -> header
fd530d029f Fixed typo in SDL_clipboard.h
7b6416add0 Sync SDL3 wiki -> header
af1c165352 Set version of new identifiers after 3.1.3 release to 3.1.6
45584ad73e Simplify get_channel_name() so it's easier for people to read and understand
c134dd6e5e Fixed typo in the channel layout documentation
4a8eadf167 include: Fixed typo in SDL_CopyFile's documentation.
d9e6fe0b7a Sync SDL3 wiki -> header
f5c27a3a2c render: Corrected docs for SDL_SetRenderVSync().
1f8b9a320c VITA: fix SDL_ShowMessageBox by using different memory type
a42c9ec5f7 Sync SDL3 wiki -> header
2318961b6f docs: Add `\threadsafety` to some low-hanging fruit across a few headers.
eed11ad6d6 docs: Fixed example code for SDL_qsort_r() and SDL_bsearch_r().
0bec18245d android: fix android.content.Context:getCacheDir JNI prototype
e9b5f6749e wikiheaders: add (disabled) code to check for missing `\threadsafety` tags.
19a1175c02 include: Updated docs on SDL_TouchFingerEvent.
e61f0678ee x11: Remove the "safety net" error handler.
f9bffa31b6 docs: fix window flags in README-migration.md
b0982e8982 docs: Updated README-emscripten.md.
c56af0d975 Removed unused code
35be8bb7f9 Fixed warning C4456: declaration of 'e' hides previous local declaration
8119568805 x11: Remove text-scaling-factor setting checks
1c51b8dc33 Only set the OpenGL flag if the OpenVR driver is active
82b3325978 Fixed memory leaks if Windows initialization fails
d199586683 Fixed memory leaks if OpenVR initialization fails
7b492553c4 Allow the OpenVR driver to be enabled on Windows
0aea14cf45 Added logging for additional events
3d47877bb4 Added SDL_EVENT_RENDER_DEVICE_LOST
54e52d055f Sync SDL3 wiki -> header
9c848e08e4 docs: Explain events for already plugged in controllers (#11286)
26567df878 Don't treat mouse buttons as focus clicks if the window has mouse capture
ef758d05c1 render: GetRenderViewportSize shouldn't use scale, just logical presentation.
92520c1d9b Improved D3D12 handling of unrecoverable device loss
315842cf71 Fixed crashes handling D3D11/12 device lost in testsprite
e2254b1045 Added color scale info for the GPU renderer TODO item
4b54e32231 Tweak android path functions comment tag \sa
a6536a9298 RI_KEY_BREAK indicates key is up
679dd4b181 SDL_RequestAndroidPermission() comment: Add link to android permissions website
eb1451536e Sync SDL3 wiki -> header
5819d4b360 SDL_CreateRenderer() comment: Remove mention of flags
e0321ca5b6 SDL3: SDL_render_gl(render name: opengl) dose not support transparent on Linux/X11 (Bug #11273) (#11274)
dcbb2f11a8 Clamp the texture alpha and color modulation values to 0-255
541ba33714 Fix SDL_GetClosestFullscreenDisplayMode documentation
40070d899d Refactor Blit_RGB555_ARGB1555 to be more generic
3d2c8c510d add GLES3 headers from Khronos for OpenVR video driver.
2668558c5c Sync SDL3 wiki -> header
153f90a725 Revert "Use the correct return type for SDL_GetAndroidJNIEnv()"
ffb1d9e4b4 Removed Blit2101010toN and BlitNto2101010
5c1ccaefae Fixed VULKAN_UpdateViewport judgment.
4c2d0c422b wayland: Remove kde_output_order_v1 support
5f874b60a8 Sync SDL3 wiki -> header
1647d36aec docs: document copying shared SDL3 a bit more + document sanitizer/libc incompatibility
b6a6a4a7f8 audio: fix incorrect dynCall in Emscripten audio.
07bb8f1c4c openvr: added APIENTRY for OpenGL functions (thanks @cnlohr!)
b40ad5428b Fixed assertion at quit when the debug text was the last texture used.
a48fa675be Fix formatting
1d23d2c3c2 Renamed SDL_SANDBOX_UNKNOWN to SDL_SANDBOX_UNKNOWN_CONTAINER
a7da3ad59b x11: Support sorting displays via the priority hint
0faf9dc4a4 kmsdrm: Support sorting displays via the priority hint
a6e5ab437f video/openvr: Avoid type redefinition errors.
2654d5d48b Sync SDL3 wiki -> header
e81e917c5e Added an OpenVR video driver (thanks @cnlohr!)
569691797d windows/SDL_systhread.c: fix permissions
186c6e5c9d windows: fix race condition with exception-based thread naming.
faa404a652 If we get a newline character, treat it as SDLK_RETURN
a432abf4cc Make sure that we quit if we get a terminating event
c5e1ae4580 Only free debug_char_texture_atlas if it has been allocated
00f4cb308b Fixed crash if the Vulkan renderer changes swapchain image count
41366f73b2 Don't block in Android USB device open
60c3eaf5ee Use SDL_GetAndroidJNIEnv() in hid.cpp
2d3fa03d53 Use the correct return type for SDL_GetAndroidJNIEnv()
3d852da806 Requesting Bluetooth permission on Android is now asynchronous
be3d961b47 Treat clicking the right pad as a thumbstick click on a Steam Controller
6da4d94abf VITA: implement camera subsystem
f79f21217b VITA: fix yuv texture update
4612db21a3 SDL_utils.c: restrict gethostname() usage to non-windows
9a5420118a Define SDL_DIALOG_DUMMY in SDL_build_config_xbox.h
dd955332a2 Removed SDL_build_config_emscripten.h
5492be23a1 ci: test Apple x64 on macos-13 runner
c48fbbb067 Sync SDL3 wiki -> header
c41b2bb855 SDL_ShouldIgnoreGamepad() should take product IDs rather than a guid.
8a30def5f2 Only use Steam Virtual Gamepads if we're running under Steam
28504f5791 Steam virtual gamepad info isn't available in the macOS sandbox
d6981da5a4 Added SDL_GetSandbox()
d7b1ba1bfc Added support for the Steam Virtual Gamepad on macOS Sequoia
3ebfdb04be SDL_stdinc.h: provide a prototype for strdup for __clang_analyzer__ case
d9df87f19f Fix syntax of trailing doc comments
9cf388f260 Re-added HAVE_FDATASYNC and HAVE_GETHOSTNAME for platforms that have them.
6897385623 Add `void` to `run_colorspace_test()` function prototype
69433ee075 doc: explain build-scripts/create-release.py in the release checklist
18410c03ea cmake: fix checks for fdatasync() and gethostname()
a027ec59ca Make the name of the Steam Deck Controller consistent.
09e3af58b5 Fixed bug #10954: software renderer: examples/renderer/10-geometry missing a triangle typo when changing return code from int to bool
860e38a3a2 VITA: fix shader color format
ed1ec236c1 Removed fdatasync and gethostname definitions from platforms that don't have them
cbbad4051b Treat a button press location as an implicit mouse move
e5fa929245 Report win32 last error string windows_file_open (#11224)
b4554a8a75 Sync SDL3 wiki -> header
97f1da73da Rename GPU properties for consistency
9af5ffcfbe Improve support for private platforms (#11220)
66d09a1cda wayland: Adjust primary display selection priority
638b50b69b CI, LoongArch64: disable clang-tidy
dede2ab86f Sync SDL3 wiki -> header
553fc5fe0e wayland: Expose displays in a deterministic order, and attempt to better handle selecting a primary display.
075ae7db7d ci: update LoongArch toolchain to 2023.08.08
4162bddca7 cmake: fix configuration with -DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON
cdaaabb978 GPU: Fix Metal sampler address mode order
104dabb9de PSVITA: enable posix fsops
afee27a530 Make sure stdio handles are in blocking mode
bb764e3106 Added support for full range BT.709 YUV conversion
ce49465b13 Sync SDL3 wiki -> header
72bae5167e Updated documentation
e254c99b38 examples/game/01-snake: Update game logic in AppIterate, don't use a timer.
edb28e79b5 Make SDL_LoadBMP() use true instead of 1
f212cb5f92 Don't overwrite the SDL_IOFromConstMem() error in testshape
51dc978785 Don't overwrite the SDL_IOFromFile() error in SDL_LoadFile()
fb43dc3097 Set error for NULL SDL_IOStream in SDL_LoadWAV_IO()
00bb81de76 GPU: Allow size queries on depth formats
817fa9a975 releases: don't add static library to MinGW binary release
45dfdfbb7b Add parametrized build script
57f2577c65 GPU Vulkan: Fix depth-only framebuffer leak
46835650db Added config.xcconfig to the Xcode build
9fac4b9f5f SDL_windowsmodes.c: Fix MSVC builds against SDKs older than 10.0.17134.0
b865708039 Sync SDL3 wiki -> header
0b6ad8bf62 Improved the documentation for SDL_SetWindowShape()
f9d490045b Fixed uikit crash when GLES is disabled
3733b1d5d8 Sync SDL3 wiki -> header
c20918b0fb render: Add SDL_RenderDebugText().
44bc19b592 test: remove testaudio-art.txt (this info is in test/LICENSE.txt now).
1cc85c912b Check return value of SDL_small_alloc()
d7be7fc168 Fixed Cohen-Sutherland out code computation for float line intersection
db78c0f563 Sync SDL3 wiki -> header
a8ca024495 Added SDL_GetDefaultLogOutputFunction()
b766c824bd Don't overwrite the SDL_IOFromFile() error in SDL_LoadBMP()
aed1f76248 Sync SDL3 wiki -> header
a567786762 Added SDL_SetErrorV()
d5e02474ac Fixed SDL_oldnames.h to use the correct new names
1a1e2e9892 Set size parameter in SDL_GetClipboardData()
82598e5ca9 GPU Vulkan: Fix frame counter timing (#11189)
b641c2a0db Refactor gendynapi.py with the final goal to make it re-usable
173c168ff4 Default functions are already declared by the first SDL_dynapi_procs.h include
fd9f2ae5b5 Sync SDL3 wiki -> header
01c9c1d0eb Document main callbacks API thread safety
fd9e57b71e 3DS: Support simple message boxes
2bef8852fb testdrawchessboard: Allow using the standard render API
7556c44796 SDL3: Fixed Cocoa_GL_CreateContext() not returning a context on success (#11181)
94c8c170eb 3DS: Only bundle resources with tests that need them
fec006a4f9 Allow for more fine tuning of Duff's device routines
aebb64efa1 Remove leftover ARM SIMD code
9a81892447 Old env vars as fallback for SDL_VIDEO_DRIVER + SDL_AUDIO_DRIVER #11115
3e57d996fe Reduce the size of the SDL_blit_0 alpha code
05c53b5ab0 Add macro guards for OpenGL <=1.3 function prototypes
365dba6de8 Sync SDL3 wiki -> header
4898cbb6cf SDL_migration.cocci: Fix renaming SDL_bool
22566506d0 SDL3: opengles2 render not support window with transparent flag on Linux/X11 (#11167)
c6c195ff88 Always use WaitForSingleObjectEx() as a fallback in SDL_SYS_DelayNS()
c5904d8710 Improved implementation of SDL_DelayPrecise() (thanks @nightmareci!)
25251a9405 Fixed warning C4723: potential divide by 0
33366b0a4e Fix SDL_MAIN_USE_CALLBACKS with Android, introduce SDL_MAIN_EXPORTED
86ef790a23 explicit cast to int in SDL_bits
3cd7e22e8b Fixed converting full range YUV to RGB
3086b25c4e Set hint SDL_HINT_MAC_SCROLL_MOMENTUM version to SDL 3.1.4.
b676413657 Sync SDL3 wiki -> header
48ff3efdb9 Clarify README-highdpi.md (#10083)
e31c68427a Sync SDL3 wiki -> header
6ea4a66451 GPU: Add SDL_CalculateGPUTextureFormatSize (#11146)
6d85127560 Rename hint string literal SDL_HINT_MAC_SCROLL_MOMENTUM
3db10a6b2c GPU: ASTC block size fixes (#11157)
90a3a2359b thread: Rewrote generic Condition Variables.
41dfe2c246 test/testautomation_stdlib.c: fix gcc warning on 32 bit
73b995fbad Don't assume OpenGL on Android
8aaaeb7560 Sync SDL3 wiki -> header
2a9cb68b91 Sync SDL3 wiki -> header
0babb284dd fnsince.pl: Make fixes now that we've reached ABI lock.
40ff6a2785 test: Fix mouse focus test on X11
e4b1a9f382 Sync SDL3 wiki -> header
7ff819141d libm/e_exp.c: fix gcc warning on 32 bit:
ac6b9e2d19 Sync SDL3 wiki -> header
8262072d91 Fixed possible memset(NULL) call in testautomation's SDL_aligned_alloc() check
4b7c5f561b Fixed warning: ‘new_item.probe_len’ may be used uninitialized in this function
c8f5f6d47a Added SDL_DelayPrecise()
28a70a5b71 Use the correct version for the \since field
bf351b0b0e Add more configChanges to Android Manifest (#11145)
9c322386bf gpu: vulkan: Fix an uninitialised structure in SDL_BlitGPUTexture()
da5a1585cd GPU: Avoid calling SDL_GetWindowSizeInPixels when possible (#11139)
4707bb730e Sync SDL3 wiki -> header
9023a199dd Fixed crash in RLE colorkey blitting
f946f87f30 Don't rely on event.buttonMask being set in touchesEnded
ee9b6204cf Updated to version 3.1.5 for development
02f3a96476 Sync SDL3 wiki -> header
f8eac30276 Added SDL_StepBackUTF8()
1f08a03794 Switched drag-n-drop logging to trace level
5b6342a00d Default SDL_HINT_JOYSTICK_GAMEINPUT to "1" on GDK platforms
ed87e7e434 test: enable GameInput driver on GDK platforms
acb18e05b5 GPU: fix swapchain buffer size not set on Xbox
ff834f7733 Removed the restrict keyword
8e6ead2f7b [GPU] Added ASTC texture format support (#11116)
02434cd293 emscripten: Fixes for data addresses above 2gb
c34790f9f1 Fixed spacing
312ecc4a52 SDL_main.h: Remove dead code for hypothetical C++ platforms
823b218051 Simplify code to include SDL_main_impl.h in SDL_main.h
cba77834f2 init: Log '<unspecified>' not '(null)' if the app name isn't set.
fb8244d6d9 init: Also log the SDL revision here
c24f7d2453 Log app ID as SYSTEM/INFO during initialization
e7ee92e822 Switched drag-n-drop logging to trace level
d9f8474dd7 Sync SDL3 wiki -> header
95aaaa3232 Sync SDL3 wiki -> header
158ba93d61 Update some window function documentation
300daf308a Replace SDL_TRUE/FALSE with true/false in the coccinelle script
95ab38ba15 ci: actions/cache might return a boolean as string
7acfdfd3e7 Sync SDL3 wiki -> header
326ab439d7 Sync SDL3 wiki -> header
fb07ab91c6 Improved SDL_main documentation and remove extern "C" comment.
03fa9ff0b0 Sync SDL3 wiki -> header
2000ccb541 Allow linear interpolation of the font textures
f6fa617139 Define SDL_DIALOG_DUMMY in SDL_build_config.h as needed
4627283eca Allow building both Cocoa and dummy dialog implementations
c8526532de Changed objectVersion to 54 so Xcode 12 can load the projects (thanks @Wohlstand!)
2fd12b2e8a keyboard: Note that enabling text input can also enable an IME
81b48de3f5 Fixed VID/PID list parsing of SDL_HINT_GAMECONTROLLER_SENSOR_FUSION
5db64300b8 Fixed SDL_GetStringInteger() for values starting with '0' and '1' (thanks @DanielGibson!)
7da728a642 Added support for wired XBox controllers on macOS 15.0 Sequoia
659f2f4b04 examples: add basic app metadata to all existing examples.
aa534c3ac3 core: Fixed incorrect comment in core/windows/SDL_windows.h.
ee7f61fd9a snake: Add extended app metadata
ca82405d5a snake: Add basic app metadata
6ae5666acf Check for VK_SUBOPTIMAL_KHR also in vkQueuePresentKHR (#11113)
06bd214af6 Fixed warnings building on Android
596fcfa6c4 fix microphone permission and feature flags being spread out
54e622c2e6 Use the printf vararg verification macros when compiling with clang
fca05fa754 examples: Use SDL_Log() instead of message boxes for errors.
9f170286ba test: Replace README with LICENSE.txt
d0ef58b442 Sync SDL3 wiki -> header
cbb9a16367 Sync SDL3 wiki -> header
65539bc4f7 Make sure trackpad state is updated when button presses are delivered
03b259893a Fixed return value of SDL_AddGamepadMapping()
bf54eddba9 macOS: Clarify when macOS hints need to be set
c2b98e21ba macOS: Add hint for smooth SDL_EVENT_MOUSE_WHEEL values
2fa8acb084 x11: Refresh the global cursor coordinates when confining the pointer
e59078ac6f Sync SDL3 wiki -> header
9e74ada7b8 gpu: fixed formatting in docs.
c358bf3f9b Removed test program list, it's better to just look at the code.
f8dd73fdb9 Fixed build
0f47d3a77b Fixed use after free (thanks @meyraud705!)
e159bcf5de test: Make blit_testExampleApplicationRender work on big endian
c9ffa3f9e1 Remove vestiges of the TAKE_FOCUS window event
596ef1ba2e Moved the SDL_ttf IME demo to showfont in the SDL_ttf project
e00b1fdd67 clipboard: include mime types in SDL_ClipboarUpdate
2880b40e33 fix pipewire prototype
b6ab7d28f6 Replaced \r\n with \n in SDL root files
b8e72b0969 Note that creating a renderer will fail if the preferred renderer isn't available.
1ca45c5891 Fix typo: DiretMedia->DirectMedia
8db3b47482 Just use normal stdio for the child process
8c3f88b495 docs: Wrote CategoryVulkan.
369b93771b Sync SDL3 wiki -> header
deeffaa8d6 Sync SDL3 wiki -> header
84ecf7fd3e docs: Add CategorySurface text.
e292d1f5ac Sync SDL3 wiki -> header
d5af0c7e09 Added missing parentheses
5a60d073c0 Sync SDL3 wiki -> header
a3413e050b Sync SDL3 wiki -> header
c25423b94c docs: Filled in some category pages.
a57ecad648 Fixed documentation typos
37315110c1 Sync SDL3 wiki -> header
f26dd52090 SDL_GetProcessProperties is missing a SDLCALL
d318a4a6b1 .wikiheaders-options: Declare SDL3 to be a stable API!
64cbf02dbf Sync SDL3 wiki -> header
ffe4e571d1 wikiheaders: regex hack to make a URL not confuse wikilink genertion.
a7e4e9219a Sync SDL3 wiki -> header
e8c852d77c GPU: re-add parens to wiki intro
00385951a1 Use file descriptor I/O for process pipes
f592a35439 Sync SDL3 wiki -> header
12d007038c GPU: wiki header link typo
f275731e18 Sync SDL3 wiki -> header
f3285b01c8 GPU: Intro fixes
93c7521dd5 Sync SDL3 wiki -> header
c1084bfaa3 GPU Introduction (#11062)
21e7fa45e8 GPU: fix padding field typo
bd4cd34a74 Add docs to mingw development archive
f859d69c44 Sync SDL3 wiki -> header
6c64c62114 Rename SDL_BUTTON() to SDL_BUTTON_MASK()
d529407ce7 Sync SDL3 wiki -> header
fe2880fcda Rename SDL_SetThreadPriority() to SDL_SetCurrentThreadPriority()
69196ab30d Change evasive library handle to `SDL_SharedObject*`
3a6a3ab64f gpu: Fix memory leak in Vulkan backend.
43e7ce7dfc Updated to version 3.1.3 for the preview release
ca0b1eaf5a Sync SDL3 wiki -> header
93c27a6675 Fixed the documentation for consistency.
3ae2af8aa1 Sync SDL3 wiki -> header
9a5d5a2839 video: Improve the EGL attribute callbacks.
d4143e02d1 Always set checked_monotonic_time when calling CheckMonotonicTime()
020fb6889c Removed unnecessary const-qualifiers in src and test files
b8e8dcaa9a Add void to openbsd function prototypes
0e909d2785 Removed redundant condition in src/events/SDL_pen.c
191f3ecbbc render: Restore previous policy for converting window/render coordinates.
3246df8bd3 Remove redundant SDL_Vulkan_GetResultString() declaration
07fd88d241 docs: Fix migration documentation for SDL_WINDOWEVENT_SIZE_CHANGED
a0de6c4abf Add properties to SDL_IOStreams returned by IOFromMem
1bb7e2b1a8 SDL_migration.cocci: Removed obsolete SDL_CreateWindowWithPosition code.
f4cea5e019 Removed const qualifiers from SDL_CreateHashTable() parameter types
d287feaddf render: Remove non-pointer args' const qualifiers on SDL_RenderTextureRotated.
e3757f072b Sync SDL3 wiki -> header
8b4f5f09c1 dynapi: It's a Python script now, not a perl script.
35b002be82 audio: Clarified SDL_GetAudioStreamQueued docs.
47450425fd Allow iterating just the keys or values in a hashtable
d5fe6dd627 Don't use const for non-pointer API parameters
d2b2a752ce SDL_migration.cocci: A few fixes.
91b074beb7 Removed SDL_IPHONE_MAX_GFORCE
34033d5838 Sync SDL3 wiki -> header
eced9f58a9 Added a userdata parameter for EGL attribute callbacks
798c9574d0 Sync SDL3 wiki -> header
89e68aa801 Added missing return value documentation for bsearch()
4fa92d233d Include stdbool.h when using Visual Studio 2017+
522321b7c9 test: Fix testcustomcursor on high-DPI displays
3b3c4a79b6 Don't close file descriptors already handled by AddFileDescriptorCloseActions()
5f5379dc99 Add `SDL_IsTV()` (#11004)
6bcf2f919a Sync SDL3 wiki -> header
0b5e01a305 loadso: library handles are now `SDL_SharedObject*` instead of `void*`.
f351395c46 Sync SDL3 wiki -> header
3234a3b902 Simplified internal SDL_Surface structure
1f3a0d12e6 Made texture size and format public in the API
5136b30652 render: SDL_ConvertEventToRenderCoordinates() now handles pen events.
b4fcd1f345 pen: Corrected some documentation.
e3dbd74fe7 Improved documentation for SDL_Surface fields
13c5d1092f hidapi: update hid_write() for windows from mainstream.
3eab599977 just force the barrier on UpdateTexture actually
e17741a6cb Render GPU: Only cycle on update if entire texture is replaced
45ad763de5 Disable backface culling and use a constant rectangle winding order.
fa14b53273 GPU Vulkan: Clear up some swapchain edge cases
c16d7c87d6 Sync SDL3 wiki -> header
ab832f1be0 Added documentation for qsort and bsearch functions
818d7d892a x11: store all atoms in a specific struct
801870c8cf video: cache some more atoms under X11
dcc7560a5c Sync SDL3 wiki -> header
afdf325fb4 GPU: Add swapchain dimension out params (#11003)
b3388d5753 Haiku does not have fdatasync, but has fsync
396afa2117 ci: bump haiku to r1beta5
0b64520997 hashtable: fixed unused-parameter warnings
1787d6ca5c main: SDL_AppQuit() now reports the result value.
6a7f8b74f1 filesystem: SDL_GlobDirectory shouldn't strip final '/' if the path is "/".
7241dd9ec3 Add more SDL_Process tests
f6055432c8 Fix null-pointer dereference on failing SDL_SYS_CreateProcess
e9bfa5bf6a Mitigate BatBadBut vulnerability
06e122103c Fix window opacity update
c84d825241 Added SDL_HashPointer() and SDL_KeyMatchPointer()
d0c9c008e1 wayland: Use high-DPI system cursors on non-DPI aware windows
5f304b3a47 Fix builed error after commit 0e45b824e34 due to -Wunused-variable
0e45b824e3 renderer: always update the output pixel size at startup
2825a682f0 Fixed build errors
ba7b346e52 hashtable: reimplement as open-addressed robin hood hashtable
62938837c2 Sync SDL3 wiki -> header
fc242abbd2 GPU: recreate swapchain on window pixel size change event (#10985)
66f6b40c92 Render GPU: Don't call GetWindowSizeInPixels during RenderPreset (#10984)
a923771978 Added SDL_murmur3_32()
039148fb0e Updated check for stdbool.h
7ca0e9ede1 wayland: Scale the pointer destination size relative to the theme size
d2094bd0a2 wayland: Don't query the cursor info with DBus if the cursor shape protocol is present
dee62e1b47 Remove trailing comma in enum
7d21a49c9c filesystem: SDL_EnumerateDirectoryCallback uses an enum now, not an int.
55bd9f5311 iostream: flush() should attempt to sync file data to physical media.
0852307b58 gpu: Check Vulkan device features for IsDeviceSuitable
fb165a542b GPU Vulkan: add resolve info to framebuffer and render pass lookups
0542bbbf1a Sync SDL3 wiki -> header
4a296f1bde filesystem: Fixed memory leak on Windows.
e944f0fb9d testfilesystem: Added test of creating parent dirs.
428f2f35be filesystem: SDL_CreateDirectory should make parent directories.
94030131de filesystem: Windows SDL_SYS_CreateDirectory should succeed if dir exists.
48c3ee2120 testcolorspace.c: Fix unreachable code warning
8d6b397cd8 Sync SDL3 wiki -> header
3f446d8fb5 Minor cleanup
1088ea55fa SDL_gpu_d3d11.c: define D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD for old toolchains
8377cad974 Sync SDL3 wiki -> header
c39e8298b7 GPU: Document swapchain dimensions
de40d6bae0 GPU Metal: Set texture to NULL even if AcquireSwapchainTexture fails
0e5a49542d Sync SDL3 wiki -> header
f32e96f5e2 clipboard: add SDL_ClipboardMimeTypes
0befa7d8e9 Sync SDL3 wiki -> header
eedd2039f9 GPU: 32-bit component texture formats
769ff47461 Sync SDL3 wiki -> header
05d0656bd6 GPU: Simultaneous compute pass read-write (#10965)
d39acc6d1e Fixed warning C4702: unreachable code
5ff6e8d522 GPU: Add enable_depth_clip to RasterizerState (#10964)
04bb105d09 Added header for SDL_ThreadID type
e98cf3c870 Fix Xbox builds
c7442b04f0 Sync SDL3 wiki -> header
be401dd1e3 GPU: More robust error reporting (#10958)
48e213b4cd Fixed SDL_ShouldQuit() returning false during status transitions
d8c76d2f34 filesystem: POSIX SDL_SYS_CopyFile shouldn't use a temp file.
0d593cf39a Sync SDL3 wiki -> header
f267ec7681 filesystem: Improve docs, make some promises about overwrites and file caches.
c1587b1eac Sync SDL3 wiki -> header
125e592844 Added SDL_ShouldInit() and SDL_ShouldQuit()
0e2c4e407a README-migration: note that logical presentation state is different from SDL2.
4e09e58f62 include: Small clarification on directory enumeration documentation.
38f971bac5 filesystem: SDL_SYS_EnumerateDirectory() now returns bool.
86ea283904 examples: No need to explicitly seed the RNG at startup.
671a33c2f7 wayland: Raise all touches on a cancel event
457d0edeaf Remove some extra semicolons
345cae361d Document mode parameter of SDL_GetRenderLogicalPresentation
345d9bfe19 A zero source rect is valid for blitting
1aea43846e Don't use BlitARGBto555PixelAlpha() for SDL_PIXELFORMAT_ARGB1555
59d69a3ba3 Sync SDL3 wiki -> header
d9a7da4fac Optimized SDL_HasEvent() and SDL_HasEvents()
3abb213083 opengl: Fixed SDL_RENDERCMD_SETDRAWCOLOR code checking the wrong variable.
961cd51611 opengl: Removed a FIXME (this is documented as not-thread-safe now.
80cf3f7c38 ci: Fix check_stdlib_usage.py and run on ci
76f28ea120 Fix stdlib usage
80da805688 build: Fix testprocess invocation during "as-installed" tests
81644d260f Sync SDL3 wiki -> header
122cd4db2b include: Added `\threadsafety` notes to all SDL_render.h functions.
276969cd58 Sync SDL3 wiki -> header
4c48ff51f8 render: SDL_RenderPresent now behaves when a render target is currently set.
7a6a0becb8 render: Fixed a FIXME for SDL_SetRenderViewport with a negative size.
54459def69 render: Remove the logical presentation render target.
bf7a48cdcc render/gpu: Change some memcpy calls to SDL_memcpy.
b48f29dd9b examples: Fix name of renderer/17-read-pixels binary.
925e47a077 GPU: Fix backwards LogError and SetError calls
1561d7c089 Fix warnings in build-scripts/check_stdlib_usage.py
2070adb262 android: add python script checking Android JNI bindings
cf4049cfde ci: check versioning on ci
557c6dfb18 GPU: call SDL_SetError where appropriate
6ec8b1a173 Throttle tickle reports to PS4/PS5 controllers
53bf2baac3 Change JNI calls to comply with recent Boolean changes
fcab6c99fb examples: Fixed some window titles.
9881c4e582 examples: Added renderer/17-read-pixels
62389ada6f examples/renderer/02-primitives: seed the RNG.
95134f6d58 examples: Added renderer/15-cliprect
ad3a4c677b wayland: Clean up cursor scaling
e5d3a1b6f5 Remove casts from typed pointer to void * for printf %p in test projects
57418475ce kmsdrm: Keep fd around if we can drop master
13f88df190 kmsdrm: Fix KMSDRM_Vulkan_CreateSurface() return value
8f55f48337 kmsdrm: Move property initialization a bit further down
1ed3dac021 examples: Added renderer/14-viewport
e00ea27d25 examples/renderer/01-clear: No longer needs vsync.
004ac40226 Fix warning: no function prototype
4a3faf20ac gpu: Replace high-level logs with SetError
043c876a15 Move default colorspace aliases into enum
0685b96469 GPU: fix build when SDL_GPU_DISABLED is set
e973b687cd examples: Added renderer/11-color-mods
0478a6ee3b Move endian pixel format aliases into enum
1828bde49f examples/renderer/01-clear: Use the color-cycle code from testvulkan.c
3bc2bd790c build-web-examples.pl: Added a FIXME.

git-subtree-dir: external/SDL
git-subtree-split: 8ec576ddabdc7edfd68e7a8a3214e84e4026328d
2025-01-07 15:13:06 +00:00

6087 lines
198 KiB
C++

/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* # CategoryStdinc
*
* SDL provides its own implementation of some of the most important C runtime
* functions.
*
* Using these functions allows an app to have access to common C
* functionality without depending on a specific C runtime (or a C runtime at
* all). More importantly, the SDL implementations work identically across
* platforms, so apps can avoid surprises like snprintf() behaving differently
* between Windows and Linux builds, or itoa() only existing on some
* platforms.
*
* For many of the most common functions, like SDL_memcpy, SDL might just call
* through to the usual C runtime behind the scenes, if it makes sense to do
* so (if it's faster and always available/reliable on a given platform),
* reducing library size and offering the most optimized option.
*
* SDL also offers other C-runtime-adjacent functionality in this header that
* either isn't, strictly speaking, part of any C runtime standards, like
* SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better
* options, like SDL_strlcpy(), which functions as a safer form of strcpy().
*/
#ifndef SDL_stdinc_h_
#define SDL_stdinc_h_
#include <SDL3/SDL_platform_defines.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(SDL_INCLUDE_INTTYPES_H)
#include <inttypes.h>
#endif
#ifndef __cplusplus
#if defined(__has_include) && !defined(SDL_INCLUDE_STDBOOL_H)
#if __has_include(<stdbool.h>)
#define SDL_INCLUDE_STDBOOL_H
#endif
#endif
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \
defined(SDL_INCLUDE_STDBOOL_H)
#include <stdbool.h>
#elif !defined(__bool_true_false_are_defined) && !defined(bool)
#define bool unsigned char
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif
#endif /* !__cplusplus */
#ifndef SDL_DISABLE_ALLOCA
# ifndef alloca
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# elif defined(SDL_PLATFORM_NETBSD)
# if defined(__STRICT_ANSI__)
# define SDL_DISABLE_ALLOCA
# else
# include <stdlib.h>
# endif
# elif defined(__GNUC__)
# define alloca __builtin_alloca
# elif defined(_MSC_VER)
# include <malloc.h>
# define alloca _alloca
# elif defined(__WATCOMC__)
# include <malloc.h>
# elif defined(__BORLANDC__)
# include <malloc.h>
# elif defined(__DMC__)
# include <stdlib.h>
# elif defined(SDL_PLATFORM_AIX)
# pragma alloca
# elif defined(__MRC__)
void *alloca(unsigned);
# else
void *alloca(size_t);
# endif
# endif
#endif
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* The largest value that a `size_t` can hold for the target platform.
*
* `size_t` is generally the same size as a pointer in modern times, but this
* can get weird on very old and very esoteric machines. For example, on a
* 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment
* plus 16-bit offset), but `size_t` is 16 bits, because it can only deal with
* the offset into an individual segment.
*
* In modern times, it's generally expected to cover an entire linear address
* space. But be careful!
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_SIZE_MAX SIZE_MAX
#elif defined(SIZE_MAX)
# define SDL_SIZE_MAX SIZE_MAX
#else
# define SDL_SIZE_MAX ((size_t) -1)
#endif
#ifndef SDL_COMPILE_TIME_ASSERT
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A compile-time assertion.
*
* This can check constant values _known to the compiler at build time_ for
* correctness, and end the compile with the error if they fail.
*
* Often times these are used to verify basic truths, like the size of a
* datatype is what is expected:
*
* ```c
* SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
* ```
*
* The `name` parameter must be a valid C symbol, and must be unique across
* all compile-time asserts in the same compilation unit (one run of the
* compiler), or the build might fail with cryptic errors on some targets.
* This is used with a C language trick that works on older compilers that
* don't support better assertion techniques.
*
* If you need an assertion that operates at runtime, on variable data, you
* should try SDL_assert instead.
*
* \param name a unique identifier for this assertion.
* \param x the value to test. Must be a boolean value.
*
* \threadsafety This macro doesn't generate any code to run.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_assert
*/
#define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
#elif defined(__cplusplus)
/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
#if (__cplusplus >= 201103L)
#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
#endif
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
#endif
#endif /* !SDL_COMPILE_TIME_ASSERT */
#ifndef SDL_COMPILE_TIME_ASSERT
/* universal, but may trigger -Wunused-local-typedefs */
#define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
#endif
/**
* The number of elements in a static array.
*
* This will compile but return incorrect results for a pointer to an array;
* it has to be an array the compiler knows the size of.
*
* This macro looks like it double-evaluates the argument, but it does so
* inside of `sizeof`, so there are no side-effects here, as expressions do
* not actually run any code in these cases.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
/**
* Macro useful for building other macros with strings in them.
*
* For example:
*
* ```c
* #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
* ```
*
* \param arg the text to turn into a string literal.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_STRINGIFY_ARG(arg) #arg
/**
* \name Cast operators
*
* Use proper C++ casts when compiled as C++ to be compatible with the option
* -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
*/
/* @{ */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Handle a Reinterpret Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_static_cast
* \sa SDL_const_cast
*/
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
/**
* Handle a Static Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ static_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_reinterpret_cast
* \sa SDL_const_cast
*/
#define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
/**
* Handle a Const Cast properly whether using C or C++.
*
* If compiled as C++, this macro offers a proper C++ const_cast<>.
*
* If compiled as C, this macro does a normal C-style cast.
*
* This is helpful to avoid compiler warnings in C++.
*
* \param type the type to cast the expression to.
* \param expression the expression to cast to a different type.
* \returns `expression`, cast to `type`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_reinterpret_cast
* \sa SDL_static_cast
*/
#define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
#elif defined(__cplusplus)
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
#define SDL_static_cast(type, expression) static_cast<type>(expression)
#define SDL_const_cast(type, expression) const_cast<type>(expression)
#else
#define SDL_reinterpret_cast(type, expression) ((type)(expression))
#define SDL_static_cast(type, expression) ((type)(expression))
#define SDL_const_cast(type, expression) ((type)(expression))
#endif
/* @} *//* Cast operators */
/**
* Define a four character code as a Uint32.
*
* \param A the first ASCII character.
* \param B the second ASCII character.
* \param C the third ASCII character.
* \param D the fourth ASCII character.
* \returns the four characters converted into a Uint32, one character
* per-byte.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_FOURCC(A, B, C, D) \
((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Append the 64 bit integer suffix to a signed integer literal.
*
* This helps compilers that might believe a integer literal larger than
* 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
* instead of `0xFFFFFFFF1` by itself.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_UINT64_C
*/
#define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
/**
* Append the 64 bit integer suffix to an unsigned integer literal.
*
* This helps compilers that might believe a integer literal larger than
* 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
* instead of `0xFFFFFFFF1` by itself.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_SINT64_C
*/
#define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
#else /* !SDL_WIKI_DOCUMENTATION_SECTION */
#ifndef SDL_SINT64_C
#if defined(INT64_C)
#define SDL_SINT64_C(c) INT64_C(c)
#elif defined(_MSC_VER)
#define SDL_SINT64_C(c) c ## i64
#elif defined(__LP64__) || defined(_LP64)
#define SDL_SINT64_C(c) c ## L
#else
#define SDL_SINT64_C(c) c ## LL
#endif
#endif /* !SDL_SINT64_C */
#ifndef SDL_UINT64_C
#if defined(UINT64_C)
#define SDL_UINT64_C(c) UINT64_C(c)
#elif defined(_MSC_VER)
#define SDL_UINT64_C(c) c ## ui64
#elif defined(__LP64__) || defined(_LP64)
#define SDL_UINT64_C(c) c ## UL
#else
#define SDL_UINT64_C(c) c ## ULL
#endif
#endif /* !SDL_UINT64_C */
#endif /* !SDL_WIKI_DOCUMENTATION_SECTION */
/**
* \name Basic data types
*/
/* @{ */
/**
* A signed 8-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef int8_t Sint8;
#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
/**
* An unsigned 8-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef uint8_t Uint8;
#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
/**
* A signed 16-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef int16_t Sint16;
#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
/**
* An unsigned 16-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef uint16_t Uint16;
#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
/**
* A signed 32-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef int32_t Sint32;
#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
/**
* An unsigned 32-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*/
typedef uint32_t Uint32;
#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
/**
* A signed 64-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_SINT64_C
*/
typedef int64_t Sint64;
#define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
/**
* An unsigned 64-bit integer type.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_UINT64_C
*/
typedef uint64_t Uint64;
#define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
#define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
/**
* SDL times are signed, 64-bit integers representing nanoseconds since the
* Unix epoch (Jan 1, 1970).
*
* They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
* and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
* SDL_TimeToWindows() and SDL_TimeFromWindows().
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_MAX_SINT64
* \sa SDL_MIN_SINT64
*/
typedef Sint64 SDL_Time;
#define SDL_MAX_TIME SDL_MAX_SINT64
#define SDL_MIN_TIME SDL_MIN_SINT64
/* @} *//* Basic data types */
/**
* \name Floating-point constants
*/
/* @{ */
#ifdef FLT_EPSILON
#define SDL_FLT_EPSILON FLT_EPSILON
#else
/**
* Epsilon constant, used for comparing floating-point numbers.
*
* Equals by default to platform-defined `FLT_EPSILON`, or
* `1.1920928955078125e-07F` if that's not available.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
#endif
/* @} *//* Floating-point constants */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A printf-formatting string for an Sint64 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIs64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIs64 "lld"
/**
* A printf-formatting string for a Uint64 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIu64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIu64 "llu"
/**
* A printf-formatting string for a Uint64 value as lower-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIx64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIx64 "llx"
/**
* A printf-formatting string for a Uint64 value as upper-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIX64 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIX64 "llX"
/**
* A printf-formatting string for an Sint32 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIs32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIs32 "d"
/**
* A printf-formatting string for a Uint32 value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIu32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIu32 "u"
/**
* A printf-formatting string for a Uint32 value as lower-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIx32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIx32 "x"
/**
* A printf-formatting string for a Uint32 value as upper-case hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRIX32 " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRIX32 "X"
/**
* A printf-formatting string prefix for a `long long` value.
*
* This is just the prefix! You probably actually want SDL_PRILLd, SDL_PRILLu,
* SDL_PRILLx, or SDL_PRILLX instead.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILL_PREFIX "d bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRILL_PREFIX "ll"
/**
* A printf-formatting string for a `long long` value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLd " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRILLd SDL_PRILL_PREFIX "d"
/**
* A printf-formatting string for a `unsigned long long` value.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLu " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRILLu SDL_PRILL_PREFIX "u"
/**
* A printf-formatting string for an `unsigned long long` value as lower-case
* hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLx " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRILLx SDL_PRILL_PREFIX "x"
/**
* A printf-formatting string for an `unsigned long long` value as upper-case
* hexadecimal.
*
* Use it like this:
*
* ```c
* SDL_Log("There are %" SDL_PRILLX " bottles of beer on the wall.", bottles);
* ```
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRILLX SDL_PRILL_PREFIX "X"
#endif /* SDL_WIKI_DOCUMENTATION_SECTION */
/* Make sure we have macros for printing width-based integers.
* <inttypes.h> should define these but this is not true all platforms.
* (for example win32) */
#ifndef SDL_PRIs64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIs64 "I64d"
#elif defined(PRId64)
#define SDL_PRIs64 PRId64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
#define SDL_PRIs64 "ld"
#else
#define SDL_PRIs64 "lld"
#endif
#endif
#ifndef SDL_PRIu64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIu64 "I64u"
#elif defined(PRIu64)
#define SDL_PRIu64 PRIu64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
#define SDL_PRIu64 "lu"
#else
#define SDL_PRIu64 "llu"
#endif
#endif
#ifndef SDL_PRIx64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIx64 "I64x"
#elif defined(PRIx64)
#define SDL_PRIx64 PRIx64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
#define SDL_PRIx64 "lx"
#else
#define SDL_PRIx64 "llx"
#endif
#endif
#ifndef SDL_PRIX64
#if defined(SDL_PLATFORM_WINDOWS)
#define SDL_PRIX64 "I64X"
#elif defined(PRIX64)
#define SDL_PRIX64 PRIX64
#elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
#define SDL_PRIX64 "lX"
#else
#define SDL_PRIX64 "llX"
#endif
#endif
#ifndef SDL_PRIs32
#ifdef PRId32
#define SDL_PRIs32 PRId32
#else
#define SDL_PRIs32 "d"
#endif
#endif
#ifndef SDL_PRIu32
#ifdef PRIu32
#define SDL_PRIu32 PRIu32
#else
#define SDL_PRIu32 "u"
#endif
#endif
#ifndef SDL_PRIx32
#ifdef PRIx32
#define SDL_PRIx32 PRIx32
#else
#define SDL_PRIx32 "x"
#endif
#endif
#ifndef SDL_PRIX32
#ifdef PRIX32
#define SDL_PRIX32 PRIX32
#else
#define SDL_PRIX32 "X"
#endif
#endif
/* Specifically for the `long long` -- SDL-specific. */
#ifdef SDL_PLATFORM_WINDOWS
SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */
#define SDL_PRILL_PREFIX "I64"
#else
#define SDL_PRILL_PREFIX "ll"
#endif
#ifndef SDL_PRILLd
#define SDL_PRILLd SDL_PRILL_PREFIX "d"
#endif
#ifndef SDL_PRILLu
#define SDL_PRILLu SDL_PRILL_PREFIX "u"
#endif
#ifndef SDL_PRILLx
#define SDL_PRILLx SDL_PRILL_PREFIX "x"
#endif
#ifndef SDL_PRILLX
#define SDL_PRILLX SDL_PRILL_PREFIX "X"
#endif
/* Annotations to help code analysis tools */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Macro that annotates function params with input buffer size.
*
* If we were to annotate `memcpy`:
*
* ```c
* void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
* ```
*
* This notes that `src` should be `len` bytes in size and is only read by the
* function. The compiler or other analysis tools can warn when this doesn't
* appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
/**
* Macro that annotates function params with input/output string buffer size.
*
* If we were to annotate `strlcat`:
*
* ```c
* size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
* ```
*
* This notes that `dst` is a null-terminated C string, should be `maxlen`
* bytes in size, and is both read from and written to by the function. The
* compiler or other analysis tools can warn when this doesn't appear to be
* the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
/**
* Macro that annotates function params with output string buffer size.
*
* If we were to annotate `snprintf`:
*
* ```c
* int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...);
* ```
*
* This notes that `text` is a null-terminated C string, should be `maxlen`
* bytes in size, and is only written to by the function. The compiler or
* other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
/**
* Macro that annotates function params with output buffer size.
*
* If we were to annotate `wcsncpy`:
*
* ```c
* char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` wchar_t in size,
* and is only written to by the function. The compiler or other analysis
* tools can warn when this doesn't appear to be the case.
*
* This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for
* bytes.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_OUT_CAP(x) _Out_cap_(x)
/**
* Macro that annotates function params with output buffer size.
*
* If we were to annotate `memcpy`:
*
* ```c
* void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` bytes in size,
* and is only written to by the function. The compiler or other analysis
* tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
/**
* Macro that annotates function params with output buffer string size.
*
* If we were to annotate `strcpy`:
*
* ```c
* char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize);
* ```
*
* This notes that `dst` should have a capacity of `bufsize` bytes in size,
* and a zero-terminated string is written to it by the function. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
/**
* Macro that annotates function params as printf-style format strings.
*
* If we were to annotate `fprintf`:
*
* ```c
* int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
* ```
*
* This notes that `fmt` should be a printf-style format string. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
/**
* Macro that annotates function params as scanf-style format strings.
*
* If we were to annotate `fscanf`:
*
* ```c
* int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...);
* ```
*
* This notes that `fmt` should be a scanf-style format string. The compiler
* or other analysis tools can warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
/**
* Macro that annotates a vararg function that operates like printf.
*
* If we were to annotate `fprintf`:
*
* ```c
* int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a printf-style format
* string, followed by `...`. The compiler or other analysis tools can warn
* when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
/**
* Macro that annotates a va_list function that operates like printf.
*
* If we were to annotate `vfprintf`:
*
* ```c
* int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a printf-style format
* string, followed by a va_list. The compiler or other analysis tools can
* warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
/**
* Macro that annotates a vararg function that operates like scanf.
*
* If we were to annotate `fscanf`:
*
* ```c
* int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a scanf-style format string,
* followed by `...`. The compiler or other analysis tools can warn when this
* doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
/**
* Macro that annotates a va_list function that operates like scanf.
*
* If we were to annotate `vfscanf`:
*
* ```c
* int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
* ```
*
* This notes that the second parameter should be a scanf-style format string,
* followed by a va_list. The compiler or other analysis tools can warn when
* this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
/**
* Macro that annotates a vararg function that operates like wprintf.
*
* If we were to annotate `fwprintf`:
*
* ```c
* int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a wprintf-style format wide
* string, followed by `...`. The compiler or other analysis tools can warn
* when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
/**
* Macro that annotates a va_list function that operates like wprintf.
*
* If we were to annotate `vfwprintf`:
*
* ```c
* int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2);
* ```
*
* This notes that the second parameter should be a wprintf-style format wide
* string, followed by a va_list. The compiler or other analysis tools can
* warn when this doesn't appear to be the case.
*
* On compilers without this annotation mechanism, this is defined to nothing.
*
* This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
* between them will cover at least Visual Studio, GCC, and Clang.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
#elif defined(SDL_DISABLE_ANALYZE_MACROS)
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
#else
#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
#include <sal.h>
#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
#define SDL_OUT_CAP(x) _Out_cap_(x)
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
#else
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#endif
#if defined(__GNUC__) || defined(__clang__)
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
#else
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
#endif
#endif /* SDL_DISABLE_ANALYZE_MACROS */
/** \cond */
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);
SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1);
SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1);
SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2);
SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2);
SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4);
SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8);
SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8);
SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long));
SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long));
typedef struct SDL_alignment_test
{
Uint8 a;
void *b;
} SDL_alignment_test;
SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
SDL_COMPILE_TIME_ASSERT(two_s_complement, (int)~(int)0 == (int)(-1));
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/** \endcond */
/* Check to make sure enums are the size of ints, for structure packing.
For both Watcom C/C++ and Borland C/C++ the compiler option that makes
enums having the size of an int must be enabled.
This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
*/
/** \cond */
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
#if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
/* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
typedef enum SDL_DUMMY_ENUM
{
DUMMY_ENUM_VALUE
} SDL_DUMMY_ENUM;
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/** \endcond */
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* A macro to initialize an SDL interface.
*
* This macro will initialize an SDL interface structure and should be called
* before you fill out the fields with your implementation.
*
* You can use it like this:
*
* ```c
* SDL_IOStreamInterface iface;
*
* SDL_INIT_INTERFACE(&iface);
*
* // Fill in the interface function pointers with your implementation
* iface.seek = ...
*
* stream = SDL_OpenIO(&iface, NULL);
* ```
*
* If you are using designated initializers, you can use the size of the
* interface as the version, e.g.
*
* ```c
* SDL_IOStreamInterface iface = {
* .version = sizeof(iface),
* .seek = ...
* };
* stream = SDL_OpenIO(&iface, NULL);
* ```
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_IOStreamInterface
* \sa SDL_StorageInterface
* \sa SDL_VirtualJoystickDesc
*/
#define SDL_INIT_INTERFACE(iface) \
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* Allocate memory on the stack (maybe).
*
* If SDL knows how to access alloca() on the current platform, it will use it
* to stack-allocate memory here. If it doesn't, it will use SDL_malloc() to
* heap-allocate memory.
*
* Since this might not be stack memory at all, it's important that you check
* the returned pointer for NULL, and that you call SDL_stack_free on the
* memory when done with it. Since this might be stack memory, it's important
* that you don't allocate large amounts of it, or allocate in a loop without
* returning from the function, so the stack doesn't overflow.
*
* \param type the datatype of the memory to allocate.
* \param count the number of `type` objects to allocate.
* \returns newly-allocated memory, or NULL on failure.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_stack_free
*/
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
/**
* Free memory previously allocated with SDL_stack_alloc.
*
* If SDL used alloca() to allocate this memory, this macro does nothing and
* the allocated memory will be automatically released when the function that
* called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will
* SDL_free the memory immediately.
*
* \param data the pointer, from SDL_stack_alloc(), to free.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_stack_alloc
*/
#define SDL_stack_free(data)
#elif !defined(SDL_DISABLE_ALLOCA)
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
#define SDL_stack_free(data)
#else
#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
#define SDL_stack_free(data) SDL_free(data)
#endif
/**
* Allocate uninitialized memory.
*
* The allocated memory returned by this function must be freed with
* SDL_free().
*
* If `size` is 0, it will be set to 1.
*
* If you want to allocate memory aligned to a specific alignment, consider
* using SDL_aligned_alloc().
*
* \param size the size to allocate.
* \returns a pointer to the allocated memory, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_free
* \sa SDL_calloc
* \sa SDL_realloc
* \sa SDL_aligned_alloc
*/
extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
/**
* Allocate a zero-initialized array.
*
* The memory returned by this function must be freed with SDL_free().
*
* If either of `nmemb` or `size` is 0, they will both be set to 1.
*
* \param nmemb the number of elements in the array.
* \param size the size of each element of the array.
* \returns a pointer to the allocated array, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_free
* \sa SDL_malloc
* \sa SDL_realloc
*/
extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
/**
* Change the size of allocated memory.
*
* The memory returned by this function must be freed with SDL_free().
*
* If `size` is 0, it will be set to 1. Note that this is unlike some other C
* runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
* same way as `free(mem)`.
*
* If `mem` is NULL, the behavior of this function is equivalent to
* SDL_malloc(). Otherwise, the function can have one of three possible
* outcomes:
*
* - If it returns the same pointer as `mem`, it means that `mem` was resized
* in place without freeing.
* - If it returns a different non-NULL pointer, it means that `mem` was freed
* and cannot be dereferenced anymore.
* - If it returns NULL (indicating failure), then `mem` will remain valid and
* must still be freed with SDL_free().
*
* \param mem a pointer to allocated memory to reallocate, or NULL.
* \param size the new size of the memory.
* \returns a pointer to the newly allocated memory, or NULL if allocation
* failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_free
* \sa SDL_malloc
* \sa SDL_calloc
*/
extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
/**
* Free allocated memory.
*
* The pointer is no longer valid after this call and cannot be dereferenced
* anymore.
*
* If `mem` is NULL, this function does nothing.
*
* \param mem a pointer to allocated memory, or NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_malloc
* \sa SDL_calloc
* \sa SDL_realloc
*/
extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
/**
* A callback used to implement SDL_malloc().
*
* SDL will always ensure that the passed `size` is greater than 0.
*
* \param size the size to allocate.
* \returns a pointer to the allocated memory, or NULL if allocation failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.1.3.
*
* \sa SDL_malloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
/**
* A callback used to implement SDL_calloc().
*
* SDL will always ensure that the passed `nmemb` and `size` are both greater
* than 0.
*
* \param nmemb the number of elements in the array.
* \param size the size of each element of the array.
* \returns a pointer to the allocated array, or NULL if allocation failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.1.3.
*
* \sa SDL_calloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
/**
* A callback used to implement SDL_realloc().
*
* SDL will always ensure that the passed `size` is greater than 0.
*
* \param mem a pointer to allocated memory to reallocate, or NULL.
* \param size the new size of the memory.
* \returns a pointer to the newly allocated memory, or NULL if allocation
* failed.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.1.3.
*
* \sa SDL_realloc
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
/**
* A callback used to implement SDL_free().
*
* SDL will always ensure that the passed `mem` is a non-NULL pointer.
*
* \param mem a pointer to allocated memory.
*
* \threadsafety It should be safe to call this callback from any thread.
*
* \since This datatype is available since SDL 3.1.3.
*
* \sa SDL_free
* \sa SDL_GetOriginalMemoryFunctions
* \sa SDL_GetMemoryFunctions
* \sa SDL_SetMemoryFunctions
*/
typedef void (SDLCALL *SDL_free_func)(void *mem);
/**
* Get the original set of SDL memory functions.
*
* This is what SDL_malloc and friends will use by default, if there has been
* no call to SDL_SetMemoryFunctions. This is not necessarily using the C
* runtime's `malloc` functions behind the scenes! Different platforms and
* build configurations might do any number of unexpected things.
*
* \param malloc_func filled with malloc function.
* \param calloc_func filled with calloc function.
* \param realloc_func filled with realloc function.
* \param free_func filled with free function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
SDL_calloc_func *calloc_func,
SDL_realloc_func *realloc_func,
SDL_free_func *free_func);
/**
* Get the current set of SDL memory functions.
*
* \param malloc_func filled with malloc function.
* \param calloc_func filled with calloc function.
* \param realloc_func filled with realloc function.
* \param free_func filled with free function.
*
* \threadsafety This does not hold a lock, so do not call this in the
* unlikely event of a background thread calling
* SDL_SetMemoryFunctions simultaneously.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_SetMemoryFunctions
* \sa SDL_GetOriginalMemoryFunctions
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
SDL_calloc_func *calloc_func,
SDL_realloc_func *realloc_func,
SDL_free_func *free_func);
/**
* Replace SDL's memory allocation functions with a custom set.
*
* It is not safe to call this function once any allocations have been made,
* as future calls to SDL_free will use the new allocator, even if they came
* from an SDL_malloc made with the old one!
*
* If used, usually this needs to be the first call made into the SDL library,
* if not the very first thing done at program startup time.
*
* \param malloc_func custom malloc function.
* \param calloc_func custom calloc function.
* \param realloc_func custom realloc function.
* \param free_func custom free function.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread, but one
* should not replace the memory functions once any allocations
* are made!
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetMemoryFunctions
* \sa SDL_GetOriginalMemoryFunctions
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func);
/**
* Allocate memory aligned to a specific alignment.
*
* The memory returned by this function must be freed with SDL_aligned_free(),
* _not_ SDL_free().
*
* If `alignment` is less than the size of `void *`, it will be increased to
* match that.
*
* The returned memory address will be a multiple of the alignment value, and
* the size of the memory allocated will be a multiple of the alignment value.
*
* \param alignment the alignment of the memory.
* \param size the size to allocate.
* \returns a pointer to the aligned memory, or NULL if allocation failed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_aligned_free
*/
extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
/**
* Free memory allocated by SDL_aligned_alloc().
*
* The pointer is no longer valid after this call and cannot be dereferenced
* anymore.
*
* If `mem` is NULL, this function does nothing.
*
* \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_aligned_alloc
*/
extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
/**
* Get the number of outstanding (unfreed) allocations.
*
* \returns the number of allocations or -1 if allocation counting is
* disabled.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
/**
* A thread-safe set of environment variables
*
* \since This struct is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
* \sa SDL_DestroyEnvironment
*/
typedef struct SDL_Environment SDL_Environment;
/**
* Get the process environment.
*
* This is initialized at application start and is not affected by setenv()
* and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
* SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
* SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
* in the C runtime environment after SDL_Quit().
*
* \returns a pointer to the environment for the process or NULL on failure;
* call SDL_GetError() for more information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
/**
* Create a set of environment variables
*
* \param populated true to initialize it from the C runtime environment,
* false to create an empty environment.
* \returns a pointer to the new environment or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety If `populated` is false, it is safe to call this function
* from any thread, otherwise it is safe if no other threads are
* calling setenv() or unsetenv()
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
* \sa SDL_DestroyEnvironment
*/
extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
/**
* Get the value of a variable in the environment.
*
* \param env the environment to query.
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
/**
* Get all variables in the environment.
*
* \param env the environment to query.
* \returns a NULL terminated array of pointers to environment variables in
* the form "variable=value" or NULL on failure; call SDL_GetError()
* for more information. This is a single allocation that should be
* freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
/**
* Set the value of a variable in the environment.
*
* \param env the environment to modify.
* \param name the name of the variable to set.
* \param value the value of the variable to set.
* \param overwrite true to overwrite the variable if it exists, false to
* return success without setting the variable if it already
* exists.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
/**
* Clear a variable from the environment.
*
* \param env the environment to modify.
* \param name the name of the variable to unset.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_GetEnvironment
* \sa SDL_CreateEnvironment
* \sa SDL_GetEnvironmentVariable
* \sa SDL_GetEnvironmentVariables
* \sa SDL_SetEnvironmentVariable
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
/**
* Destroy a set of environment variables.
*
* \param env the environment to destroy.
*
* \threadsafety It is safe to call this function from any thread, as long as
* the environment is no longer in use.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_CreateEnvironment
*/
extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
/**
* Get the value of a variable in the environment.
*
* This function uses SDL's cached copy of the environment and is thread-safe.
*
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
/**
* Get the value of a variable in the environment.
*
* This function bypasses SDL's cached copy of the environment and is not
* thread-safe.
*
* \param name the name of the variable to get.
* \returns a pointer to the value of the variable or NULL if it can't be
* found.
*
* \threadsafety This function is not thread safe, consider using SDL_getenv()
* instead.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_getenv
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
/**
* Set the value of a variable in the environment.
*
* \param name the name of the variable to set.
* \param value the value of the variable to set.
* \param overwrite 1 to overwrite the variable if it exists, 0 to return
* success without setting the variable if it already exists.
* \returns 0 on success, -1 on error.
*
* \threadsafety This function is not thread safe, consider using
* SDL_SetEnvironmentVariable() instead.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_SetEnvironmentVariable
*/
extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
/**
* Clear a variable from the environment.
*
* \param name the name of the variable to unset.
* \returns 0 on success, -1 on error.
*
* \threadsafety This function is not thread safe, consider using
* SDL_UnsetEnvironmentVariable() instead.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_UnsetEnvironmentVariable
*/
extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
/**
* A callback used with SDL sorting and binary search functions.
*
* \param a a pointer to the first element being compared.
* \param b a pointer to the second element being compared.
* \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
* before `a`, 0 if they are equal. If two elements are equal, their
* order in the sorted array is undefined.
*
* \since This callback is available since SDL 3.1.3.
*
* \sa SDL_bsearch
* \sa SDL_qsort
*/
typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
/**
* Sort an array.
*
* For example:
*
* ```c
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *a, const void *b)
* {
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->n < B->n) {
* return -1;
* } else if (B->n < A->n) {
* return 1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 3, "third" }, { 1, "first" }, { 2, "second" }
* };
*
* SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
* ```
*
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_bsearch
* \sa SDL_qsort_r
*/
extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
/**
* Perform a binary search on a previously sorted array.
*
* For example:
*
* ```c
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *a, const void *b)
* {
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->n < B->n) {
* return -1;
* } else if (B->n < A->n) {
* return 1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 1, "first" }, { 2, "second" }, { 3, "third" }
* };
* data key = { 2, NULL };
*
* data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
* ```
*
* \param key a pointer to a key equal to the element being searched for.
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \returns a pointer to the matching element in the array, or NULL if not
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_bsearch_r
* \sa SDL_qsort
*/
extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
/**
* A callback used with SDL sorting and binary search functions.
*
* \param userdata the `userdata` pointer passed to the sort function.
* \param a a pointer to the first element being compared.
* \param b a pointer to the second element being compared.
* \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
* before `a`, 0 if they are equal. If two elements are equal, their
* order in the sorted array is undefined.
*
* \since This callback is available since SDL 3.1.3.
*
* \sa SDL_qsort_r
* \sa SDL_bsearch_r
*/
typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
/**
* Sort an array, passing a userdata pointer to the compare function.
*
* For example:
*
* ```c
* typedef enum {
* sort_increasing,
* sort_decreasing,
* } sort_method;
*
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *userdata, const void *a, const void *b)
* {
* sort_method method = (sort_method)(uintptr_t)userdata;
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->key < B->key) {
* return (method == sort_increasing) ? -1 : 1;
* } else if (B->key < A->key) {
* return (method == sort_increasing) ? 1 : -1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 3, "third" }, { 1, "first" }, { 2, "second" }
* };
*
* SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
* ```
*
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \param userdata a pointer to pass to the compare function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_bsearch_r
* \sa SDL_qsort
*/
extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
/**
* Perform a binary search on a previously sorted array, passing a userdata
* pointer to the compare function.
*
* For example:
*
* ```c
* typedef enum {
* sort_increasing,
* sort_decreasing,
* } sort_method;
*
* typedef struct {
* int key;
* const char *string;
* } data;
*
* int SDLCALL compare(const void *userdata, const void *a, const void *b)
* {
* sort_method method = (sort_method)(uintptr_t)userdata;
* const data *A = (const data *)a;
* const data *B = (const data *)b;
*
* if (A->key < B->key) {
* return (method == sort_increasing) ? -1 : 1;
* } else if (B->key < A->key) {
* return (method == sort_increasing) ? 1 : -1;
* } else {
* return 0;
* }
* }
*
* data values[] = {
* { 1, "first" }, { 2, "second" }, { 3, "third" }
* };
* data key = { 2, NULL };
*
* data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
* ```
*
* \param key a pointer to a key equal to the element being searched for.
* \param base a pointer to the start of the array.
* \param nmemb the number of elements in the array.
* \param size the size of the elements in the array.
* \param compare a function used to compare elements in the array.
* \param userdata a pointer to pass to the compare function.
* \returns a pointer to the matching element in the array, or NULL if not
* found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_bsearch
* \sa SDL_qsort_r
*/
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);
/**
* Compute the absolute value of `x`.
*
* \param x an integer value.
* \returns the absolute value of x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
/**
* Return the lesser of two values.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `<` operator. However, it double-evaluates both its parameters, so do not
* use expressions with side-effects here.
*
* \param x the first value to compare.
* \param y the second value to compare.
* \returns the lesser of `x` and `y`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
/**
* Return the greater of two values.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `>` operator. However, it double-evaluates both its parameters, so do not
* use expressions with side-effects here.
*
* \param x the first value to compare.
* \param y the second value to compare.
* \returns the lesser of `x` and `y`.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
/**
* Return a value clamped to a range.
*
* If `x` is outside the range a values between `a` and `b`, the returned
* value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
*
* This macro will produce incorrect results if `b` is less than `a`.
*
* This is a helper macro that might be more clear than writing out the
* comparisons directly, and works with any type that can be compared with the
* `<` and `>` operators. However, it double-evaluates all its parameters, so
* do not use expressions with side-effects here.
*
* \param x the value to compare.
* \param a the low end value.
* \param b the high end value.
* \returns x, clamped between a and b.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
/**
* Query if a character is alphabetic (a letter).
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* for English 'a-z' and 'A-Z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
/**
* Query if a character is alphabetic (a letter) or a number.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* for English 'a-z', 'A-Z', and '0-9' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
/**
* Report if a character is blank (a space or tab).
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 0x20 (space) or 0x9 (tab) as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
/**
* Report if a character is a control character.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 0 through 0x1F, and 0x7F, as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
/**
* Report if a character is a numeric digit.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* '0' (0x30) through '9' (0x39), as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
/**
* Report if a character is a hexadecimal digit.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
/**
* Report if a character is a punctuation mark.
*
* **WARNING**: Regardless of system locale, this is equivalent to
* `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isgraph
* \sa SDL_isalnum
*/
extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
/**
* Report if a character is whitespace.
*
* **WARNING**: Regardless of system locale, this will only treat the
* following ASCII values as true:
*
* - space (0x20)
* - tab (0x09)
* - newline (0x0A)
* - vertical tab (0x0B)
* - form feed (0x0C)
* - return (0x0D)
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
/**
* Report if a character is upper case.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'A' through 'Z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
/**
* Report if a character is lower case.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* 'a' through 'z' as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
/**
* Report if a character is "printable".
*
* Be advised that "printable" has a definition that goes back to text
* terminals from the dawn of computing, making this a sort of special case
* function that is not suitable for Unicode (or most any) text management.
*
* **WARNING**: Regardless of system locale, this will only treat ASCII values
* ' ' (0x20) through '~' (0x7E) as true.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
/**
* Report if a character is any "printable" except space.
*
* Be advised that "printable" has a definition that goes back to text
* terminals from the dawn of computing, making this a sort of special case
* function that is not suitable for Unicode (or most any) text management.
*
* **WARNING**: Regardless of system locale, this is equivalent to
* `(SDL_isprint(x)) && ((x) != ' ')`.
*
* \param x character value to check.
* \returns non-zero if x falls within the character class, zero otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isprint
*/
extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
/**
* Convert low-ASCII English letters to uppercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'a' through 'z' to uppercase.
*
* This function returns the uppercase equivalent of `x`. If a character
* cannot be converted, or is already uppercase, this function returns `x`.
*
* \param x character value to check.
* \returns capitalized version of x, or x if no conversion available.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
/**
* Convert low-ASCII English letters to lowercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to lowercase.
*
* This function returns the lowercase equivalent of `x`. If a character
* cannot be converted, or is already lowercase, this function returns `x`.
*
* \param x character value to check.
* \returns lowercase version of x, or x if no conversion available.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
/**
* Calculate a CRC-16 value.
*
* https://en.wikipedia.org/wiki/Cyclic_redundancy_check
*
* This function can be called multiple times, to stream data to be
* checksummed in blocks. Each call must provide the previous CRC-16 return
* value to be updated with the next block. The first call to this function
* for a set of blocks should pass in a zero CRC value.
*
* \param crc the current checksum for this data set, or 0 for a new data set.
* \param data a new block of data to add to the checksum.
* \param len the size, in bytes, of the new block of data.
* \returns a CRC-16 checksum value of all blocks in the data set.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
/**
* Calculate a CRC-32 value.
*
* https://en.wikipedia.org/wiki/Cyclic_redundancy_check
*
* This function can be called multiple times, to stream data to be
* checksummed in blocks. Each call must provide the previous CRC-32 return
* value to be updated with the next block. The first call to this function
* for a set of blocks should pass in a zero CRC value.
*
* \param crc the current checksum for this data set, or 0 for a new data set.
* \param data a new block of data to add to the checksum.
* \param len the size, in bytes, of the new block of data.
* \returns a CRC-32 checksum value of all blocks in the data set.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
/**
* Calculate a 32-bit MurmurHash3 value for a block of data.
*
* https://en.wikipedia.org/wiki/MurmurHash
*
* A seed may be specified, which changes the final results consistently, but
* this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
* result from this function back into itself as the next seed value to
* calculate a hash in chunks; it won't produce the same hash as it would if
* the same data was provided in a single call.
*
* If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
* cryptographically secure, so it shouldn't be used for hashing top-secret
* data.
*
* \param data the data to be hashed.
* \param len the size of data, in bytes.
* \param seed a value that alters the final hash value.
* \returns a Murmur3 32-bit hash value.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
/**
* Copy non-overlapping memory.
*
* The memory regions must not overlap. If they do, use SDL_memmove() instead.
*
* \param dst The destination memory region. Must not be NULL, and must not
* overlap with `src`.
* \param src The source memory region. Must not be NULL, and must not overlap
* with `dst`.
* \param len The length in bytes of both `dst` and `src`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_memmove
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
/* Take advantage of compiler optimizations for memcpy */
#ifndef SDL_SLOW_MEMCPY
#ifdef SDL_memcpy
#undef SDL_memcpy
#endif
#define SDL_memcpy memcpy
#endif
/**
* A macro to copy memory between objects, with basic type checking.
*
* SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
* which can lead to bugs. This macro aims to avoid most of those bugs by
* making sure that the source and destination are both pointers to objects
* that are the same size. It does not check that the objects are the same
* _type_, just that the copy will not overflow either object.
*
* The size check happens at compile time, and the compiler will throw an
* error if the objects are different sizes.
*
* Generally this is intended to copy a single object, not an array.
*
* This macro looks like it double-evaluates its parameters, but the extras
* them are in `sizeof` sections, which generate no code nor side-effects.
*
* \param dst a pointer to the destination object. Must not be NULL.
* \param src a pointer to the source object. Must not be NULL.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
#define SDL_copyp(dst, src) \
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))
/**
* Copy memory ranges that might overlap.
*
* It is okay for the memory regions to overlap. If you are confident that the
* regions never overlap, using SDL_memcpy() may improve performance.
*
* \param dst The destination memory region. Must not be NULL.
* \param src The source memory region. Must not be NULL.
* \param len The length in bytes of both `dst` and `src`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_memcpy
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
/* Take advantage of compiler optimizations for memmove */
#ifndef SDL_SLOW_MEMMOVE
#ifdef SDL_memmove
#undef SDL_memmove
#endif
#define SDL_memmove memmove
#endif
/**
* Initialize all bytes of buffer of memory to a specific value.
*
* This function will set `len` bytes, pointed to by `dst`, to the value
* specified in `c`.
*
* Despite `c` being an `int` instead of a `char`, this only operates on
* bytes; `c` must be a value between 0 and 255, inclusive.
*
* \param dst the destination memory region. Must not be NULL.
* \param c the byte value to set.
* \param len the length, in bytes, to set in `dst`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
/**
* Initialize all 32-bit words of buffer of memory to a specific value.
*
* This function will set a buffer of `dwords` Uint32 values, pointed to by
* `dst`, to the value specified in `val`.
*
* Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
* to a range of 0-255.
*
* \param dst the destination memory region. Must not be NULL.
* \param val the Uint32 value to set.
* \param dwords the number of Uint32 values to set in `dst`.
* \returns `dst`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
/* Take advantage of compiler optimizations for memset */
#ifndef SDL_SLOW_MEMSET
#ifdef SDL_memset
#undef SDL_memset
#endif
#define SDL_memset memset
#endif
/**
* Clear an object's memory to zero.
*
* This is wrapper over SDL_memset that handles calculating the object size,
* so there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires an object, not a pointer to an object, nor an array.
*
* \param x the object to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_zerop
* \sa SDL_zeroa
*/
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
/**
* Clear an object's memory to zero, using a pointer.
*
* This is wrapper over SDL_memset that handles calculating the object size,
* so there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires a pointer to an object, not an object itself, nor an array.
*
* \param x a pointer to the object to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_zero
* \sa SDL_zeroa
*/
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
/**
* Clear an array's memory to zero.
*
* This is wrapper over SDL_memset that handles calculating the array size, so
* there's no chance of copy/paste errors, and the code is cleaner.
*
* This requires an array, not an object, nor a pointer to an object.
*
* \param x an array to clear.
*
* \threadsafety It is safe to call this macro from any thread.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_zero
* \sa SDL_zeroa
*/
#define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
/**
* Compare two buffers of memory.
*
* \param s1 the first buffer to compare. NULL is not permitted!
* \param s2 the second buffer to compare. NULL is not permitted!
* \param len the number of bytes to compare between the buffers.
* \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
* "greater than" s2, and zero if the buffers match exactly for `len`
* bytes.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
/**
* This works exactly like wcslen() but doesn't require access to a C runtime.
*
* Counts the number of wchar_t values in `wstr`, excluding the null
* terminator.
*
* Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
* this counts wchar_t values in a string, even if the string's encoding is of
* variable width, like UTF-16.
*
* Also be aware that wchar_t is different sizes on different platforms (4
* bytes on Linux, 2 on Windows, etc).
*
* \param wstr The null-terminated wide string to read. Must not be NULL.
* \returns the length (in wchar_t values, excluding the null terminator) of
* `wstr`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_wcsnlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
/**
* This works exactly like wcsnlen() but doesn't require access to a C
* runtime.
*
* Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
* null terminator.
*
* Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
* this counts wchar_t values in a string, even if the string's encoding is of
* variable width, like UTF-16.
*
* Also be aware that wchar_t is different sizes on different platforms (4
* bytes on Linux, 2 on Windows, etc).
*
* Also, `maxlen` is a count of wide characters, not bytes!
*
* \param wstr The null-terminated wide string to read. Must not be NULL.
* \param maxlen The maximum amount of wide characters to count.
* \returns the length (in wide characters, excluding the null terminator) of
* `wstr` but never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_wcslen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
/**
* Copy a wide string.
*
* This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
* appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` is 0, no wide characters are copied and no null terminator is
* written.
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated wide string to copy. Must not be NULL, and
* must not overlap with `dst`.
* \param maxlen The length (in wide characters) of the destination buffer.
* \returns the length (in wide characters, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_wcslcat
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
/**
* Concatenate wide strings.
*
* This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
* from `src` to the end of the wide string in `dst`, then appends a null
* terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
* unmodified.
*
* \param dst The destination buffer already containing the first
* null-terminated wide string. Must not be NULL and must not
* overlap with `src`.
* \param src The second null-terminated wide string. Must not be NULL, and
* must not overlap with `dst`.
* \param maxlen The length (in wide characters) of the destination buffer.
* \returns the length (in wide characters, excluding the null terminator) of
* the string in `dst` plus the length of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_wcslcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
/**
* Allocate a copy of a wide string.
*
* This allocates enough space for a null-terminated copy of `wstr`, using
* SDL_malloc, and then makes a copy of the string into this space.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param wstr the string to copy.
* \returns a pointer to the newly-allocated wide string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
/**
* Search a wide string for the first instance of a specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string.
*
* Note that this looks for strings of _wide characters_, not _codepoints_, so
* it's legal to search for malformed and incomplete UTF-16 sequences.
*
* \param haystack the wide string to search. Must not be NULL.
* \param needle the wide string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
/**
* Search a wide string, up to n wide chars, for the first instance of a
* specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* value to end the string, or `maxlen` wide character have been examined. It
* is possible to use this function on a wide string without a null
* terminator.
*
* Note that this looks for strings of _wide characters_, not _codepoints_, so
* it's legal to search for malformed and incomplete UTF-16 sequences.
*
* \param haystack the wide string to search. Must not be NULL.
* \param needle the wide string to search for. Must not be NULL.
* \param maxlen the maximum number of wide characters to search in
* `haystack`.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
/**
* Compare two null-terminated wide strings.
*
* This only compares wchar_t values until it hits a null-terminating
* character; it does not care if the string is well-formed UTF-16 (or UTF-32,
* depending on your platform's wchar_t size), or uses valid Unicode values.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
/**
* Compare two wide strings up to a number of wchar_t values.
*
* This only compares wchar_t values; it does not care if the string is
* well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
* or uses valid Unicode values.
*
* Note that while this function is intended to be used with UTF-16 (or
* UTF-32, depending on your platform's definition of wchar_t), it is
* comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
* a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
* sequence, it will only compare a portion of the final character.
*
* `maxlen` specifies a maximum number of wchar_t to compare; if the strings
* match to this number of wide chars (or both have matched to a
* null-terminator character before this count), they will be considered
* equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of wchar_t to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
/**
* Compare two null-terminated wide strings, case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
* UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
* handles Unicode, it expects the string to be well-formed and not a
* null-terminated string of arbitrary bytes. Characters that are not valid
* UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
/**
* Compare two wide strings, case-insensitively, up to a number of wchar_t.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
* UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
* handles Unicode, it expects the string to be well-formed and not a
* null-terminated string of arbitrary bytes. Characters that are not valid
* UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* Note that while this function might deal with variable-sized characters,
* `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
* multi-byte UTF-16 sequence, it may convert a portion of the final character
* to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
* to overflow a buffer.
*
* `maxlen` specifies a maximum number of wchar_t values to compare; if the
* strings match to this number of wchar_t (or both have matched to a
* null-terminator character before this number of bytes), they will be
* considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of wchar_t values to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
/**
* Parse a `long` from a wide string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long`, the result is clamped to
* the minimum and maximum representable `long` values.
*
* \param str The null-terminated wide string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid wide character
* (i.e. the next character after the parsed number) will be
* written to this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strtol
*/
extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
/**
* This works exactly like strlen() but doesn't require access to a C runtime.
*
* Counts the bytes in `str`, excluding the null terminator.
*
* If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the length (in bytes, excluding the null terminator) of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strnlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
/**
* This works exactly like strnlen() but doesn't require access to a C
* runtime.
*
* Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
* terminator.
*
* If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
*
* \param str The null-terminated string to read. Must not be NULL.
* \param maxlen The maximum amount of bytes to count.
* \returns the length (in bytes, excluding the null terminator) of `src` but
* never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strlen
* \sa SDL_utf8strlen
* \sa SDL_utf8strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
/**
* Copy a string.
*
* This function copies up to `maxlen` - 1 characters from `src` to `dst`,
* then appends a null terminator.
*
* If `maxlen` is 0, no characters are copied and no null terminator is
* written.
*
* If you want to copy an UTF-8 string but need to ensure that multi-byte
* sequences are not truncated, consider using SDL_utf8strlcpy().
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated string to copy. Must not be NULL, and must
* not overlap with `dst`.
* \param maxlen The length (in characters) of the destination buffer.
* \returns the length (in characters, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strlcat
* \sa SDL_utf8strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
/**
* Copy an UTF-8 string.
*
* This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
* also ensuring that the string written to `dst` does not end in a truncated
* multi-byte sequence. Finally, it appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* Note that unlike SDL_strlcpy(), this function returns the number of bytes
* written, not the length of `src`.
*
* \param dst The destination buffer. Must not be NULL, and must not overlap
* with `src`.
* \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
* must not overlap with `dst`.
* \param dst_bytes The length (in bytes) of the destination buffer. Must not
* be 0.
* \returns the number of bytes written, excluding the null terminator.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
/**
* Concatenate strings.
*
* This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
* `src` to the end of the string in `dst`, then appends a null terminator.
*
* `src` and `dst` must not overlap.
*
* If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
* unmodified.
*
* \param dst The destination buffer already containing the first
* null-terminated string. Must not be NULL and must not overlap
* with `src`.
* \param src The second null-terminated string. Must not be NULL, and must
* not overlap with `dst`.
* \param maxlen The length (in characters) of the destination buffer.
* \returns the length (in characters, excluding the null terminator) of the
* string in `dst` plus the length of `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strlcpy
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
/**
* Allocate a copy of a string.
*
* This allocates enough space for a null-terminated copy of `str`, using
* SDL_malloc, and then makes a copy of the string into this space.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param str the string to copy.
* \returns a pointer to the newly-allocated string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
/**
* Allocate a copy of a string, up to n characters.
*
* This allocates enough space for a null-terminated copy of `str`, up to
* `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
* this space.
*
* If the string is longer than `maxlen` bytes, the returned string will be
* `maxlen` bytes long, plus a null-terminator character that isn't included
* in the count.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param str the string to copy.
* \param maxlen the maximum length of the copied string, not counting the
* null-terminator character.
* \returns a pointer to the newly-allocated string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
/**
* Reverse a string's contents.
*
* This reverses a null-terminated string in-place. Only the content of the
* string is reversed; the null-terminator character remains at the end of the
* reversed string.
*
* **WARNING**: This function reverses the _bytes_ of the string, not the
* codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
* will ruin the string data. You should only use this function on strings
* that are completely comprised of low ASCII characters.
*
* \param str the string to reverse.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
/**
* Convert a string to uppercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to uppercase.
*
* This function operates on a null-terminated string of bytes--even if it is
* malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
* uppercase equivalents in-place, returning the original `str` pointer.
*
* \param str the string to convert in-place. Can not be NULL.
* \returns the `str` pointer passed into this function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strlwr
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
/**
* Convert a string to lowercase.
*
* **WARNING**: Regardless of system locale, this will only convert ASCII
* values 'A' through 'Z' to lowercase.
*
* This function operates on a null-terminated string of bytes--even if it is
* malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
* lowercase equivalents in-place, returning the original `str` pointer.
*
* \param str the string to convert in-place. Can not be NULL.
* \returns the `str` pointer passed into this function.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_strupr
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
/**
* Search a string for the first instance of a specific byte.
*
* The search ends once it finds the requested byte value, or a null
* terminator byte to end the string.
*
* Note that this looks for _bytes_, not _characters_, so you cannot match
* against a Unicode codepoint > 255, regardless of character encoding.
*
* \param str the string to search. Must not be NULL.
* \param c the byte value to search for.
* \returns a pointer to the first instance of `c` in the string, or NULL if
* not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
/**
* Search a string for the last instance of a specific byte.
*
* The search must go until it finds a null terminator byte to end the string.
*
* Note that this looks for _bytes_, not _characters_, so you cannot match
* against a Unicode codepoint > 255, regardless of character encoding.
*
* \param str the string to search. Must not be NULL.
* \param c the byte value to search for.
* \returns a pointer to the last instance of `c` in the string, or NULL if
* not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
/**
* Search a string for the first instance of a specific substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string.
*
* Note that this looks for strings of _bytes_, not _characters_, so it's
* legal to search for malformed and incomplete UTF-8 sequences.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
/**
* Search a string, up to n bytes, for the first instance of a specific
* substring.
*
* The search ends once it finds the requested substring, or a null terminator
* byte to end the string, or `maxlen` bytes have been examined. It is
* possible to use this function on a string without a null terminator.
*
* Note that this looks for strings of _bytes_, not _characters_, so it's
* legal to search for malformed and incomplete UTF-8 sequences.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \param maxlen the maximum number of bytes to search in `haystack`.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
/**
* Search a UTF-8 string for the first instance of a specific substring,
* case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param haystack the string to search. Must not be NULL.
* \param needle the string to search for. Must not be NULL.
* \returns a pointer to the first instance of `needle` in the string, or NULL
* if not found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
/**
* This works exactly like strtok_r() but doesn't require access to a C
* runtime.
*
* Break a string up into a series of tokens.
*
* To start tokenizing a new string, `str` should be the non-NULL address of
* the string to start tokenizing. Future calls to get the next token from the
* same string should specify a NULL.
*
* Note that this function will overwrite pieces of `str` with null chars to
* split it into tokens. This function cannot be used with const/read-only
* strings!
*
* `saveptr` just needs to point to a `char *` that can be overwritten; SDL
* will use this to save tokenizing state between calls. It is initialized if
* `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
*
* \param str the string to tokenize, or NULL to continue tokenizing.
* \param delim the delimiter string that separates tokens.
* \param saveptr pointer to a char *, used for ongoing state.
* \returns A pointer to the next token, or NULL if no tokens remain.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
/**
* Count the number of codepoints in a UTF-8 string.
*
* Counts the _codepoints_, not _bytes_, in `str`, excluding the null
* terminator.
*
* If you need to count the bytes in a string instead, consider using
* SDL_strlen().
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
* count by several replacement characters.
*
* \param str The null-terminated UTF-8 string to read. Must not be NULL.
* \returns The length (in codepoints, excluding the null terminator) of
* `src`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_utf8strnlen
* \sa SDL_strlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
/**
* Count the number of codepoints in a UTF-8 string, up to n bytes.
*
* Counts the _codepoints_, not _bytes_, in `str`, excluding the null
* terminator.
*
* If you need to count the bytes in a string instead, consider using
* SDL_strnlen().
*
* The counting stops at `bytes` bytes (not codepoints!). This seems
* counterintuitive, but makes it easy to express the total size of the
* string's buffer.
*
* Since this handles Unicode, it expects the strings to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
* count by several replacement characters.
*
* \param str The null-terminated UTF-8 string to read. Must not be NULL.
* \param bytes The maximum amount of bytes to count.
* \returns The length (in codepoints, excluding the null terminator) of `src`
* but never more than `maxlen`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_utf8strlen
* \sa SDL_strnlen
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
/**
* Convert an integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_uitoa
* \sa SDL_ltoa
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
/**
* Convert an unsigned integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_itoa
* \sa SDL_ultoa
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
/**
* Convert a long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_ultoa
* \sa SDL_itoa
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
/**
* Convert an unsigned long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_ltoa
* \sa SDL_uitoa
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
/**
* Convert a long long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget possible negative
* signs, null terminator bytes, etc).
*
* \param value the long long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_ulltoa
* \sa SDL_itoa
* \sa SDL_ltoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
/**
* Convert an unsigned long long integer into a string.
*
* This requires a radix to specified for string format. Specifying 10
* produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
* to 36.
*
* Note that this function will overflow a buffer if `str` is not large enough
* to hold the output! It may be safer to use SDL_snprintf to clamp output, or
* SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
* much more space than you expect to use (and don't forget null terminator
* bytes, etc).
*
* \param value the unsigned long long integer to convert.
* \param str the buffer to write the string into.
* \param radix the radix to use for string generation.
* \returns `str`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_lltoa
* \sa SDL_uitoa
* \sa SDL_ultoa
*/
extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
/**
* Parse an `int` from a string.
*
* The result of calling `SDL_atoi(str)` is equivalent to
* `(int)SDL_strtol(str, NULL, 10)`.
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the parsed `int`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_itoa
*/
extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
/**
* Parse a `double` from a string.
*
* The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
* NULL)`.
*
* \param str The null-terminated string to read. Must not be NULL.
* \returns the parsed `double`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
*/
extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
/**
* Parse a `long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long`, the result is clamped to
* the minimum and maximum representable `long` values.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtoul
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_ltoa
* \sa SDL_wcstol
*/
extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
/**
* Parse an `unsigned long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside an `unsigned long`, the result is
* clamped to the maximum representable `unsigned long` value.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `unsigned long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_ultoa
*/
extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
/**
* Parse a `long long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside a `long long`, the result is
* clamped to the minimum and maximum representable `long long` values.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `long long`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoul
* \sa SDL_strtoull
* \sa SDL_strtod
* \sa SDL_lltoa
*/
extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
/**
* Parse an `unsigned long long` from a string.
*
* If `str` starts with whitespace, then those whitespace characters are
* skipped before attempting to parse the number.
*
* If the parsed number does not fit inside an `unsigned long long`, the
* result is clamped to the maximum representable `unsigned long long` value.
*
* \param str The null-terminated string to read. Must not be NULL.
* \param endp If not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \param base The base of the integer to read. Supported values are 0 and 2
* to 36 inclusive. If 0, the base will be inferred from the
* number's prefix (0x for hexadecimal, 0 for octal, decimal
* otherwise).
* \returns the parsed `unsigned long long`, or 0 if no number could be
* parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoul
* \sa SDL_strtod
* \sa SDL_ulltoa
*/
extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
/**
* Parse a `double` from a string.
*
* This function makes fewer guarantees than the C runtime `strtod`:
*
* - Only decimal notation is guaranteed to be supported. The handling of
* scientific and hexadecimal notation is unspecified.
* - Whether or not INF and NAN can be parsed is unspecified.
* - The precision of the result is unspecified.
*
* \param str the null-terminated string to read. Must not be NULL.
* \param endp if not NULL, the address of the first invalid character (i.e.
* the next character after the parsed number) will be written to
* this pointer.
* \returns the parsed `double`, or 0 if no number could be parsed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atoi
* \sa SDL_atof
* \sa SDL_strtol
* \sa SDL_strtoll
* \sa SDL_strtoul
* \sa SDL_strtoull
*/
extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
/**
* Compare two null-terminated UTF-8 strings.
*
* Due to the nature of UTF-8 encoding, this will work with Unicode strings,
* since effectively this function just compares bytes until it hits a
* null-terminating character. Also due to the nature of UTF-8, this can be
* used with SDL_qsort() to put strings in (roughly) alphabetical order.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
/**
* Compare two UTF-8 strings up to a number of bytes.
*
* Due to the nature of UTF-8 encoding, this will work with Unicode strings,
* since effectively this function just compares bytes until it hits a
* null-terminating character. Also due to the nature of UTF-8, this can be
* used with SDL_qsort() to put strings in (roughly) alphabetical order.
*
* Note that while this function is intended to be used with UTF-8, it is
* doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
* limit lands in the middle of a multi-byte UTF-8 sequence, it will only
* compare a portion of the final character.
*
* `maxlen` specifies a maximum number of bytes to compare; if the strings
* match to this number of bytes (or both have matched to a null-terminator
* character before this number of bytes), they will be considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of _bytes_ to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
/**
* Compare two null-terminated UTF-8 strings, case-insensitively.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the string to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
/**
* Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
*
* This will work with Unicode strings, using a technique called
* "case-folding" to handle the vast majority of case-sensitive human
* languages regardless of system locale. It can deal with expanding values: a
* German Eszett character can compare against two ASCII 's' chars and be
* considered a match, for example. A notable exception: it does not handle
* the Turkish 'i' character; human language is complicated!
*
* Since this handles Unicode, it expects the string to be well-formed UTF-8
* and not a null-terminated string of arbitrary bytes. Bytes that are not
* valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
* CHARACTER), which is to say two strings of random bits may turn out to
* match if they convert to the same amount of replacement characters.
*
* Note that while this function is intended to be used with UTF-8, `maxlen`
* specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
* UTF-8 sequence, it may convert a portion of the final character to one or
* more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
* a buffer.
*
* `maxlen` specifies a maximum number of bytes to compare; if the strings
* match to this number of bytes (or both have matched to a null-terminator
* character before this number of bytes), they will be considered equal.
*
* \param str1 the first string to compare. NULL is not permitted!
* \param str2 the second string to compare. NULL is not permitted!
* \param maxlen the maximum number of bytes to compare.
* \returns less than zero if str1 is "less than" str2, greater than zero if
* str1 is "greater than" str2, and zero if the strings match
* exactly.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
/**
* Searches a string for the first occurence of any character contained in a
* breakset, and returns a pointer from the string to that character.
*
* \param str The null-terminated string to be searched. Must not be NULL, and
* must not overlap with `breakset`.
* \param breakset A null-terminated string containing the list of characters
* to look for. Must not be NULL, and must not overlap with
* `str`.
* \returns A pointer to the location, in str, of the first occurence of a
* character present in the breakset, or NULL if none is found.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
/**
* The Unicode REPLACEMENT CHARACTER codepoint.
*
* SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
* encounter a UTF-8 string with encoding errors.
*
* This tends to render as something like a question mark in most places.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_StepBackUTF8
* \sa SDL_StepUTF8
*/
#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
/**
* Decode a UTF-8 string, one Unicode codepoint at a time.
*
* This will return the first Unicode codepoint in the UTF-8 encoded string in
* `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
*
* It will not access more than `*pslen` bytes from the string. `*pslen` will
* be adjusted, as well, subtracting the number of bytes consumed.
*
* `pslen` is allowed to be NULL, in which case the string _must_ be
* NULL-terminated, as the function will blindly read until it sees the NULL
* char.
*
* if `*pslen` is zero, it assumes the end of string is reached and returns a
* zero codepoint regardless of the contents of the string buffer.
*
* If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
* zero, it will not advance `*pstr` or `*pslen` at all.
*
* Generally this function is called in a loop until it returns zero,
* adjusting its parameters each iteration.
*
* If an invalid UTF-8 sequence is encountered, this function returns
* SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
* (which is to say, a multibyte sequence might produce several
* SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
* UTF-8 sequence).
*
* Several things can generate invalid UTF-8 sequences, including overlong
* encodings, the use of UTF-16 surrogate values, and truncated data. Please
* refer to
* [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
* for details.
*
* \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
* \param pslen a pointer to the number of bytes in the string, to be read and
* adjusted. NULL is allowed.
* \returns the first Unicode codepoint in the string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
/**
* Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
*
* This will go to the start of the previous Unicode codepoint in the string,
* move `*pstr` to that location and return that codepoint.
*
* If `*pstr` is already at the start of the string), it will not advance
* `*pstr` at all.
*
* Generally this function is called in a loop until it returns zero,
* adjusting its parameter each iteration.
*
* If an invalid UTF-8 sequence is encountered, this function returns
* SDL_INVALID_UNICODE_CODEPOINT.
*
* Several things can generate invalid UTF-8 sequences, including overlong
* encodings, the use of UTF-16 surrogate values, and truncated data. Please
* refer to
* [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
* for details.
*
* \param start a pointer to the beginning of the UTF-8 string.
* \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
* \returns the previous Unicode codepoint in the string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.6.
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
/**
* Convert a single Unicode codepoint to UTF-8.
*
* The buffer pointed to by `dst` must be at least 4 bytes long, as this
* function may generate between 1 and 4 bytes of output.
*
* This function returns the first byte _after_ the newly-written UTF-8
* sequence, which is useful for encoding multiple codepoints in a loop, or
* knowing where to write a NULL-terminator character to end the string (in
* either case, plan to have a buffer of _more_ than 4 bytes!).
*
* If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
* surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
* codepoint instead, and not set an error.
*
* If `dst` is NULL, this returns NULL immediately without writing to the
* pointer and without setting an error.
*
* \param codepoint a Unicode codepoint to convert to UTF-8.
* \param dst the location to write the encoded UTF-8. Must point to at least
* 4 bytes!
* \returns the first byte past the newly-written UTF-8 sequence.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
/**
* This works exactly like sscanf() but doesn't require access to a C runtime.
*
* Scan a string, matching a format string, converting each '%' item and
* storing it to pointers provided through variable arguments.
*
* \param text the string to scan. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of pointers to values to be filled in with scanned items.
* \returns the number of items that matched the format string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
/**
* This works exactly like vsscanf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_sscanf(), except it takes a `va_list` instead
* of using `...` variable arguments.
*
* \param text the string to scan. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` of pointers to values to be filled in with scanned
* items.
* \returns the number of items that matched the format string.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
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);
/**
* This works exactly like snprintf() but doesn't require access to a C
* runtime.
*
* Format a string of up to `maxlen`-1 bytes, converting each '%' item with
* values provided through variable arguments.
*
* While some C runtimes differ on how to deal with too-large strings, this
* function null-terminates the output, by treating the null-terminator as
* part of the `maxlen` count. Note that if `maxlen` is zero, however, no
* bytes will be written at all.
*
* This function returns the number of _bytes_ (not _characters_) that should
* be written, excluding the null-terminator character. If this returns a
* number >= `maxlen`, it means the output string was truncated. A negative
* return value means an error occurred.
*
* Referencing the output string's pointer with a format item is undefined
* behavior.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum bytes to write, including the null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of bytes that should be written, not counting the
* null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
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);
/**
* This works exactly like swprintf() but doesn't require access to a C
* runtime.
*
* Format a wide string of up to `maxlen`-1 wchar_t values, converting each
* '%' item with values provided through variable arguments.
*
* While some C runtimes differ on how to deal with too-large strings, this
* function null-terminates the output, by treating the null-terminator as
* part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
* characters will be written at all.
*
* This function returns the number of _wide characters_ (not _codepoints_)
* that should be written, excluding the null-terminator character. If this
* returns a number >= `maxlen`, it means the output string was truncated. A
* negative return value means an error occurred.
*
* Referencing the output string's pointer with a format item is undefined
* behavior.
*
* \param text the buffer to write the wide string into. Must not be NULL.
* \param maxlen the maximum wchar_t values to write, including the
* null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of wide characters that should be written, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
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);
/**
* This works exactly like vsnprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_snprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum bytes to write, including the null-terminator.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of bytes that should be written, not counting the
* null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
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);
/**
* This works exactly like vswprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_swprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param text the buffer to write the string into. Must not be NULL.
* \param maxlen the maximum wide characters to write, including the
* null-terminator.
* \param fmt a printf-style format wide string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of wide characters that should be written, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
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);
/**
* This works exactly like asprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_snprintf(), except it allocates a buffer large
* enough to hold the output string on behalf of the caller.
*
* On success, this function returns the number of bytes (not characters)
* comprising the output string, not counting the null-terminator character,
* and sets `*strp` to the newly-allocated string.
*
* On error, this function returns a negative number, and the value of `*strp`
* is undefined.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param strp on output, is set to the new string. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ... a list of values to be used with the format string.
* \returns the number of bytes in the newly-allocated string, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/**
* This works exactly like vasprintf() but doesn't require access to a C
* runtime.
*
* Functions identically to SDL_asprintf(), except it takes a `va_list`
* instead of using `...` variable arguments.
*
* \param strp on output, is set to the new string. Must not be NULL.
* \param fmt a printf-style format string. Must not be NULL.
* \param ap a `va_list` values to be used with the format string.
* \returns the number of bytes in the newly-allocated string, not counting
* the null-terminator char, or a negative value on error.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
/**
* Seeds the pseudo-random number generator.
*
* Reusing the seed number will cause SDL_rand_*() to repeat the same stream
* of 'random' numbers.
*
* \param seed the value to use as a random number seed, or 0 to use
* SDL_GetPerformanceCounter().
*
* \threadsafety This should be called on the same thread that calls
* SDL_rand*()
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_rand
* \sa SDL_rand_bits
* \sa SDL_randf
*/
extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
/**
* Generate a pseudo-random number less than n for positive n
*
* The method used is faster and of better quality than `rand() % n`. Odds are
* roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
* much worse as n gets bigger.
*
* Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
* 1..6
*
* If you want to generate a pseudo-random number in the full range of Sint32,
* you should use: (Sint32)SDL_rand_bits()
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param n the number of possible outcomes. n must be positive.
* \returns a random value in the range of [0 .. n-1].
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_srand
* \sa SDL_randf
*/
extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
/**
* Generate a uniform pseudo-random floating point number less than 1.0
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \returns a random value in the range of [0.0, 1.0).
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_srand
* \sa SDL_rand
*/
extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
/**
* Generate 32 pseudo-random bits.
*
* You likely want to use SDL_rand() to get a psuedo-random number instead.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \returns a random value in the range of [0-SDL_MAX_UINT32].
*
* \threadsafety All calls should be made from a single thread
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_rand
* \sa SDL_randf
* \sa SDL_srand
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
/**
* Generate a pseudo-random number less than n for positive n
*
* The method used is faster and of better quality than `rand() % n`. Odds are
* roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
* much worse as n gets bigger.
*
* Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
* 0..5 to 1..6
*
* If you want to generate a pseudo-random number in the full range of Sint32,
* you should use: (Sint32)SDL_rand_bits_r(state)
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \param n the number of possible outcomes. n must be positive.
* \returns a random value in the range of [0 .. n-1].
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_rand
* \sa SDL_rand_bits_r
* \sa SDL_randf_r
*/
extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
/**
* Generate a uniform pseudo-random floating point number less than 1.0
*
* If you want reproducible output, be sure to initialize with SDL_srand()
* first.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \returns a random value in the range of [0.0, 1.0).
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_rand_bits_r
* \sa SDL_rand_r
* \sa SDL_randf
*/
extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
/**
* Generate 32 pseudo-random bits.
*
* You likely want to use SDL_rand_r() to get a psuedo-random number instead.
*
* There are no guarantees as to the quality of the random sequence produced,
* and this should not be used for security (cryptography, passwords) or where
* money is on the line (loot-boxes, casinos). There are many random number
* libraries available with different characteristics and you should pick one
* of those to meet any serious needs.
*
* \param state a pointer to the current random number state, this may not be
* NULL.
* \returns a random value in the range of [0-SDL_MAX_UINT32].
*
* \threadsafety This function is thread-safe, as long as the state pointer
* isn't shared between threads.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_rand_r
* \sa SDL_randf_r
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
#ifndef SDL_PI_D
/**
* The value of Pi, as a double-precision floating point literal.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_PI_F
*/
#define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
#endif
#ifndef SDL_PI_F
/**
* The value of Pi, as a single-precision floating point literal.
*
* \since This macro is available since SDL 3.1.3.
*
* \sa SDL_PI_D
*/
#define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
#endif
/**
* Compute the arc cosine of `x`.
*
* The definition of `y = acos(x)` is `x = cos(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `0 <= y <= Pi`
*
* This function operates on double-precision floating point values, use
* SDL_acosf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc cosine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_acosf
* \sa SDL_asin
* \sa SDL_cos
*/
extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
/**
* Compute the arc cosine of `x`.
*
* The definition of `y = acos(x)` is `x = cos(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `0 <= y <= Pi`
*
* This function operates on single-precision floating point values, use
* SDL_acos for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc cosine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_acos
* \sa SDL_asinf
* \sa SDL_cosf
*/
extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
/**
* Compute the arc sine of `x`.
*
* The definition of `y = asin(x)` is `x = sin(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on double-precision floating point values, use
* SDL_asinf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc sine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_asinf
* \sa SDL_acos
* \sa SDL_sin
*/
extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
/**
* Compute the arc sine of `x`.
*
* The definition of `y = asin(x)` is `x = sin(y)`.
*
* Domain: `-1 <= x <= 1`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on single-precision floating point values, use
* SDL_asin for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc sine of `x`, in radians.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_asin
* \sa SDL_acosf
* \sa SDL_sinf
*/
extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
/**
* Compute the arc tangent of `x`.
*
* The definition of `y = atan(x)` is `x = tan(y)`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on double-precision floating point values, use
* SDL_atanf for single-precision floats.
*
* To calculate the arc tangent of y / x, use SDL_atan2.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atanf
* \sa SDL_atan2
* \sa SDL_tan
*/
extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
/**
* Compute the arc tangent of `x`.
*
* The definition of `y = atan(x)` is `x = tan(y)`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on single-precision floating point values, use
* SDL_atan for dboule-precision floats.
*
* To calculate the arc tangent of y / x, use SDL_atan2f.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atan
* \sa SDL_atan2f
* \sa SDL_tanf
*/
extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
/**
* Compute the arc tangent of `y / x`, using the signs of x and y to adjust
* the result's quadrant.
*
* The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
* of z is determined based on the signs of x and y.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on double-precision floating point values, use
* SDL_atan2f for single-precision floats.
*
* To calculate the arc tangent of a single value, use SDL_atan.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param y floating point value of the numerator (y coordinate).
* \param x floating point value of the denominator (x coordinate).
* \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
* `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atan2f
* \sa SDL_atan
* \sa SDL_tan
*/
extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
/**
* Compute the arc tangent of `y / x`, using the signs of x and y to adjust
* the result's quadrant.
*
* The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
* of z is determined based on the signs of x and y.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-Pi/2 <= y <= Pi/2`
*
* This function operates on single-precision floating point values, use
* SDL_atan2 for double-precision floats.
*
* To calculate the arc tangent of a single value, use SDL_atanf.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param y floating point value of the numerator (y coordinate).
* \param x floating point value of the denominator (x coordinate).
* \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
* `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_atan2f
* \sa SDL_atan
* \sa SDL_tan
*/
extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
/**
* Compute the ceiling of `x`.
*
* The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_ceilf for single-precision floats.
*
* \param x floating point value.
* \returns the ceiling of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_ceilf
* \sa SDL_floor
* \sa SDL_trunc
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
/**
* Compute the ceiling of `x`.
*
* The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
* rounded up to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_ceil for double-precision floats.
*
* \param x floating point value.
* \returns the ceiling of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_ceil
* \sa SDL_floorf
* \sa SDL_truncf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
/**
* Copy the sign of one floating-point value to another.
*
* The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
*
* Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
*
* Range: `-INF <= z <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_copysignf for single-precision floats.
*
* \param x floating point value to use as the magnitude.
* \param y floating point value to use as the sign.
* \returns the floating point value with the sign of y and the magnitude of
* x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_copysignf
* \sa SDL_fabs
*/
extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
/**
* Copy the sign of one floating-point value to another.
*
* The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
*
* Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
*
* Range: `-INF <= z <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_copysign for double-precision floats.
*
* \param x floating point value to use as the magnitude.
* \param y floating point value to use as the sign.
* \returns the floating point value with the sign of y and the magnitude of
* x.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_copysignf
* \sa SDL_fabsf
*/
extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
/**
* Compute the cosine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on double-precision floating point values, use
* SDL_cosf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns cosine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_cosf
* \sa SDL_acos
* \sa SDL_sin
*/
extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
/**
* Compute the cosine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on single-precision floating point values, use
* SDL_cos for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns cosine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_cos
* \sa SDL_acosf
* \sa SDL_sinf
*/
extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
/**
* Compute the exponential of `x`.
*
* The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
* natural logarithm. The inverse is the natural logarithm, SDL_log.
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* The output will overflow if `exp(x)` is too large to be represented.
*
* This function operates on double-precision floating point values, use
* SDL_expf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns value of `e^x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_expf
* \sa SDL_log
*/
extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
/**
* Compute the exponential of `x`.
*
* The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
* natural logarithm. The inverse is the natural logarithm, SDL_logf.
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* The output will overflow if `exp(x)` is too large to be represented.
*
* This function operates on single-precision floating point values, use
* SDL_exp for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value.
* \returns value of `e^x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_exp
* \sa SDL_logf
*/
extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
/**
* Compute the absolute value of `x`
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_copysignf for single-precision floats.
*
* \param x floating point value to use as the magnitude.
* \returns the absolute value of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_fabsf
*/
extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
/**
* Compute the absolute value of `x`
*
* Domain: `-INF <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_copysignf for double-precision floats.
*
* \param x floating point value to use as the magnitude.
* \returns the absolute value of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_fabs
*/
extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
/**
* Compute the floor of `x`.
*
* The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_floorf for single-precision floats.
*
* \param x floating point value.
* \returns the floor of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_floorf
* \sa SDL_ceil
* \sa SDL_trunc
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
/**
* Compute the floor of `x`.
*
* The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
* rounded down to the nearest integer.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_floorf for double-precision floats.
*
* \param x floating point value.
* \returns the floor of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_floor
* \sa SDL_ceilf
* \sa SDL_truncf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
/**
* Truncate `x` to an integer.
*
* Rounds `x` to the next closest integer to 0. This is equivalent to removing
* the fractional part of `x`, leaving only the integer part.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_truncf for single-precision floats.
*
* \param x floating point value.
* \returns `x` truncated to an integer.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_truncf
* \sa SDL_fmod
* \sa SDL_ceil
* \sa SDL_floor
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
/**
* Truncate `x` to an integer.
*
* Rounds `x` to the next closest integer to 0. This is equivalent to removing
* the fractional part of `x`, leaving only the integer part.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on single-precision floating point values, use
* SDL_truncf for double-precision floats.
*
* \param x floating point value.
* \returns `x` truncated to an integer.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_trunc
* \sa SDL_fmodf
* \sa SDL_ceilf
* \sa SDL_floorf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
/**
* Return the floating-point remainder of `x / y`
*
* Divides `x` by `y`, and returns the remainder.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
*
* Range: `-y <= z <= y`
*
* This function operates on double-precision floating point values, use
* SDL_fmodf for single-precision floats.
*
* \param x the numerator.
* \param y the denominator. Must not be 0.
* \returns the remainder of `x / y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_fmodf
* \sa SDL_modf
* \sa SDL_trunc
* \sa SDL_ceil
* \sa SDL_floor
* \sa SDL_round
* \sa SDL_lround
*/
extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
/**
* Return the floating-point remainder of `x / y`
*
* Divides `x` by `y`, and returns the remainder.
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
*
* Range: `-y <= z <= y`
*
* This function operates on single-precision floating point values, use
* SDL_fmod for single-precision floats.
*
* \param x the numerator.
* \param y the denominator. Must not be 0.
* \returns the remainder of `x / y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_fmod
* \sa SDL_truncf
* \sa SDL_modff
* \sa SDL_ceilf
* \sa SDL_floorf
* \sa SDL_roundf
* \sa SDL_lroundf
*/
extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
/**
* Return whether the value is infinity.
*
* \param x double-precision floating point value.
* \returns non-zero if the value is infinity, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isinff
*/
extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
/**
* Return whether the value is infinity.
*
* \param x floating point value.
* \returns non-zero if the value is infinity, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isinf
*/
extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
/**
* Return whether the value is NaN.
*
* \param x double-precision floating point value.
* \returns non-zero if the value is NaN, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isnanf
*/
extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
/**
* Return whether the value is NaN.
*
* \param x floating point value.
* \returns non-zero if the value is NaN, 0 otherwise.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_isnan
*/
extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
/**
* Compute the natural logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on double-precision floating point values, use
* SDL_logf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the natural logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_logf
* \sa SDL_log10
* \sa SDL_exp
*/
extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
/**
* Compute the natural logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on single-precision floating point values, use
* SDL_log for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the natural logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_log
* \sa SDL_expf
*/
extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
/**
* Compute the base-10 logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on double-precision floating point values, use
* SDL_log10f for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_log10f
* \sa SDL_log
* \sa SDL_pow
*/
extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
/**
* Compute the base-10 logarithm of `x`.
*
* Domain: `0 < x <= INF`
*
* Range: `-INF <= y <= INF`
*
* It is an error for `x` to be less than or equal to 0.
*
* This function operates on single-precision floating point values, use
* SDL_log10 for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than 0.
* \returns the logarithm of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_log10
* \sa SDL_logf
* \sa SDL_powf
*/
extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
/**
* Split `x` into integer and fractional parts
*
* This function operates on double-precision floating point values, use
* SDL_modff for single-precision floats.
*
* \param x floating point value.
* \param y output pointer to store the integer part of `x`.
* \returns the fractional part of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_modff
* \sa SDL_trunc
* \sa SDL_fmod
*/
extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
/**
* Split `x` into integer and fractional parts
*
* This function operates on single-precision floating point values, use
* SDL_modf for double-precision floats.
*
* \param x floating point value.
* \param y output pointer to store the integer part of `x`.
* \returns the fractional part of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_modf
* \sa SDL_truncf
* \sa SDL_fmodf
*/
extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
/**
* Raise `x` to the power `y`
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-INF <= z <= INF`
*
* If `y` is the base of the natural logarithm (e), consider using SDL_exp
* instead.
*
* This function operates on double-precision floating point values, use
* SDL_powf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x the base.
* \param y the exponent.
* \returns `x` raised to the power `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_powf
* \sa SDL_exp
* \sa SDL_log
*/
extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
/**
* Raise `x` to the power `y`
*
* Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
*
* Range: `-INF <= z <= INF`
*
* If `y` is the base of the natural logarithm (e), consider using SDL_exp
* instead.
*
* This function operates on single-precision floating point values, use
* SDL_powf for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x the base.
* \param y the exponent.
* \returns `x` raised to the power `y`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_pow
* \sa SDL_expf
* \sa SDL_logf
*/
extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
/**
* Round `x` to the nearest integer.
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_roundf for single-precision floats. To get the result as an integer
* type, use SDL_lround.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_roundf
* \sa SDL_lround
* \sa SDL_floor
* \sa SDL_ceil
* \sa SDL_trunc
*/
extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
/**
* Round `x` to the nearest integer.
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`, y integer
*
* This function operates on double-precision floating point values, use
* SDL_roundf for single-precision floats. To get the result as an integer
* type, use SDL_lroundf.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_round
* \sa SDL_lroundf
* \sa SDL_floorf
* \sa SDL_ceilf
* \sa SDL_truncf
*/
extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
/**
* Round `x` to the nearest integer representable as a long
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `MIN_LONG <= y <= MAX_LONG`
*
* This function operates on double-precision floating point values, use
* SDL_lround for single-precision floats. To get the result as a
* floating-point type, use SDL_round.
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_lroundf
* \sa SDL_round
* \sa SDL_floor
* \sa SDL_ceil
* \sa SDL_trunc
*/
extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
/**
* Round `x` to the nearest integer representable as a long
*
* Rounds `x` to the nearest integer. Values halfway between integers will be
* rounded away from zero.
*
* Domain: `-INF <= x <= INF`
*
* Range: `MIN_LONG <= y <= MAX_LONG`
*
* This function operates on single-precision floating point values, use
* SDL_lroundf for double-precision floats. To get the result as a
* floating-point type, use SDL_roundf,
*
* \param x floating point value.
* \returns the nearest integer to `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_lround
* \sa SDL_roundf
* \sa SDL_floorf
* \sa SDL_ceilf
* \sa SDL_truncf
*/
extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
/**
* Scale `x` by an integer power of two.
*
* Multiplies `x` by the `n`th power of the floating point radix (always 2).
*
* Domain: `-INF <= x <= INF`, `n` integer
*
* Range: `-INF <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_scalbnf for single-precision floats.
*
* \param x floating point value to be scaled.
* \param n integer exponent.
* \returns `x * 2^n`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_scalbnf
* \sa SDL_pow
*/
extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
/**
* Scale `x` by an integer power of two.
*
* Multiplies `x` by the `n`th power of the floating point radix (always 2).
*
* Domain: `-INF <= x <= INF`, `n` integer
*
* Range: `-INF <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_scalbn for double-precision floats.
*
* \param x floating point value to be scaled.
* \param n integer exponent.
* \returns `x * 2^n`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_scalbn
* \sa SDL_powf
*/
extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
/**
* Compute the sine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on double-precision floating point values, use
* SDL_sinf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns sine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_sinf
* \sa SDL_asin
* \sa SDL_cos
*/
extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
/**
* Compute the sine of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-1 <= y <= 1`
*
* This function operates on single-precision floating point values, use
* SDL_sin for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns sine of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_sin
* \sa SDL_asinf
* \sa SDL_cosf
*/
extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
/**
* Compute the square root of `x`.
*
* Domain: `0 <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_sqrtf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than or equal to 0.
* \returns square root of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_sqrtf
*/
extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
/**
* Compute the square root of `x`.
*
* Domain: `0 <= x <= INF`
*
* Range: `0 <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_sqrt for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value. Must be greater than or equal to 0.
* \returns square root of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_sqrt
*/
extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
/**
* Compute the tangent of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`
*
* This function operates on double-precision floating point values, use
* SDL_tanf for single-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns tangent of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_tanf
* \sa SDL_sin
* \sa SDL_cos
* \sa SDL_atan
* \sa SDL_atan2
*/
extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
/**
* Compute the tangent of `x`.
*
* Domain: `-INF <= x <= INF`
*
* Range: `-INF <= y <= INF`
*
* This function operates on single-precision floating point values, use
* SDL_tanf for double-precision floats.
*
* This function may use a different approximation across different versions,
* platforms and configurations. i.e, it can return a different value given
* the same input on different machines or operating systems, or if SDL is
* updated.
*
* \param x floating point value, in radians.
* \returns tangent of `x`.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_tan
* \sa SDL_sinf
* \sa SDL_cosf
* \sa SDL_atanf
* \sa SDL_atan2f
*/
extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
/**
* An opaque handle representing string encoding conversion state.
*
* \since This datatype is available since SDL 3.1.3.
*
* \sa SDL_iconv_open
*/
typedef struct SDL_iconv_data_t *SDL_iconv_t;
/**
* This function allocates a context for the specified character set
* conversion.
*
* \param tocode The target character encoding, must not be NULL.
* \param fromcode The source character encoding, must not be NULL.
* \returns a handle that must be freed with SDL_iconv_close, or
* SDL_ICONV_ERROR on failure.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_iconv
* \sa SDL_iconv_close
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
const char *fromcode);
/**
* This function frees a context used for character set conversion.
*
* \param cd The character set conversion handle.
* \returns 0 on success, or -1 on failure.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_iconv
* \sa SDL_iconv_open
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
/**
* This function converts text between encodings, reading from and writing to
* a buffer.
*
* It returns the number of succesful conversions on success. On error,
* SDL_ICONV_E2BIG is returned when the output buffer is too small, or
* SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
* or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
* encountered.
*
* On exit:
*
* - inbuf will point to the beginning of the next multibyte sequence. On
* error, this is the location of the problematic input sequence. On
* success, this is the end of the input sequence.
* - inbytesleft will be set to the number of bytes left to convert, which
* will be 0 on success.
* - outbuf will point to the location where to store the next output byte.
* - outbytesleft will be set to the number of bytes left in the output
* buffer.
*
* \param cd The character set conversion context, created in
* SDL_iconv_open().
* \param inbuf Address of variable that points to the first character of the
* input sequence.
* \param inbytesleft The number of bytes in the input buffer.
* \param outbuf Address of variable that points to the output buffer.
* \param outbytesleft The number of bytes in the output buffer.
* \returns the number of conversions on success, or a negative error code.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_iconv_open
* \sa SDL_iconv_close
* \sa SDL_iconv_string
*/
extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
size_t *inbytesleft, char **outbuf,
size_t *outbytesleft);
#define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
#define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
#define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
#define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
/**
* Helper function to convert a string's encoding in one call.
*
* This function converts a buffer or string between encodings in one pass.
*
* The string does not need to be NULL-terminated; this function operates on
* the number of bytes specified in `inbytesleft` whether there is a NULL
* character anywhere in the buffer.
*
* The returned string is owned by the caller, and should be passed to
* SDL_free when no longer needed.
*
* \param tocode the character encoding of the output string. Examples are
* "UTF-8", "UCS-4", etc.
* \param fromcode the character encoding of data in `inbuf`.
* \param inbuf the string to convert to a different encoding.
* \param inbytesleft the size of the input string _in bytes_.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \since This function is available since SDL 3.1.3.
*
* \sa SDL_iconv_open
* \sa SDL_iconv_close
* \sa SDL_iconv
*/
extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
const char *fromcode,
const char *inbuf,
size_t inbytesleft);
/* Some helper macros for common SDL_iconv_string cases... */
/**
* Convert a UTF-8 string to the current locale's character encoding.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
/**
* Convert a UTF-8 string to UCS-2.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
/**
* Convert a UTF-8 string to UCS-4.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
/**
* Convert a wchar_t string to UTF-8.
*
* This is a helper macro that might be more clear than calling
* SDL_iconv_string directly. However, it double-evaluates its parameter, so
* do not use an expression with side-effects here.
*
* \param S the string to convert.
* \returns a new string, converted to the new encoding, or NULL on error.
*
* \since This macro is available since SDL 3.1.3.
*/
#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
/* force builds using Clang's static analysis tools to use literal C runtime
here, since there are possibly tests that are ineffective otherwise. */
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
/* The analyzer knows about strlcpy even when the system doesn't provide it */
#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
size_t strlcpy(char *dst, const char *src, size_t size);
#endif
/* The analyzer knows about strlcat even when the system doesn't provide it */
#if !defined(HAVE_STRLCAT) && !defined(strlcat)
size_t strlcat(char *dst, const char *src, size_t size);
#endif
#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
#endif
#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
#endif
/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
char *strdup(const char *str);
/* Starting LLVM 16, the analyser errors out if these functions do not have
their prototype defined (clang-diagnostic-implicit-function-declaration) */
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define SDL_malloc malloc
#define SDL_calloc calloc
#define SDL_realloc realloc
#define SDL_free free
#ifndef SDL_memcpy
#define SDL_memcpy memcpy
#endif
#ifndef SDL_memmove
#define SDL_memmove memmove
#endif
#ifndef SDL_memset
#define SDL_memset memset
#endif
#define SDL_memcmp memcmp
#define SDL_strlcpy strlcpy
#define SDL_strlcat strlcat
#define SDL_strlen strlen
#define SDL_wcslen wcslen
#define SDL_wcslcpy wcslcpy
#define SDL_wcslcat wcslcat
#define SDL_strdup strdup
#define SDL_wcsdup wcsdup
#define SDL_strchr strchr
#define SDL_strrchr strrchr
#define SDL_strstr strstr
#define SDL_wcsstr wcsstr
#define SDL_strtok_r strtok_r
#define SDL_strcmp strcmp
#define SDL_wcscmp wcscmp
#define SDL_strncmp strncmp
#define SDL_wcsncmp wcsncmp
#define SDL_strcasecmp strcasecmp
#define SDL_strncasecmp strncasecmp
#define SDL_strpbrk strpbrk
#define SDL_sscanf sscanf
#define SDL_vsscanf vsscanf
#define SDL_snprintf snprintf
#define SDL_vsnprintf vsnprintf
#endif
/**
* Multiply two integers, checking for overflow.
*
* If `a * b` would overflow, return false.
*
* Otherwise store `a * b` via ret and return true.
*
* \param a the multiplicand.
* \param b the multiplier.
* \param ret on non-overflow output, stores the multiplication result, may
* not be NULL.
* \returns false on overflow, true if result is multiplied without overflow.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
{
if (a != 0 && b > SDL_SIZE_MAX / a) {
return false;
}
*ret = a * b;
return true;
}
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if SDL_HAS_BUILTIN(__builtin_mul_overflow)
/* This needs to be wrapped in an inline rather than being a direct #define,
* because __builtin_mul_overflow() is type-generic, but we want to be
* consistent about interpreting a and b as size_t. */
SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
{
return (__builtin_mul_overflow(a, b, ret) == 0);
}
#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
#endif
#endif
/**
* Add two integers, checking for overflow.
*
* If `a + b` would overflow, return false.
*
* Otherwise store `a + b` via ret and return true.
*
* \param a the first addend.
* \param b the second addend.
* \param ret on non-overflow output, stores the addition result, may not be
* NULL.
* \returns false on overflow, true if result is added without overflow.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.1.3.
*/
SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
{
if (b > SDL_SIZE_MAX - a) {
return false;
}
*ret = a + b;
return true;
}
#ifndef SDL_WIKI_DOCUMENTATION_SECTION
#if SDL_HAS_BUILTIN(__builtin_add_overflow)
/* This needs to be wrapped in an inline rather than being a direct #define,
* the same as the call to __builtin_mul_overflow() above. */
SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
{
return (__builtin_add_overflow(a, b, ret) == 0);
}
#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
#endif
#endif
/* This is a generic function pointer which should be cast to the type you expect */
#ifdef SDL_WIKI_DOCUMENTATION_SECTION
/**
* A generic function pointer.
*
* In theory, generic function pointers should use this, instead of `void *`,
* since some platforms could treat code addresses differently than data
* addresses. Although in current times no popular platforms make this
* distinction, it is more correct and portable to use the correct type for a
* generic pointer.
*
* If for some reason you need to force this typedef to be an actual `void *`,
* perhaps to work around a compiler or existing code, you can define
* `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
*
* \since This datatype is available since SDL 3.1.3.
*/
typedef void (*SDL_FunctionPointer)(void);
#elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
typedef void *SDL_FunctionPointer;
#else
typedef void (*SDL_FunctionPointer)(void);
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_stdinc_h_ */