SDL_stdinc.h 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryStdinc
  20. *
  21. * This is a general header that includes C language support. It implements a
  22. * subset of the C runtime: these should all behave the same way as their C
  23. * runtime equivalents, but with an SDL_ prefix.
  24. */
  25. #ifndef SDL_stdinc_h_
  26. #define SDL_stdinc_h_
  27. #include <SDL3/SDL_platform_defines.h>
  28. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  29. #include <inttypes.h>
  30. #endif
  31. #include <stdarg.h>
  32. #ifndef __cplusplus
  33. #include <stdbool.h>
  34. #endif
  35. #include <stdint.h>
  36. #include <string.h>
  37. #include <wchar.h>
  38. #ifndef SDL_DISABLE_ALLOCA
  39. # ifndef alloca
  40. # ifdef HAVE_ALLOCA_H
  41. # include <alloca.h>
  42. # elif defined(SDL_PLATFORM_NETBSD)
  43. # if defined(__STRICT_ANSI__)
  44. # define SDL_DISABLE_ALLOCA
  45. # else
  46. # include <stdlib.h>
  47. # endif
  48. # elif defined(__GNUC__)
  49. # define alloca __builtin_alloca
  50. # elif defined(_MSC_VER)
  51. # include <malloc.h>
  52. # define alloca _alloca
  53. # elif defined(__WATCOMC__)
  54. # include <malloc.h>
  55. # elif defined(__BORLANDC__)
  56. # include <malloc.h>
  57. # elif defined(__DMC__)
  58. # include <stdlib.h>
  59. # elif defined(SDL_PLATFORM_AIX)
  60. # pragma alloca
  61. # elif defined(__MRC__)
  62. void *alloca(unsigned);
  63. # else
  64. void *alloca(size_t);
  65. # endif
  66. # endif
  67. #endif
  68. #ifdef SIZE_MAX
  69. # define SDL_SIZE_MAX SIZE_MAX
  70. #else
  71. # define SDL_SIZE_MAX ((size_t) -1)
  72. #endif
  73. /**
  74. * Check if the compiler supports a given builtin.
  75. * Supported by virtually all clang versions and recent gcc. Use this
  76. * instead of checking the clang version if possible.
  77. */
  78. #ifdef __has_builtin
  79. #define SDL_HAS_BUILTIN(x) __has_builtin(x)
  80. #else
  81. #define SDL_HAS_BUILTIN(x) 0
  82. #endif
  83. /**
  84. * The number of elements in an array.
  85. *
  86. * This macro looks like it double-evaluates the argument, but it does so
  87. * inside of `sizeof`, so there are no side-effects here, as expressions do
  88. * not actually run any code in these cases.
  89. *
  90. * \since This macro is available since SDL 3.0.0.
  91. */
  92. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  93. /**
  94. * Macro useful for building other macros with strings in them.
  95. *
  96. * For example:
  97. *
  98. * ```c
  99. * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
  100. * ```
  101. *
  102. * \since This macro is available since SDL 3.0.0.
  103. */
  104. #define SDL_STRINGIFY_ARG(arg) #arg
  105. /**
  106. * \name Cast operators
  107. *
  108. * Use proper C++ casts when compiled as C++ to be compatible with the option
  109. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  110. */
  111. /* @{ */
  112. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  113. /**
  114. * Handle a Reinterpret Cast properly whether using C or C++.
  115. *
  116. * If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
  117. *
  118. * If compiled as C, this macro does a normal C-style cast.
  119. *
  120. * This is helpful to avoid compiler warnings in C++.
  121. *
  122. * \param type the type to cast the expression to.
  123. * \param expression the expression to cast to a different type.
  124. * \returns `expression`, cast to `type`.
  125. *
  126. * \threadsafety It is safe to call this macro from any thread.
  127. *
  128. * \since This macro is available since SDL 3.0.0.
  129. *
  130. * \sa SDL_static_cast
  131. * \sa SDL_const_cast
  132. */
  133. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
  134. /**
  135. * Handle a Static Cast properly whether using C or C++.
  136. *
  137. * If compiled as C++, this macro offers a proper C++ static_cast<>.
  138. *
  139. * If compiled as C, this macro does a normal C-style cast.
  140. *
  141. * This is helpful to avoid compiler warnings in C++.
  142. *
  143. * \param type the type to cast the expression to.
  144. * \param expression the expression to cast to a different type.
  145. * \returns `expression`, cast to `type`.
  146. *
  147. * \threadsafety It is safe to call this macro from any thread.
  148. *
  149. * \since This macro is available since SDL 3.0.0.
  150. *
  151. * \sa SDL_reinterpret_cast
  152. * \sa SDL_const_cast
  153. */
  154. #define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
  155. /**
  156. * Handle a Const Cast properly whether using C or C++.
  157. *
  158. * If compiled as C++, this macro offers a proper C++ const_cast<>.
  159. *
  160. * If compiled as C, this macro does a normal C-style cast.
  161. *
  162. * This is helpful to avoid compiler warnings in C++.
  163. *
  164. * \param type the type to cast the expression to.
  165. * \param expression the expression to cast to a different type.
  166. * \returns `expression`, cast to `type`.
  167. *
  168. * \threadsafety It is safe to call this macro from any thread.
  169. *
  170. * \since This macro is available since SDL 3.0.0.
  171. *
  172. * \sa SDL_reinterpret_cast
  173. * \sa SDL_static_cast
  174. */
  175. #define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
  176. #elif defined(__cplusplus)
  177. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  178. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  179. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  180. #else
  181. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  182. #define SDL_static_cast(type, expression) ((type)(expression))
  183. #define SDL_const_cast(type, expression) ((type)(expression))
  184. #endif
  185. /* @} *//* Cast operators */
  186. /**
  187. * Define a four character code as a Uint32.
  188. *
  189. * \param A the first ASCII character.
  190. * \param B the second ASCII character.
  191. * \param C the third ASCII character.
  192. * \param D the fourth ASCII character.
  193. * \returns the four characters converted into a Uint32, one character
  194. * per-byte.
  195. *
  196. * \threadsafety It is safe to call this macro from any thread.
  197. *
  198. * \since This macro is available since SDL 3.0.0.
  199. */
  200. #define SDL_FOURCC(A, B, C, D) \
  201. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  202. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  203. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  204. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  205. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  206. /**
  207. * Append the 64 bit integer suffix to a signed integer literal.
  208. *
  209. * This helps compilers that might believe a integer literal larger than
  210. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
  211. * instead of `0xFFFFFFFF1` by itself.
  212. *
  213. * \since This macro is available since SDL 3.0.0.
  214. *
  215. * \sa SDL_UINT64_C
  216. */
  217. #define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
  218. /**
  219. * Append the 64 bit integer suffix to an unsigned integer literal.
  220. *
  221. * This helps compilers that might believe a integer literal larger than
  222. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
  223. * instead of `0xFFFFFFFF1` by itself.
  224. *
  225. * \since This macro is available since SDL 3.0.0.
  226. *
  227. * \sa SDL_SINT64_C
  228. */
  229. #define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
  230. #elif defined(INT64_C)
  231. #define SDL_SINT64_C(c) INT64_C(c)
  232. #define SDL_UINT64_C(c) UINT64_C(c)
  233. #elif defined(_MSC_VER)
  234. #define SDL_SINT64_C(c) c ## i64
  235. #define SDL_UINT64_C(c) c ## ui64
  236. #elif defined(__LP64__) || defined(_LP64)
  237. #define SDL_SINT64_C(c) c ## L
  238. #define SDL_UINT64_C(c) c ## UL
  239. #else
  240. #define SDL_SINT64_C(c) c ## LL
  241. #define SDL_UINT64_C(c) c ## ULL
  242. #endif
  243. /**
  244. * \name Basic data types
  245. */
  246. /* @{ */
  247. /**
  248. * A boolean false.
  249. *
  250. * \since This macro is available since SDL 3.0.0.
  251. *
  252. * \sa SDL_bool
  253. */
  254. #define SDL_FALSE false
  255. /**
  256. * A boolean true.
  257. *
  258. * \since This macro is available since SDL 3.0.0.
  259. *
  260. * \sa SDL_bool
  261. */
  262. #define SDL_TRUE true
  263. /**
  264. * A boolean type: true or false.
  265. *
  266. * \since This datatype is available since SDL 3.0.0.
  267. *
  268. * \sa SDL_TRUE
  269. * \sa SDL_FALSE
  270. */
  271. typedef bool SDL_bool;
  272. /**
  273. * A signed 8-bit integer type.
  274. *
  275. * \since This macro is available since SDL 3.0.0.
  276. */
  277. typedef int8_t Sint8;
  278. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  279. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  280. /**
  281. * An unsigned 8-bit integer type.
  282. *
  283. * \since This macro is available since SDL 3.0.0.
  284. */
  285. typedef uint8_t Uint8;
  286. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  287. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  288. /**
  289. * A signed 16-bit integer type.
  290. *
  291. * \since This macro is available since SDL 3.0.0.
  292. */
  293. typedef int16_t Sint16;
  294. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  295. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  296. /**
  297. * An unsigned 16-bit integer type.
  298. *
  299. * \since This macro is available since SDL 3.0.0.
  300. */
  301. typedef uint16_t Uint16;
  302. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  303. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  304. /**
  305. * A signed 32-bit integer type.
  306. *
  307. * \since This macro is available since SDL 3.0.0.
  308. */
  309. typedef int32_t Sint32;
  310. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  311. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  312. /**
  313. * An unsigned 32-bit integer type.
  314. *
  315. * \since This macro is available since SDL 3.0.0.
  316. */
  317. typedef uint32_t Uint32;
  318. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  319. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  320. /**
  321. * A signed 64-bit integer type.
  322. *
  323. * \since This macro is available since SDL 3.0.0.
  324. *
  325. * \sa SDL_SINT64_C
  326. */
  327. typedef int64_t Sint64;
  328. #define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
  329. #define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
  330. /**
  331. * An unsigned 64-bit integer type.
  332. *
  333. * \since This macro is available since SDL 3.0.0.
  334. *
  335. * \sa SDL_UINT64_C
  336. */
  337. typedef uint64_t Uint64;
  338. #define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
  339. #define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
  340. /**
  341. * SDL times are signed, 64-bit integers representing nanoseconds since the
  342. * Unix epoch (Jan 1, 1970).
  343. *
  344. * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
  345. * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
  346. * SDL_TimeToWindows() and SDL_TimeFromWindows().
  347. *
  348. * \since This macro is available since SDL 3.0.0.
  349. *
  350. * \sa SDL_MAX_SINT64
  351. * \sa SDL_MIN_SINT64
  352. */
  353. typedef Sint64 SDL_Time;
  354. #define SDL_MAX_TIME SDL_MAX_SINT64
  355. #define SDL_MIN_TIME SDL_MIN_SINT64
  356. /* @} *//* Basic data types */
  357. /**
  358. * \name Floating-point constants
  359. */
  360. /* @{ */
  361. #ifdef FLT_EPSILON
  362. #define SDL_FLT_EPSILON FLT_EPSILON
  363. #else
  364. /**
  365. * Epsilon constant, used for comparing floating-point numbers.
  366. *
  367. * Equals by default to platform-defined `FLT_EPSILON`, or
  368. * `1.1920928955078125e-07F` if that's not available.
  369. *
  370. * \since This macro is available since SDL 3.0.0.
  371. */
  372. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  373. #endif
  374. /* @} *//* Floating-point constants */
  375. /* Make sure we have macros for printing width-based integers.
  376. * <stdint.h> should define these but this is not true all platforms.
  377. * (for example win32) */
  378. #ifndef SDL_PRIs64
  379. #if defined(SDL_PLATFORM_WINDOWS)
  380. #define SDL_PRIs64 "I64d"
  381. #elif defined(PRIs64)
  382. #define SDL_PRIs64 PRIs64
  383. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  384. #define SDL_PRIs64 "ld"
  385. #else
  386. #define SDL_PRIs64 "lld"
  387. #endif
  388. #endif
  389. #ifndef SDL_PRIu64
  390. #if defined(SDL_PLATFORM_WINDOWS)
  391. #define SDL_PRIu64 "I64u"
  392. #elif defined(PRIu64)
  393. #define SDL_PRIu64 PRIu64
  394. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  395. #define SDL_PRIu64 "lu"
  396. #else
  397. #define SDL_PRIu64 "llu"
  398. #endif
  399. #endif
  400. #ifndef SDL_PRIx64
  401. #if defined(SDL_PLATFORM_WINDOWS)
  402. #define SDL_PRIx64 "I64x"
  403. #elif defined(PRIx64)
  404. #define SDL_PRIx64 PRIx64
  405. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  406. #define SDL_PRIx64 "lx"
  407. #else
  408. #define SDL_PRIx64 "llx"
  409. #endif
  410. #endif
  411. #ifndef SDL_PRIX64
  412. #if defined(SDL_PLATFORM_WINDOWS)
  413. #define SDL_PRIX64 "I64X"
  414. #elif defined(PRIX64)
  415. #define SDL_PRIX64 PRIX64
  416. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  417. #define SDL_PRIX64 "lX"
  418. #else
  419. #define SDL_PRIX64 "llX"
  420. #endif
  421. #endif
  422. #ifndef SDL_PRIs32
  423. #ifdef PRId32
  424. #define SDL_PRIs32 PRId32
  425. #else
  426. #define SDL_PRIs32 "d"
  427. #endif
  428. #endif
  429. #ifndef SDL_PRIu32
  430. #ifdef PRIu32
  431. #define SDL_PRIu32 PRIu32
  432. #else
  433. #define SDL_PRIu32 "u"
  434. #endif
  435. #endif
  436. #ifndef SDL_PRIx32
  437. #ifdef PRIx32
  438. #define SDL_PRIx32 PRIx32
  439. #else
  440. #define SDL_PRIx32 "x"
  441. #endif
  442. #endif
  443. #ifndef SDL_PRIX32
  444. #ifdef PRIX32
  445. #define SDL_PRIX32 PRIX32
  446. #else
  447. #define SDL_PRIX32 "X"
  448. #endif
  449. #endif
  450. /* Annotations to help code analysis tools */
  451. #ifdef SDL_DISABLE_ANALYZE_MACROS
  452. #define SDL_IN_BYTECAP(x)
  453. #define SDL_INOUT_Z_CAP(x)
  454. #define SDL_OUT_Z_CAP(x)
  455. #define SDL_OUT_CAP(x)
  456. #define SDL_OUT_BYTECAP(x)
  457. #define SDL_OUT_Z_BYTECAP(x)
  458. #define SDL_PRINTF_FORMAT_STRING
  459. #define SDL_SCANF_FORMAT_STRING
  460. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  461. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  462. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  463. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  464. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  465. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
  466. #else
  467. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  468. #include <sal.h>
  469. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  470. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  471. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  472. #define SDL_OUT_CAP(x) _Out_cap_(x)
  473. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  474. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  475. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  476. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  477. #else
  478. #define SDL_IN_BYTECAP(x)
  479. #define SDL_INOUT_Z_CAP(x)
  480. #define SDL_OUT_Z_CAP(x)
  481. #define SDL_OUT_CAP(x)
  482. #define SDL_OUT_BYTECAP(x)
  483. #define SDL_OUT_Z_BYTECAP(x)
  484. #define SDL_PRINTF_FORMAT_STRING
  485. #define SDL_SCANF_FORMAT_STRING
  486. #endif
  487. #ifdef __GNUC__
  488. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  489. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
  490. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  491. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
  492. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
  493. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wscanf__, fmtargnumber, fmtargnumber+1 ))) */
  494. #else
  495. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  496. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  497. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  498. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  499. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  500. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
  501. #endif
  502. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  503. #ifndef SDL_COMPILE_TIME_ASSERT
  504. #if defined(__cplusplus)
  505. /* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
  506. #if (__cplusplus >= 201103L)
  507. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  508. #endif
  509. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
  510. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  511. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  512. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  513. #endif
  514. #endif /* !SDL_COMPILE_TIME_ASSERT */
  515. #ifndef SDL_COMPILE_TIME_ASSERT
  516. /* universal, but may trigger -Wunused-local-typedefs */
  517. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  518. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  519. #endif
  520. /** \cond */
  521. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  522. SDL_COMPILE_TIME_ASSERT(bool, sizeof(SDL_bool) == 1);
  523. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  524. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  525. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  526. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  527. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  528. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  529. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  530. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  531. typedef struct SDL_alignment_test
  532. {
  533. Uint8 a;
  534. void *b;
  535. } SDL_alignment_test;
  536. SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
  537. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  538. /** \endcond */
  539. /* Check to make sure enums are the size of ints, for structure packing.
  540. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  541. enums having the size of an int must be enabled.
  542. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  543. */
  544. /** \cond */
  545. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  546. #if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
  547. /* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
  548. typedef enum SDL_DUMMY_ENUM
  549. {
  550. DUMMY_ENUM_VALUE
  551. } SDL_DUMMY_ENUM;
  552. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  553. #endif
  554. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  555. /** \endcond */
  556. #include <SDL3/SDL_begin_code.h>
  557. /* Set up for C function definitions, even when using C++ */
  558. #ifdef __cplusplus
  559. extern "C" {
  560. #endif
  561. /**
  562. * A macro to initialize an SDL interface.
  563. *
  564. * This macro will initialize an SDL interface structure and should be called
  565. * before you fill out the fields with your implementation.
  566. *
  567. * You can use it like this:
  568. *
  569. * ```c
  570. * SDL_IOStreamInterface iface;
  571. *
  572. * SDL_INIT_INTERFACE(&iface);
  573. *
  574. * // Fill in the interface function pointers with your implementation
  575. * iface.seek = ...
  576. *
  577. * stream = SDL_OpenIO(&iface, NULL);
  578. * ```
  579. *
  580. * If you are using designated initializers, you can use the size of the
  581. * interface as the version, e.g.
  582. *
  583. * ```c
  584. * SDL_IOStreamInterface iface = {
  585. * .version = sizeof(iface),
  586. * .seek = ...
  587. * };
  588. * stream = SDL_OpenIO(&iface, NULL);
  589. * ```
  590. *
  591. * \threadsafety It is safe to call this macro from any thread.
  592. *
  593. * \since This macro is available since SDL 3.0.0.
  594. *
  595. * \sa SDL_IOStreamInterface
  596. * \sa SDL_StorageInterface
  597. * \sa SDL_VirtualJoystickDesc
  598. */
  599. #define SDL_INIT_INTERFACE(iface) \
  600. do { \
  601. SDL_zerop(iface); \
  602. (iface)->version = sizeof(*(iface)); \
  603. } while (0)
  604. #ifndef SDL_DISABLE_ALLOCA
  605. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  606. #define SDL_stack_free(data)
  607. #else
  608. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  609. #define SDL_stack_free(data) SDL_free(data)
  610. #endif
  611. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
  612. extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
  613. extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
  614. extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
  615. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  616. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  617. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  618. typedef void (SDLCALL *SDL_free_func)(void *mem);
  619. /**
  620. * Get the original set of SDL memory functions.
  621. *
  622. * This is what SDL_malloc and friends will use by default, if there has been
  623. * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
  624. * runtime's `malloc` functions behind the scenes! Different platforms and
  625. * build configurations might do any number of unexpected things.
  626. *
  627. * \param malloc_func filled with malloc function.
  628. * \param calloc_func filled with calloc function.
  629. * \param realloc_func filled with realloc function.
  630. * \param free_func filled with free function.
  631. *
  632. * \threadsafety It is safe to call this function from any thread.
  633. *
  634. * \since This function is available since SDL 3.0.0.
  635. */
  636. extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
  637. SDL_calloc_func *calloc_func,
  638. SDL_realloc_func *realloc_func,
  639. SDL_free_func *free_func);
  640. /**
  641. * Get the current set of SDL memory functions.
  642. *
  643. * \param malloc_func filled with malloc function.
  644. * \param calloc_func filled with calloc function.
  645. * \param realloc_func filled with realloc function.
  646. * \param free_func filled with free function.
  647. *
  648. * \threadsafety This does not hold a lock, so do not call this in the
  649. * unlikely event of a background thread calling
  650. * SDL_SetMemoryFunctions simultaneously.
  651. *
  652. * \since This function is available since SDL 3.0.0.
  653. *
  654. * \sa SDL_SetMemoryFunctions
  655. * \sa SDL_GetOriginalMemoryFunctions
  656. */
  657. extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  658. SDL_calloc_func *calloc_func,
  659. SDL_realloc_func *realloc_func,
  660. SDL_free_func *free_func);
  661. /**
  662. * Replace SDL's memory allocation functions with a custom set.
  663. *
  664. * It is not safe to call this function once any allocations have been made,
  665. * as future calls to SDL_free will use the new allocator, even if they came
  666. * from an SDL_malloc made with the old one!
  667. *
  668. * If used, usually this needs to be the first call made into the SDL library,
  669. * if not the very first thing done at program startup time.
  670. *
  671. * \param malloc_func custom malloc function.
  672. * \param calloc_func custom calloc function.
  673. * \param realloc_func custom realloc function.
  674. * \param free_func custom free function.
  675. * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
  676. * for more information.
  677. *
  678. * \threadsafety It is safe to call this function from any thread, but one
  679. * should not replace the memory functions once any allocations
  680. * are made!
  681. *
  682. * \since This function is available since SDL 3.0.0.
  683. *
  684. * \sa SDL_GetMemoryFunctions
  685. * \sa SDL_GetOriginalMemoryFunctions
  686. */
  687. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  688. SDL_calloc_func calloc_func,
  689. SDL_realloc_func realloc_func,
  690. SDL_free_func free_func);
  691. /**
  692. * Allocate memory aligned to a specific value.
  693. *
  694. * If `alignment` is less than the size of `void *`, then it will be increased
  695. * to match that.
  696. *
  697. * The returned memory address will be a multiple of the alignment value, and
  698. * the amount of memory allocated will be a multiple of the alignment value.
  699. *
  700. * The memory returned by this function must be freed with SDL_aligned_free(),
  701. * and _not_ SDL_free.
  702. *
  703. * \param alignment the alignment requested.
  704. * \param size the size to allocate.
  705. * \returns a pointer to the aligned memory.
  706. *
  707. * \threadsafety It is safe to call this function from any thread.
  708. *
  709. * \since This function is available since SDL 3.0.0.
  710. *
  711. * \sa SDL_aligned_free
  712. */
  713. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  714. /**
  715. * Free memory allocated by SDL_aligned_alloc().
  716. *
  717. * The pointer is no longer valid after this call and cannot be dereferenced
  718. * anymore.
  719. *
  720. * \param mem a pointer previously returned by SDL_aligned_alloc.
  721. *
  722. * \threadsafety It is safe to call this function from any thread.
  723. *
  724. * \since This function is available since SDL 3.0.0.
  725. *
  726. * \sa SDL_aligned_alloc
  727. */
  728. extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  729. /**
  730. * Get the number of outstanding (unfreed) allocations.
  731. *
  732. * \returns the number of allocations.
  733. *
  734. * \threadsafety It is safe to call this function from any thread.
  735. *
  736. * \since This function is available since SDL 3.0.0.
  737. */
  738. extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  739. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
  740. extern SDL_DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  741. extern SDL_DECLSPEC int SDLCALL SDL_unsetenv(const char *name);
  742. typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
  743. extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  744. extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  745. typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
  746. extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
  747. 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);
  748. extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
  749. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  750. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  751. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  752. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  753. /**
  754. * Query if a character is alphabetic (a letter).
  755. *
  756. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  757. * for English 'a-z' and 'A-Z' as true.
  758. *
  759. * \param x character value to check.
  760. * \returns non-zero if x falls within the character class, zero otherwise.
  761. *
  762. * \threadsafety It is safe to call this function from any thread.
  763. *
  764. * \since This function is available since SDL 3.0.0.
  765. */
  766. extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
  767. /**
  768. * Query if a character is alphabetic (a letter) or a number.
  769. *
  770. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  771. * for English 'a-z', 'A-Z', and '0-9' as true.
  772. *
  773. * \param x character value to check.
  774. * \returns non-zero if x falls within the character class, zero otherwise.
  775. *
  776. * \threadsafety It is safe to call this function from any thread.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. */
  780. extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
  781. /**
  782. * Report if a character is blank (a space or tab).
  783. *
  784. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  785. * 0x20 (space) or 0x9 (tab) as true.
  786. *
  787. * \param x character value to check.
  788. * \returns non-zero if x falls within the character class, zero otherwise.
  789. *
  790. * \threadsafety It is safe to call this function from any thread.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. */
  794. extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
  795. /**
  796. * Report if a character is a control character.
  797. *
  798. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  799. * 0 through 0x1F, and 0x7F, as true.
  800. *
  801. * \param x character value to check.
  802. * \returns non-zero if x falls within the character class, zero otherwise.
  803. *
  804. * \threadsafety It is safe to call this function from any thread.
  805. *
  806. * \since This function is available since SDL 3.0.0.
  807. */
  808. extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
  809. /**
  810. * Report if a character is a numeric digit.
  811. *
  812. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  813. * '0' (0x30) through '9' (0x39), as true.
  814. *
  815. * \param x character value to check.
  816. * \returns non-zero if x falls within the character class, zero otherwise.
  817. *
  818. * \threadsafety It is safe to call this function from any thread.
  819. *
  820. * \since This function is available since SDL 3.0.0.
  821. */
  822. extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
  823. /**
  824. * Report if a character is a hexadecimal digit.
  825. *
  826. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  827. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  828. *
  829. * \param x character value to check.
  830. * \returns non-zero if x falls within the character class, zero otherwise.
  831. *
  832. * \threadsafety It is safe to call this function from any thread.
  833. *
  834. * \since This function is available since SDL 3.0.0.
  835. */
  836. extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
  837. /**
  838. * Report if a character is a punctuation mark.
  839. *
  840. * **WARNING**: Regardless of system locale, this is equivalent to
  841. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  842. *
  843. * \param x character value to check.
  844. * \returns non-zero if x falls within the character class, zero otherwise.
  845. *
  846. * \threadsafety It is safe to call this function from any thread.
  847. *
  848. * \since This function is available since SDL 3.0.0.
  849. *
  850. * \sa SDL_isgraph
  851. * \sa SDL_isalnum
  852. */
  853. extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
  854. /**
  855. * Report if a character is whitespace.
  856. *
  857. * **WARNING**: Regardless of system locale, this will only treat the
  858. * following ASCII values as true:
  859. *
  860. * - space (0x20)
  861. * - tab (0x09)
  862. * - newline (0x0A)
  863. * - vertical tab (0x0B)
  864. * - form feed (0x0C)
  865. * - return (0x0D)
  866. *
  867. * \param x character value to check.
  868. * \returns non-zero if x falls within the character class, zero otherwise.
  869. *
  870. * \threadsafety It is safe to call this function from any thread.
  871. *
  872. * \since This function is available since SDL 3.0.0.
  873. */
  874. extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
  875. /**
  876. * Report if a character is upper case.
  877. *
  878. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  879. * 'A' through 'Z' as true.
  880. *
  881. * \param x character value to check.
  882. * \returns non-zero if x falls within the character class, zero otherwise.
  883. *
  884. * \threadsafety It is safe to call this function from any thread.
  885. *
  886. * \since This function is available since SDL 3.0.0.
  887. */
  888. extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
  889. /**
  890. * Report if a character is lower case.
  891. *
  892. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  893. * 'a' through 'z' as true.
  894. *
  895. * \param x character value to check.
  896. * \returns non-zero if x falls within the character class, zero otherwise.
  897. *
  898. * \threadsafety It is safe to call this function from any thread.
  899. *
  900. * \since This function is available since SDL 3.0.0.
  901. */
  902. extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
  903. /**
  904. * Report if a character is "printable".
  905. *
  906. * Be advised that "printable" has a definition that goes back to text
  907. * terminals from the dawn of computing, making this a sort of special case
  908. * function that is not suitable for Unicode (or most any) text management.
  909. *
  910. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  911. * ' ' (0x20) through '~' (0x7E) as true.
  912. *
  913. * \param x character value to check.
  914. * \returns non-zero if x falls within the character class, zero otherwise.
  915. *
  916. * \threadsafety It is safe to call this function from any thread.
  917. *
  918. * \since This function is available since SDL 3.0.0.
  919. */
  920. extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
  921. /**
  922. * Report if a character is any "printable" except space.
  923. *
  924. * Be advised that "printable" has a definition that goes back to text
  925. * terminals from the dawn of computing, making this a sort of special case
  926. * function that is not suitable for Unicode (or most any) text management.
  927. *
  928. * **WARNING**: Regardless of system locale, this is equivalent to
  929. * `(SDL_isprint(x)) && ((x) != ' ')`.
  930. *
  931. * \param x character value to check.
  932. * \returns non-zero if x falls within the character class, zero otherwise.
  933. *
  934. * \threadsafety It is safe to call this function from any thread.
  935. *
  936. * \since This function is available since SDL 3.0.0.
  937. *
  938. * \sa SDL_isprint
  939. */
  940. extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
  941. /**
  942. * Convert low-ASCII English letters to uppercase.
  943. *
  944. * **WARNING**: Regardless of system locale, this will only convert ASCII
  945. * values 'a' through 'z' to uppercase.
  946. *
  947. * This function returns the uppercase equivalent of `x`. If a character
  948. * cannot be converted, or is already uppercase, this function returns `x`.
  949. *
  950. * \param x character value to check.
  951. * \returns capitalized version of x, or x if no conversion available.
  952. *
  953. * \threadsafety It is safe to call this function from any thread.
  954. *
  955. * \since This function is available since SDL 3.0.0.
  956. */
  957. extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
  958. /**
  959. * Convert low-ASCII English letters to lowercase.
  960. *
  961. * **WARNING**: Regardless of system locale, this will only convert ASCII
  962. * values 'A' through 'Z' to lowercase.
  963. *
  964. * This function returns the lowercase equivalent of `x`. If a character
  965. * cannot be converted, or is already lowercase, this function returns `x`.
  966. *
  967. * \param x character value to check.
  968. * \returns lowercase version of x, or x if no conversion available.
  969. *
  970. * \threadsafety It is safe to call this function from any thread.
  971. *
  972. * \since This function is available since SDL 3.0.0.
  973. */
  974. extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
  975. extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  976. extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  977. extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  978. /* Take advantage of compiler optimizations for memcpy */
  979. #ifndef SDL_SLOW_MEMCPY
  980. #ifdef SDL_memcpy
  981. #undef SDL_memcpy
  982. #endif
  983. #define SDL_memcpy memcpy
  984. #endif
  985. #define SDL_copyp(dst, src) \
  986. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  987. SDL_memcpy((dst), (src), sizeof(*(src)))
  988. extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  989. /* Take advantage of compiler optimizations for memmove */
  990. #ifndef SDL_SLOW_MEMMOVE
  991. #ifdef SDL_memmove
  992. #undef SDL_memmove
  993. #endif
  994. #define SDL_memmove memmove
  995. #endif
  996. extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  997. extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  998. /* Take advantage of compiler optimizations for memset */
  999. #ifndef SDL_SLOW_MEMSET
  1000. #ifdef SDL_memset
  1001. #undef SDL_memset
  1002. #endif
  1003. #define SDL_memset memset
  1004. #endif
  1005. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  1006. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  1007. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  1008. extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  1009. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  1010. extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  1011. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1012. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1013. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
  1014. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  1015. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  1016. /**
  1017. * Compare two null-terminated wide strings.
  1018. *
  1019. * This only compares wchar_t values until it hits a null-terminating
  1020. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  1021. * depending on your platform's wchar_t size), or uses valid Unicode values.
  1022. *
  1023. * \param str1 the first string to compare. NULL is not permitted!
  1024. * \param str2 the second string to compare. NULL is not permitted!
  1025. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1026. * str1 is "greater than" str2, and zero if the strings match
  1027. * exactly.
  1028. *
  1029. * \threadsafety It is safe to call this function from any thread.
  1030. *
  1031. * \since This function is available since SDL 3.0.0.
  1032. */
  1033. extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  1034. /**
  1035. * Compare two wide strings up to a number of wchar_t values.
  1036. *
  1037. * This only compares wchar_t values; it does not care if the string is
  1038. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  1039. * or uses valid Unicode values.
  1040. *
  1041. * Note that while this function is intended to be used with UTF-16 (or
  1042. * UTF-32, depending on your platform's definition of wchar_t), it is
  1043. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  1044. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  1045. * sequence, it will only compare a portion of the final character.
  1046. *
  1047. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  1048. * match to this number of wide chars (or both have matched to a
  1049. * null-terminator character before this count), they will be considered
  1050. * equal.
  1051. *
  1052. * \param str1 the first string to compare. NULL is not permitted!
  1053. * \param str2 the second string to compare. NULL is not permitted!
  1054. * \param maxlen the maximum number of wchar_t to compare.
  1055. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1056. * str1 is "greater than" str2, and zero if the strings match
  1057. * exactly.
  1058. *
  1059. * \threadsafety It is safe to call this function from any thread.
  1060. *
  1061. * \since This function is available since SDL 3.0.0.
  1062. */
  1063. extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1064. /**
  1065. * Compare two null-terminated wide strings, case-insensitively.
  1066. *
  1067. * This will work with Unicode strings, using a technique called
  1068. * "case-folding" to handle the vast majority of case-sensitive human
  1069. * languages regardless of system locale. It can deal with expanding values: a
  1070. * German Eszett character can compare against two ASCII 's' chars and be
  1071. * considered a match, for example. A notable exception: it does not handle
  1072. * the Turkish 'i' character; human language is complicated!
  1073. *
  1074. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1075. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1076. * handles Unicode, it expects the string to be well-formed and not a
  1077. * null-terminated string of arbitrary bytes. Characters that are not valid
  1078. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1079. * CHARACTER), which is to say two strings of random bits may turn out to
  1080. * match if they convert to the same amount of replacement characters.
  1081. *
  1082. * \param str1 the first string to compare. NULL is not permitted!
  1083. * \param str2 the second string to compare. NULL is not permitted!
  1084. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1085. * str1 is "greater than" str2, and zero if the strings match
  1086. * exactly.
  1087. *
  1088. * \threadsafety It is safe to call this function from any thread.
  1089. *
  1090. * \since This function is available since SDL 3.0.0.
  1091. */
  1092. extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  1093. /**
  1094. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  1095. *
  1096. * This will work with Unicode strings, using a technique called
  1097. * "case-folding" to handle the vast majority of case-sensitive human
  1098. * languages regardless of system locale. It can deal with expanding values: a
  1099. * German Eszett character can compare against two ASCII 's' chars and be
  1100. * considered a match, for example. A notable exception: it does not handle
  1101. * the Turkish 'i' character; human language is complicated!
  1102. *
  1103. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1104. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1105. * handles Unicode, it expects the string to be well-formed and not a
  1106. * null-terminated string of arbitrary bytes. Characters that are not valid
  1107. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1108. * CHARACTER), which is to say two strings of random bits may turn out to
  1109. * match if they convert to the same amount of replacement characters.
  1110. *
  1111. * Note that while this function might deal with variable-sized characters,
  1112. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  1113. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  1114. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  1115. * to overflow a buffer.
  1116. *
  1117. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  1118. * strings match to this number of wchar_t (or both have matched to a
  1119. * null-terminator character before this number of bytes), they will be
  1120. * considered equal.
  1121. *
  1122. * \param str1 the first string to compare. NULL is not permitted!
  1123. * \param str2 the second string to compare. NULL is not permitted!
  1124. * \param maxlen the maximum number of wchar_t values to compare.
  1125. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1126. * str1 is "greater than" str2, and zero if the strings match
  1127. * exactly.
  1128. *
  1129. * \threadsafety It is safe to call this function from any thread.
  1130. *
  1131. * \since This function is available since SDL 3.0.0.
  1132. */
  1133. extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1134. extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  1135. extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  1136. extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  1137. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1138. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  1139. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1140. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
  1141. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
  1142. extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
  1143. /**
  1144. * Convert a string to uppercase.
  1145. *
  1146. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1147. * values 'A' through 'Z' to uppercase.
  1148. *
  1149. * This function operates on a null-terminated string of bytes--even if it is
  1150. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  1151. * uppercase equivalents in-place, returning the original `str` pointer.
  1152. *
  1153. * \param str the string to convert in-place. Can not be NULL.
  1154. * \returns the `str` pointer passed into this function.
  1155. *
  1156. * \threadsafety It is safe to call this function from any thread.
  1157. *
  1158. * \since This function is available since SDL 3.0.0.
  1159. *
  1160. * \sa SDL_strlwr
  1161. */
  1162. extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
  1163. /**
  1164. * Convert a string to lowercase.
  1165. *
  1166. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1167. * values 'A' through 'Z' to lowercase.
  1168. *
  1169. * This function operates on a null-terminated string of bytes--even if it is
  1170. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  1171. * lowercase equivalents in-place, returning the original `str` pointer.
  1172. *
  1173. * \param str the string to convert in-place. Can not be NULL.
  1174. * \returns the `str` pointer passed into this function.
  1175. *
  1176. * \threadsafety It is safe to call this function from any thread.
  1177. *
  1178. * \since This function is available since SDL 3.0.0.
  1179. *
  1180. * \sa SDL_strupr
  1181. */
  1182. extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
  1183. extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
  1184. extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
  1185. extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
  1186. extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  1187. extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  1188. extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
  1189. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  1190. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  1191. extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
  1192. extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  1193. extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
  1194. extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  1195. extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  1196. extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  1197. extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
  1198. extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
  1199. extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  1200. extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  1201. extern SDL_DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  1202. extern SDL_DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  1203. extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  1204. /**
  1205. * Compare two null-terminated UTF-8 strings.
  1206. *
  1207. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  1208. * since effectively this function just compares bytes until it hits a
  1209. * null-terminating character. Also due to the nature of UTF-8, this can be
  1210. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  1211. *
  1212. * \param str1 the first string to compare. NULL is not permitted!
  1213. * \param str2 the second string to compare. NULL is not permitted!
  1214. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1215. * str1 is "greater than" str2, and zero if the strings match
  1216. * exactly.
  1217. *
  1218. * \threadsafety It is safe to call this function from any thread.
  1219. *
  1220. * \since This function is available since SDL 3.0.0.
  1221. */
  1222. extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  1223. /**
  1224. * Compare two UTF-8 strings up to a number of bytes.
  1225. *
  1226. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  1227. * since effectively this function just compares bytes until it hits a
  1228. * null-terminating character. Also due to the nature of UTF-8, this can be
  1229. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  1230. *
  1231. * Note that while this function is intended to be used with UTF-8, it is
  1232. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  1233. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  1234. * compare a portion of the final character.
  1235. *
  1236. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  1237. * match to this number of bytes (or both have matched to a null-terminator
  1238. * character before this number of bytes), they will be considered equal.
  1239. *
  1240. * \param str1 the first string to compare. NULL is not permitted!
  1241. * \param str2 the second string to compare. NULL is not permitted!
  1242. * \param maxlen the maximum number of _bytes_ to compare.
  1243. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1244. * str1 is "greater than" str2, and zero if the strings match
  1245. * exactly.
  1246. *
  1247. * \threadsafety It is safe to call this function from any thread.
  1248. *
  1249. * \since This function is available since SDL 3.0.0.
  1250. */
  1251. extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  1252. /**
  1253. * Compare two null-terminated UTF-8 strings, case-insensitively.
  1254. *
  1255. * This will work with Unicode strings, using a technique called
  1256. * "case-folding" to handle the vast majority of case-sensitive human
  1257. * languages regardless of system locale. It can deal with expanding values: a
  1258. * German Eszett character can compare against two ASCII 's' chars and be
  1259. * considered a match, for example. A notable exception: it does not handle
  1260. * the Turkish 'i' character; human language is complicated!
  1261. *
  1262. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  1263. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  1264. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  1265. * CHARACTER), which is to say two strings of random bits may turn out to
  1266. * match if they convert to the same amount of replacement characters.
  1267. *
  1268. * \param str1 the first string to compare. NULL is not permitted!
  1269. * \param str2 the second string to compare. NULL is not permitted!
  1270. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1271. * str1 is "greater than" str2, and zero if the strings match
  1272. * exactly.
  1273. *
  1274. * \threadsafety It is safe to call this function from any thread.
  1275. *
  1276. * \since This function is available since SDL 3.0.0.
  1277. */
  1278. extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  1279. /**
  1280. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  1281. *
  1282. * This will work with Unicode strings, using a technique called
  1283. * "case-folding" to handle the vast majority of case-sensitive human
  1284. * languages regardless of system locale. It can deal with expanding values: a
  1285. * German Eszett character can compare against two ASCII 's' chars and be
  1286. * considered a match, for example. A notable exception: it does not handle
  1287. * the Turkish 'i' character; human language is complicated!
  1288. *
  1289. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  1290. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  1291. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  1292. * CHARACTER), which is to say two strings of random bits may turn out to
  1293. * match if they convert to the same amount of replacement characters.
  1294. *
  1295. * Note that while this function is intended to be used with UTF-8, `maxlen`
  1296. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  1297. * UTF-8 sequence, it may convert a portion of the final character to one or
  1298. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  1299. * a buffer.
  1300. *
  1301. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  1302. * match to this number of bytes (or both have matched to a null-terminator
  1303. * character before this number of bytes), they will be considered equal.
  1304. *
  1305. * \param str1 the first string to compare. NULL is not permitted!
  1306. * \param str2 the second string to compare. NULL is not permitted!
  1307. * \param maxlen the maximum number of bytes to compare.
  1308. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1309. * str1 is "greater than" str2, and zero if the strings match
  1310. * exactly.
  1311. *
  1312. * \threadsafety It is safe to call this function from any thread.
  1313. *
  1314. * \since This function is available since SDL 3.0.0.
  1315. */
  1316. extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  1317. /**
  1318. * Searches a string for the first occurence of any character contained in a
  1319. * breakset, and returns a pointer from the string to that character.
  1320. *
  1321. * \param str The null-terminated string to be searched.
  1322. * \param breakset A null-terminated string containing the list of characters
  1323. * to look for.
  1324. * \returns A pointer to the location, in str, of the first occurence of a
  1325. * character present in the breakset, or NULL if none is found.
  1326. *
  1327. * \threadsafety It is safe to call this function from any thread.
  1328. *
  1329. * \since This function is available since SDL 3.0.0.
  1330. */
  1331. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char * SDL_RESTRICT str, const char * SDL_RESTRICT breakset);
  1332. /**
  1333. * The Unicode REPLACEMENT CHARACTER codepoint.
  1334. *
  1335. * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
  1336. * with encoding errors.
  1337. *
  1338. * This tends to render as something like a question mark in most places.
  1339. *
  1340. * \since This macro is available since SDL 3.0.0.
  1341. *
  1342. * \sa SDL_StepUTF8
  1343. */
  1344. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  1345. /**
  1346. * Decode a UTF-8 string, one Unicode codepoint at a time.
  1347. *
  1348. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  1349. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  1350. *
  1351. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  1352. * be adjusted, as well, subtracting the number of bytes consumed.
  1353. *
  1354. * `pslen` is allowed to be NULL, in which case the string _must_ be
  1355. * NULL-terminated, as the function will blindly read until it sees the NULL
  1356. * char.
  1357. *
  1358. * if `*pslen` is zero, it assumes the end of string is reached and returns a
  1359. * zero codepoint regardless of the contents of the string buffer.
  1360. *
  1361. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  1362. * zero, it will not advance `*pstr` or `*pslen` at all.
  1363. *
  1364. * Generally this function is called in a loop until it returns zero,
  1365. * adjusting its parameters each iteration.
  1366. *
  1367. * If an invalid UTF-8 sequence is encountered, this function returns
  1368. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  1369. * (which is to say, a multibyte sequence might produce several
  1370. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  1371. * UTF-8 sequence).
  1372. *
  1373. * Several things can generate invalid UTF-8 sequences, including overlong
  1374. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  1375. * refer to
  1376. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  1377. * for details.
  1378. *
  1379. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  1380. * \param pslen a pointer to the number of bytes in the string, to be read and
  1381. * adjusted. NULL is allowed.
  1382. * \returns the first Unicode codepoint in the string.
  1383. *
  1384. * \threadsafety It is safe to call this function from any thread.
  1385. *
  1386. * \since This function is available since SDL 3.0.0.
  1387. */
  1388. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  1389. /**
  1390. * Convert a single Unicode codepoint to UTF-8.
  1391. *
  1392. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  1393. * function may generate between 1 and 4 bytes of output.
  1394. *
  1395. * This function returns the first byte _after_ the newly-written UTF-8
  1396. * sequence, which is useful for encoding multiple codepoints in a loop, or
  1397. * knowing where to write a NULL-terminator character to end the string (in
  1398. * either case, plan to have a buffer of _more_ than 4 bytes!).
  1399. *
  1400. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  1401. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  1402. * codepoint instead, and not set an error.
  1403. *
  1404. * If `dst` is NULL, this returns NULL immediately without writing to the
  1405. * pointer and without setting an error.
  1406. *
  1407. * \param codepoint a Unicode codepoint to convert to UTF-8.
  1408. * \param dst the location to write the encoded UTF-8. Must point to at least
  1409. * 4 bytes!
  1410. * \returns the first byte past the newly-written UTF-8 sequence.
  1411. *
  1412. * \threadsafety It is safe to call this function from any thread.
  1413. *
  1414. * \since This function is available since SDL 3.0.0.
  1415. */
  1416. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  1417. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  1418. 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);
  1419. 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);
  1420. 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);
  1421. 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);
  1422. extern SDL_DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap);
  1423. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  1424. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  1425. /**
  1426. * Seeds the pseudo-random number generator.
  1427. *
  1428. * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
  1429. * of 'random' numbers.
  1430. *
  1431. * \param seed the value to use as a random number seed, or 0 to use
  1432. * SDL_GetPerformanceCounter().
  1433. *
  1434. * \threadsafety This should be called on the same thread that calls
  1435. * SDL_rand*()
  1436. *
  1437. * \since This function is available since SDL 3.0.0.
  1438. *
  1439. * \sa SDL_rand
  1440. * \sa SDL_rand_bits
  1441. * \sa SDL_randf
  1442. */
  1443. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  1444. /**
  1445. * Generate a pseudo-random number less than n for positive n
  1446. *
  1447. * The method used is faster and of better quality than `rand() % n`. Odds are
  1448. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  1449. * much worse as n gets bigger.
  1450. *
  1451. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  1452. * 1..6
  1453. *
  1454. * If you want to generate a pseudo-random number in the full range of Sint32,
  1455. * you should use: (Sint32)SDL_rand_bits()
  1456. *
  1457. * If you want reproducible output, be sure to initialize with SDL_srand()
  1458. * first.
  1459. *
  1460. * There are no guarantees as to the quality of the random sequence produced,
  1461. * and this should not be used for security (cryptography, passwords) or where
  1462. * money is on the line (loot-boxes, casinos). There are many random number
  1463. * libraries available with different characteristics and you should pick one
  1464. * of those to meet any serious needs.
  1465. *
  1466. * \param n the number of possible outcomes. n must be positive.
  1467. * \returns a random value in the range of [0 .. n-1].
  1468. *
  1469. * \threadsafety All calls should be made from a single thread
  1470. *
  1471. * \since This function is available since SDL 3.0.0.
  1472. *
  1473. * \sa SDL_srand
  1474. * \sa SDL_randf
  1475. */
  1476. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  1477. /**
  1478. * Generate a uniform pseudo-random floating point number less than 1.0
  1479. *
  1480. * If you want reproducible output, be sure to initialize with SDL_srand()
  1481. * first.
  1482. *
  1483. * There are no guarantees as to the quality of the random sequence produced,
  1484. * and this should not be used for security (cryptography, passwords) or where
  1485. * money is on the line (loot-boxes, casinos). There are many random number
  1486. * libraries available with different characteristics and you should pick one
  1487. * of those to meet any serious needs.
  1488. *
  1489. * \returns a random value in the range of [0.0, 1.0).
  1490. *
  1491. * \threadsafety All calls should be made from a single thread
  1492. *
  1493. * \since This function is available since SDL 3.0.0.
  1494. *
  1495. * \sa SDL_srand
  1496. * \sa SDL_rand
  1497. */
  1498. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  1499. /**
  1500. * Generate 32 pseudo-random bits.
  1501. *
  1502. * You likely want to use SDL_rand() to get a psuedo-random number instead.
  1503. *
  1504. * There are no guarantees as to the quality of the random sequence produced,
  1505. * and this should not be used for security (cryptography, passwords) or where
  1506. * money is on the line (loot-boxes, casinos). There are many random number
  1507. * libraries available with different characteristics and you should pick one
  1508. * of those to meet any serious needs.
  1509. *
  1510. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  1511. *
  1512. * \threadsafety All calls should be made from a single thread
  1513. *
  1514. * \since This function is available since SDL 3.0.0.
  1515. *
  1516. * \sa SDL_rand
  1517. * \sa SDL_randf
  1518. * \sa SDL_srand
  1519. */
  1520. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  1521. /**
  1522. * Generate a pseudo-random number less than n for positive n
  1523. *
  1524. * The method used is faster and of better quality than `rand() % n`. Odds are
  1525. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  1526. * much worse as n gets bigger.
  1527. *
  1528. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  1529. * 0..5 to 1..6
  1530. *
  1531. * If you want to generate a pseudo-random number in the full range of Sint32,
  1532. * you should use: (Sint32)SDL_rand_bits_r(state)
  1533. *
  1534. * There are no guarantees as to the quality of the random sequence produced,
  1535. * and this should not be used for security (cryptography, passwords) or where
  1536. * money is on the line (loot-boxes, casinos). There are many random number
  1537. * libraries available with different characteristics and you should pick one
  1538. * of those to meet any serious needs.
  1539. *
  1540. * \param state a pointer to the current random number state, this may not be
  1541. * NULL.
  1542. * \param n the number of possible outcomes. n must be positive.
  1543. * \returns a random value in the range of [0 .. n-1].
  1544. *
  1545. * \threadsafety This function is thread-safe, as long as the state pointer
  1546. * isn't shared between threads.
  1547. *
  1548. * \since This function is available since SDL 3.0.0.
  1549. *
  1550. * \sa SDL_rand
  1551. * \sa SDL_rand_bits_r
  1552. * \sa SDL_randf_r
  1553. */
  1554. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  1555. /**
  1556. * Generate a uniform pseudo-random floating point number less than 1.0
  1557. *
  1558. * If you want reproducible output, be sure to initialize with SDL_srand()
  1559. * first.
  1560. *
  1561. * There are no guarantees as to the quality of the random sequence produced,
  1562. * and this should not be used for security (cryptography, passwords) or where
  1563. * money is on the line (loot-boxes, casinos). There are many random number
  1564. * libraries available with different characteristics and you should pick one
  1565. * of those to meet any serious needs.
  1566. *
  1567. * \param state a pointer to the current random number state, this may not be
  1568. * NULL.
  1569. * \returns a random value in the range of [0.0, 1.0).
  1570. *
  1571. * \threadsafety This function is thread-safe, as long as the state pointer
  1572. * isn't shared between threads.
  1573. *
  1574. * \since This function is available since SDL 3.0.0.
  1575. *
  1576. * \sa SDL_rand_bits_r
  1577. * \sa SDL_rand_r
  1578. * \sa SDL_randf
  1579. */
  1580. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  1581. /**
  1582. * Generate 32 pseudo-random bits.
  1583. *
  1584. * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
  1585. *
  1586. * There are no guarantees as to the quality of the random sequence produced,
  1587. * and this should not be used for security (cryptography, passwords) or where
  1588. * money is on the line (loot-boxes, casinos). There are many random number
  1589. * libraries available with different characteristics and you should pick one
  1590. * of those to meet any serious needs.
  1591. *
  1592. * \param state a pointer to the current random number state, this may not be
  1593. * NULL.
  1594. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  1595. *
  1596. * \threadsafety This function is thread-safe, as long as the state pointer
  1597. * isn't shared between threads.
  1598. *
  1599. * \since This function is available since SDL 3.0.0.
  1600. *
  1601. * \sa SDL_rand_r
  1602. * \sa SDL_randf_r
  1603. */
  1604. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  1605. #ifndef SDL_PI_D
  1606. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  1607. #endif
  1608. #ifndef SDL_PI_F
  1609. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  1610. #endif
  1611. /**
  1612. * Compute the arc cosine of `x`.
  1613. *
  1614. * The definition of `y = acos(x)` is `x = cos(y)`.
  1615. *
  1616. * Domain: `-1 <= x <= 1`
  1617. *
  1618. * Range: `0 <= y <= Pi`
  1619. *
  1620. * This function operates on double-precision floating point values, use
  1621. * SDL_acosf for single-precision floats.
  1622. *
  1623. * This function may use a different approximation across different versions,
  1624. * platforms and configurations. i.e, it can return a different value given
  1625. * the same input on different machines or operating systems, or if SDL is
  1626. * updated.
  1627. *
  1628. * \param x floating point value.
  1629. * \returns arc cosine of `x`, in radians.
  1630. *
  1631. * \threadsafety It is safe to call this function from any thread.
  1632. *
  1633. * \since This function is available since SDL 3.0.0.
  1634. *
  1635. * \sa SDL_acosf
  1636. * \sa SDL_asin
  1637. * \sa SDL_cos
  1638. */
  1639. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  1640. /**
  1641. * Compute the arc cosine of `x`.
  1642. *
  1643. * The definition of `y = acos(x)` is `x = cos(y)`.
  1644. *
  1645. * Domain: `-1 <= x <= 1`
  1646. *
  1647. * Range: `0 <= y <= Pi`
  1648. *
  1649. * This function operates on single-precision floating point values, use
  1650. * SDL_acos for double-precision floats.
  1651. *
  1652. * This function may use a different approximation across different versions,
  1653. * platforms and configurations. i.e, it can return a different value given
  1654. * the same input on different machines or operating systems, or if SDL is
  1655. * updated.
  1656. *
  1657. * \param x floating point value.
  1658. * \returns arc cosine of `x`, in radians.
  1659. *
  1660. * \threadsafety It is safe to call this function from any thread.
  1661. *
  1662. * \since This function is available since SDL 3.0.0.
  1663. *
  1664. * \sa SDL_acos
  1665. * \sa SDL_asinf
  1666. * \sa SDL_cosf
  1667. */
  1668. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  1669. /**
  1670. * Compute the arc sine of `x`.
  1671. *
  1672. * The definition of `y = asin(x)` is `x = sin(y)`.
  1673. *
  1674. * Domain: `-1 <= x <= 1`
  1675. *
  1676. * Range: `-Pi/2 <= y <= Pi/2`
  1677. *
  1678. * This function operates on double-precision floating point values, use
  1679. * SDL_asinf for single-precision floats.
  1680. *
  1681. * This function may use a different approximation across different versions,
  1682. * platforms and configurations. i.e, it can return a different value given
  1683. * the same input on different machines or operating systems, or if SDL is
  1684. * updated.
  1685. *
  1686. * \param x floating point value.
  1687. * \returns arc sine of `x`, in radians.
  1688. *
  1689. * \threadsafety It is safe to call this function from any thread.
  1690. *
  1691. * \since This function is available since SDL 3.0.0.
  1692. *
  1693. * \sa SDL_asinf
  1694. * \sa SDL_acos
  1695. * \sa SDL_sin
  1696. */
  1697. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  1698. /**
  1699. * Compute the arc sine of `x`.
  1700. *
  1701. * The definition of `y = asin(x)` is `x = sin(y)`.
  1702. *
  1703. * Domain: `-1 <= x <= 1`
  1704. *
  1705. * Range: `-Pi/2 <= y <= Pi/2`
  1706. *
  1707. * This function operates on single-precision floating point values, use
  1708. * SDL_asin for double-precision floats.
  1709. *
  1710. * This function may use a different approximation across different versions,
  1711. * platforms and configurations. i.e, it can return a different value given
  1712. * the same input on different machines or operating systems, or if SDL is
  1713. * updated.
  1714. *
  1715. * \param x floating point value.
  1716. * \returns arc sine of `x`, in radians.
  1717. *
  1718. * \threadsafety It is safe to call this function from any thread.
  1719. *
  1720. * \since This function is available since SDL 3.0.0.
  1721. *
  1722. * \sa SDL_asin
  1723. * \sa SDL_acosf
  1724. * \sa SDL_sinf
  1725. */
  1726. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  1727. /**
  1728. * Compute the arc tangent of `x`.
  1729. *
  1730. * The definition of `y = atan(x)` is `x = tan(y)`.
  1731. *
  1732. * Domain: `-INF <= x <= INF`
  1733. *
  1734. * Range: `-Pi/2 <= y <= Pi/2`
  1735. *
  1736. * This function operates on double-precision floating point values, use
  1737. * SDL_atanf for single-precision floats.
  1738. *
  1739. * To calculate the arc tangent of y / x, use SDL_atan2.
  1740. *
  1741. * This function may use a different approximation across different versions,
  1742. * platforms and configurations. i.e, it can return a different value given
  1743. * the same input on different machines or operating systems, or if SDL is
  1744. * updated.
  1745. *
  1746. * \param x floating point value.
  1747. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1748. *
  1749. * \threadsafety It is safe to call this function from any thread.
  1750. *
  1751. * \since This function is available since SDL 3.0.0.
  1752. *
  1753. * \sa SDL_atanf
  1754. * \sa SDL_atan2
  1755. * \sa SDL_tan
  1756. */
  1757. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  1758. /**
  1759. * Compute the arc tangent of `x`.
  1760. *
  1761. * The definition of `y = atan(x)` is `x = tan(y)`.
  1762. *
  1763. * Domain: `-INF <= x <= INF`
  1764. *
  1765. * Range: `-Pi/2 <= y <= Pi/2`
  1766. *
  1767. * This function operates on single-precision floating point values, use
  1768. * SDL_atan for dboule-precision floats.
  1769. *
  1770. * To calculate the arc tangent of y / x, use SDL_atan2f.
  1771. *
  1772. * This function may use a different approximation across different versions,
  1773. * platforms and configurations. i.e, it can return a different value given
  1774. * the same input on different machines or operating systems, or if SDL is
  1775. * updated.
  1776. *
  1777. * \param x floating point value.
  1778. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1779. *
  1780. * \threadsafety It is safe to call this function from any thread.
  1781. *
  1782. * \since This function is available since SDL 3.0.0.
  1783. *
  1784. * \sa SDL_atan
  1785. * \sa SDL_atan2f
  1786. * \sa SDL_tanf
  1787. */
  1788. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  1789. /**
  1790. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1791. * the result's quadrant.
  1792. *
  1793. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1794. * of z is determined based on the signs of x and y.
  1795. *
  1796. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1797. *
  1798. * Range: `-Pi/2 <= y <= Pi/2`
  1799. *
  1800. * This function operates on double-precision floating point values, use
  1801. * SDL_atan2f for single-precision floats.
  1802. *
  1803. * To calculate the arc tangent of a single value, use SDL_atan.
  1804. *
  1805. * This function may use a different approximation across different versions,
  1806. * platforms and configurations. i.e, it can return a different value given
  1807. * the same input on different machines or operating systems, or if SDL is
  1808. * updated.
  1809. *
  1810. * \param y floating point value of the numerator (y coordinate).
  1811. * \param x floating point value of the denominator (x coordinate).
  1812. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1813. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1814. *
  1815. * \threadsafety It is safe to call this function from any thread.
  1816. *
  1817. * \since This function is available since SDL 3.0.0.
  1818. *
  1819. * \sa SDL_atan2f
  1820. * \sa SDL_atan
  1821. * \sa SDL_tan
  1822. */
  1823. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  1824. /**
  1825. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1826. * the result's quadrant.
  1827. *
  1828. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1829. * of z is determined based on the signs of x and y.
  1830. *
  1831. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1832. *
  1833. * Range: `-Pi/2 <= y <= Pi/2`
  1834. *
  1835. * This function operates on single-precision floating point values, use
  1836. * SDL_atan2 for double-precision floats.
  1837. *
  1838. * To calculate the arc tangent of a single value, use SDL_atanf.
  1839. *
  1840. * This function may use a different approximation across different versions,
  1841. * platforms and configurations. i.e, it can return a different value given
  1842. * the same input on different machines or operating systems, or if SDL is
  1843. * updated.
  1844. *
  1845. * \param y floating point value of the numerator (y coordinate).
  1846. * \param x floating point value of the denominator (x coordinate).
  1847. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1848. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1849. *
  1850. * \threadsafety It is safe to call this function from any thread.
  1851. *
  1852. * \since This function is available since SDL 3.0.0.
  1853. *
  1854. * \sa SDL_atan2f
  1855. * \sa SDL_atan
  1856. * \sa SDL_tan
  1857. */
  1858. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  1859. /**
  1860. * Compute the ceiling of `x`.
  1861. *
  1862. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1863. * rounded up to the nearest integer.
  1864. *
  1865. * Domain: `-INF <= x <= INF`
  1866. *
  1867. * Range: `-INF <= y <= INF`, y integer
  1868. *
  1869. * This function operates on double-precision floating point values, use
  1870. * SDL_ceilf for single-precision floats.
  1871. *
  1872. * \param x floating point value.
  1873. * \returns the ceiling of `x`.
  1874. *
  1875. * \threadsafety It is safe to call this function from any thread.
  1876. *
  1877. * \since This function is available since SDL 3.0.0.
  1878. *
  1879. * \sa SDL_ceilf
  1880. * \sa SDL_floor
  1881. * \sa SDL_trunc
  1882. * \sa SDL_round
  1883. * \sa SDL_lround
  1884. */
  1885. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  1886. /**
  1887. * Compute the ceiling of `x`.
  1888. *
  1889. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1890. * rounded up to the nearest integer.
  1891. *
  1892. * Domain: `-INF <= x <= INF`
  1893. *
  1894. * Range: `-INF <= y <= INF`, y integer
  1895. *
  1896. * This function operates on single-precision floating point values, use
  1897. * SDL_ceil for double-precision floats.
  1898. *
  1899. * \param x floating point value.
  1900. * \returns the ceiling of `x`.
  1901. *
  1902. * \threadsafety It is safe to call this function from any thread.
  1903. *
  1904. * \since This function is available since SDL 3.0.0.
  1905. *
  1906. * \sa SDL_ceil
  1907. * \sa SDL_floorf
  1908. * \sa SDL_truncf
  1909. * \sa SDL_roundf
  1910. * \sa SDL_lroundf
  1911. */
  1912. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  1913. /**
  1914. * Copy the sign of one floating-point value to another.
  1915. *
  1916. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1917. *
  1918. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1919. *
  1920. * Range: `-INF <= z <= INF`
  1921. *
  1922. * This function operates on double-precision floating point values, use
  1923. * SDL_copysignf for single-precision floats.
  1924. *
  1925. * \param x floating point value to use as the magnitude.
  1926. * \param y floating point value to use as the sign.
  1927. * \returns the floating point value with the sign of y and the magnitude of
  1928. * x.
  1929. *
  1930. * \threadsafety It is safe to call this function from any thread.
  1931. *
  1932. * \since This function is available since SDL 3.0.0.
  1933. *
  1934. * \sa SDL_copysignf
  1935. * \sa SDL_fabs
  1936. */
  1937. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  1938. /**
  1939. * Copy the sign of one floating-point value to another.
  1940. *
  1941. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1942. *
  1943. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1944. *
  1945. * Range: `-INF <= z <= INF`
  1946. *
  1947. * This function operates on single-precision floating point values, use
  1948. * SDL_copysign for double-precision floats.
  1949. *
  1950. * \param x floating point value to use as the magnitude.
  1951. * \param y floating point value to use as the sign.
  1952. * \returns the floating point value with the sign of y and the magnitude of
  1953. * x.
  1954. *
  1955. * \threadsafety It is safe to call this function from any thread.
  1956. *
  1957. * \since This function is available since SDL 3.0.0.
  1958. *
  1959. * \sa SDL_copysignf
  1960. * \sa SDL_fabsf
  1961. */
  1962. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  1963. /**
  1964. * Compute the cosine of `x`.
  1965. *
  1966. * Domain: `-INF <= x <= INF`
  1967. *
  1968. * Range: `-1 <= y <= 1`
  1969. *
  1970. * This function operates on double-precision floating point values, use
  1971. * SDL_cosf for single-precision floats.
  1972. *
  1973. * This function may use a different approximation across different versions,
  1974. * platforms and configurations. i.e, it can return a different value given
  1975. * the same input on different machines or operating systems, or if SDL is
  1976. * updated.
  1977. *
  1978. * \param x floating point value, in radians.
  1979. * \returns cosine of `x`.
  1980. *
  1981. * \threadsafety It is safe to call this function from any thread.
  1982. *
  1983. * \since This function is available since SDL 3.0.0.
  1984. *
  1985. * \sa SDL_cosf
  1986. * \sa SDL_acos
  1987. * \sa SDL_sin
  1988. */
  1989. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  1990. /**
  1991. * Compute the cosine of `x`.
  1992. *
  1993. * Domain: `-INF <= x <= INF`
  1994. *
  1995. * Range: `-1 <= y <= 1`
  1996. *
  1997. * This function operates on single-precision floating point values, use
  1998. * SDL_cos for double-precision floats.
  1999. *
  2000. * This function may use a different approximation across different versions,
  2001. * platforms and configurations. i.e, it can return a different value given
  2002. * the same input on different machines or operating systems, or if SDL is
  2003. * updated.
  2004. *
  2005. * \param x floating point value, in radians.
  2006. * \returns cosine of `x`.
  2007. *
  2008. * \threadsafety It is safe to call this function from any thread.
  2009. *
  2010. * \since This function is available since SDL 3.0.0.
  2011. *
  2012. * \sa SDL_cos
  2013. * \sa SDL_acosf
  2014. * \sa SDL_sinf
  2015. */
  2016. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  2017. /**
  2018. * Compute the exponential of `x`.
  2019. *
  2020. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2021. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  2022. *
  2023. * Domain: `-INF <= x <= INF`
  2024. *
  2025. * Range: `0 <= y <= INF`
  2026. *
  2027. * The output will overflow if `exp(x)` is too large to be represented.
  2028. *
  2029. * This function operates on double-precision floating point values, use
  2030. * SDL_expf for single-precision floats.
  2031. *
  2032. * This function may use a different approximation across different versions,
  2033. * platforms and configurations. i.e, it can return a different value given
  2034. * the same input on different machines or operating systems, or if SDL is
  2035. * updated.
  2036. *
  2037. * \param x floating point value.
  2038. * \returns value of `e^x`.
  2039. *
  2040. * \threadsafety It is safe to call this function from any thread.
  2041. *
  2042. * \since This function is available since SDL 3.0.0.
  2043. *
  2044. * \sa SDL_expf
  2045. * \sa SDL_log
  2046. */
  2047. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  2048. /**
  2049. * Compute the exponential of `x`.
  2050. *
  2051. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2052. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  2053. *
  2054. * Domain: `-INF <= x <= INF`
  2055. *
  2056. * Range: `0 <= y <= INF`
  2057. *
  2058. * The output will overflow if `exp(x)` is too large to be represented.
  2059. *
  2060. * This function operates on single-precision floating point values, use
  2061. * SDL_exp for double-precision floats.
  2062. *
  2063. * This function may use a different approximation across different versions,
  2064. * platforms and configurations. i.e, it can return a different value given
  2065. * the same input on different machines or operating systems, or if SDL is
  2066. * updated.
  2067. *
  2068. * \param x floating point value.
  2069. * \returns value of `e^x`.
  2070. *
  2071. * \threadsafety It is safe to call this function from any thread.
  2072. *
  2073. * \since This function is available since SDL 3.0.0.
  2074. *
  2075. * \sa SDL_exp
  2076. * \sa SDL_logf
  2077. */
  2078. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  2079. /**
  2080. * Compute the absolute value of `x`
  2081. *
  2082. * Domain: `-INF <= x <= INF`
  2083. *
  2084. * Range: `0 <= y <= INF`
  2085. *
  2086. * This function operates on double-precision floating point values, use
  2087. * SDL_copysignf for single-precision floats.
  2088. *
  2089. * \param x floating point value to use as the magnitude.
  2090. * \returns the absolute value of `x`.
  2091. *
  2092. * \threadsafety It is safe to call this function from any thread.
  2093. *
  2094. * \since This function is available since SDL 3.0.0.
  2095. *
  2096. * \sa SDL_fabsf
  2097. */
  2098. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  2099. /**
  2100. * Compute the absolute value of `x`
  2101. *
  2102. * Domain: `-INF <= x <= INF`
  2103. *
  2104. * Range: `0 <= y <= INF`
  2105. *
  2106. * This function operates on single-precision floating point values, use
  2107. * SDL_copysignf for double-precision floats.
  2108. *
  2109. * \param x floating point value to use as the magnitude.
  2110. * \returns the absolute value of `x`.
  2111. *
  2112. * \threadsafety It is safe to call this function from any thread.
  2113. *
  2114. * \since This function is available since SDL 3.0.0.
  2115. *
  2116. * \sa SDL_fabs
  2117. */
  2118. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  2119. /**
  2120. * Compute the floor of `x`.
  2121. *
  2122. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2123. * rounded down to the nearest integer.
  2124. *
  2125. * Domain: `-INF <= x <= INF`
  2126. *
  2127. * Range: `-INF <= y <= INF`, y integer
  2128. *
  2129. * This function operates on double-precision floating point values, use
  2130. * SDL_floorf for single-precision floats.
  2131. *
  2132. * \param x floating point value.
  2133. * \returns the floor of `x`.
  2134. *
  2135. * \threadsafety It is safe to call this function from any thread.
  2136. *
  2137. * \since This function is available since SDL 3.0.0.
  2138. *
  2139. * \sa SDL_floorf
  2140. * \sa SDL_ceil
  2141. * \sa SDL_trunc
  2142. * \sa SDL_round
  2143. * \sa SDL_lround
  2144. */
  2145. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  2146. /**
  2147. * Compute the floor of `x`.
  2148. *
  2149. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2150. * rounded down to the nearest integer.
  2151. *
  2152. * Domain: `-INF <= x <= INF`
  2153. *
  2154. * Range: `-INF <= y <= INF`, y integer
  2155. *
  2156. * This function operates on single-precision floating point values, use
  2157. * SDL_floorf for double-precision floats.
  2158. *
  2159. * \param x floating point value.
  2160. * \returns the floor of `x`.
  2161. *
  2162. * \threadsafety It is safe to call this function from any thread.
  2163. *
  2164. * \since This function is available since SDL 3.0.0.
  2165. *
  2166. * \sa SDL_floor
  2167. * \sa SDL_ceilf
  2168. * \sa SDL_truncf
  2169. * \sa SDL_roundf
  2170. * \sa SDL_lroundf
  2171. */
  2172. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  2173. /**
  2174. * Truncate `x` to an integer.
  2175. *
  2176. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2177. * the fractional part of `x`, leaving only the integer part.
  2178. *
  2179. * Domain: `-INF <= x <= INF`
  2180. *
  2181. * Range: `-INF <= y <= INF`, y integer
  2182. *
  2183. * This function operates on double-precision floating point values, use
  2184. * SDL_truncf for single-precision floats.
  2185. *
  2186. * \param x floating point value.
  2187. * \returns `x` truncated to an integer.
  2188. *
  2189. * \threadsafety It is safe to call this function from any thread.
  2190. *
  2191. * \since This function is available since SDL 3.0.0.
  2192. *
  2193. * \sa SDL_truncf
  2194. * \sa SDL_fmod
  2195. * \sa SDL_ceil
  2196. * \sa SDL_floor
  2197. * \sa SDL_round
  2198. * \sa SDL_lround
  2199. */
  2200. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  2201. /**
  2202. * Truncate `x` to an integer.
  2203. *
  2204. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2205. * the fractional part of `x`, leaving only the integer part.
  2206. *
  2207. * Domain: `-INF <= x <= INF`
  2208. *
  2209. * Range: `-INF <= y <= INF`, y integer
  2210. *
  2211. * This function operates on single-precision floating point values, use
  2212. * SDL_truncf for double-precision floats.
  2213. *
  2214. * \param x floating point value.
  2215. * \returns `x` truncated to an integer.
  2216. *
  2217. * \threadsafety It is safe to call this function from any thread.
  2218. *
  2219. * \since This function is available since SDL 3.0.0.
  2220. *
  2221. * \sa SDL_trunc
  2222. * \sa SDL_fmodf
  2223. * \sa SDL_ceilf
  2224. * \sa SDL_floorf
  2225. * \sa SDL_roundf
  2226. * \sa SDL_lroundf
  2227. */
  2228. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  2229. /**
  2230. * Return the floating-point remainder of `x / y`
  2231. *
  2232. * Divides `x` by `y`, and returns the remainder.
  2233. *
  2234. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  2235. *
  2236. * Range: `-y <= z <= y`
  2237. *
  2238. * This function operates on double-precision floating point values, use
  2239. * SDL_fmodf for single-precision floats.
  2240. *
  2241. * \param x the numerator.
  2242. * \param y the denominator. Must not be 0.
  2243. * \returns the remainder of `x / y`.
  2244. *
  2245. * \threadsafety It is safe to call this function from any thread.
  2246. *
  2247. * \since This function is available since SDL 3.0.0.
  2248. *
  2249. * \sa SDL_fmodf
  2250. * \sa SDL_modf
  2251. * \sa SDL_trunc
  2252. * \sa SDL_ceil
  2253. * \sa SDL_floor
  2254. * \sa SDL_round
  2255. * \sa SDL_lround
  2256. */
  2257. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  2258. /**
  2259. * Return the floating-point remainder of `x / y`
  2260. *
  2261. * Divides `x` by `y`, and returns the remainder.
  2262. *
  2263. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  2264. *
  2265. * Range: `-y <= z <= y`
  2266. *
  2267. * This function operates on single-precision floating point values, use
  2268. * SDL_fmod for single-precision floats.
  2269. *
  2270. * \param x the numerator.
  2271. * \param y the denominator. Must not be 0.
  2272. * \returns the remainder of `x / y`.
  2273. *
  2274. * \threadsafety It is safe to call this function from any thread.
  2275. *
  2276. * \since This function is available since SDL 3.0.0.
  2277. *
  2278. * \sa SDL_fmod
  2279. * \sa SDL_truncf
  2280. * \sa SDL_modff
  2281. * \sa SDL_ceilf
  2282. * \sa SDL_floorf
  2283. * \sa SDL_roundf
  2284. * \sa SDL_lroundf
  2285. */
  2286. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  2287. /**
  2288. * Return whether the value is infinity.
  2289. *
  2290. * \param x double-precision floating point value.
  2291. * \returns non-zero if the value is infinity, 0 otherwise.
  2292. *
  2293. * \threadsafety It is safe to call this function from any thread.
  2294. *
  2295. * \since This function is available since SDL 3.0.0.
  2296. *
  2297. * \sa SDL_isinff
  2298. */
  2299. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  2300. /**
  2301. * Return whether the value is infinity.
  2302. *
  2303. * \param x floating point value.
  2304. * \returns non-zero if the value is infinity, 0 otherwise.
  2305. *
  2306. * \threadsafety It is safe to call this function from any thread.
  2307. *
  2308. * \since This function is available since SDL 3.0.0.
  2309. *
  2310. * \sa SDL_isinf
  2311. */
  2312. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  2313. /**
  2314. * Return whether the value is NaN.
  2315. *
  2316. * \param x double-precision floating point value.
  2317. * \returns non-zero if the value is NaN, 0 otherwise.
  2318. *
  2319. * \threadsafety It is safe to call this function from any thread.
  2320. *
  2321. * \since This function is available since SDL 3.0.0.
  2322. *
  2323. * \sa SDL_isnanf
  2324. */
  2325. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  2326. /**
  2327. * Return whether the value is NaN.
  2328. *
  2329. * \param x floating point value.
  2330. * \returns non-zero if the value is NaN, 0 otherwise.
  2331. *
  2332. * \threadsafety It is safe to call this function from any thread.
  2333. *
  2334. * \since This function is available since SDL 3.0.0.
  2335. *
  2336. * \sa SDL_isnan
  2337. */
  2338. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  2339. /**
  2340. * Compute the natural logarithm of `x`.
  2341. *
  2342. * Domain: `0 < x <= INF`
  2343. *
  2344. * Range: `-INF <= y <= INF`
  2345. *
  2346. * It is an error for `x` to be less than or equal to 0.
  2347. *
  2348. * This function operates on double-precision floating point values, use
  2349. * SDL_logf for single-precision floats.
  2350. *
  2351. * This function may use a different approximation across different versions,
  2352. * platforms and configurations. i.e, it can return a different value given
  2353. * the same input on different machines or operating systems, or if SDL is
  2354. * updated.
  2355. *
  2356. * \param x floating point value. Must be greater than 0.
  2357. * \returns the natural logarithm of `x`.
  2358. *
  2359. * \threadsafety It is safe to call this function from any thread.
  2360. *
  2361. * \since This function is available since SDL 3.0.0.
  2362. *
  2363. * \sa SDL_logf
  2364. * \sa SDL_log10
  2365. * \sa SDL_exp
  2366. */
  2367. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  2368. /**
  2369. * Compute the natural logarithm of `x`.
  2370. *
  2371. * Domain: `0 < x <= INF`
  2372. *
  2373. * Range: `-INF <= y <= INF`
  2374. *
  2375. * It is an error for `x` to be less than or equal to 0.
  2376. *
  2377. * This function operates on single-precision floating point values, use
  2378. * SDL_log for double-precision floats.
  2379. *
  2380. * This function may use a different approximation across different versions,
  2381. * platforms and configurations. i.e, it can return a different value given
  2382. * the same input on different machines or operating systems, or if SDL is
  2383. * updated.
  2384. *
  2385. * \param x floating point value. Must be greater than 0.
  2386. * \returns the natural logarithm of `x`.
  2387. *
  2388. * \threadsafety It is safe to call this function from any thread.
  2389. *
  2390. * \since This function is available since SDL 3.0.0.
  2391. *
  2392. * \sa SDL_log
  2393. * \sa SDL_expf
  2394. */
  2395. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  2396. /**
  2397. * Compute the base-10 logarithm of `x`.
  2398. *
  2399. * Domain: `0 < x <= INF`
  2400. *
  2401. * Range: `-INF <= y <= INF`
  2402. *
  2403. * It is an error for `x` to be less than or equal to 0.
  2404. *
  2405. * This function operates on double-precision floating point values, use
  2406. * SDL_log10f for single-precision floats.
  2407. *
  2408. * This function may use a different approximation across different versions,
  2409. * platforms and configurations. i.e, it can return a different value given
  2410. * the same input on different machines or operating systems, or if SDL is
  2411. * updated.
  2412. *
  2413. * \param x floating point value. Must be greater than 0.
  2414. * \returns the logarithm of `x`.
  2415. *
  2416. * \threadsafety It is safe to call this function from any thread.
  2417. *
  2418. * \since This function is available since SDL 3.0.0.
  2419. *
  2420. * \sa SDL_log10f
  2421. * \sa SDL_log
  2422. * \sa SDL_pow
  2423. */
  2424. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  2425. /**
  2426. * Compute the base-10 logarithm of `x`.
  2427. *
  2428. * Domain: `0 < x <= INF`
  2429. *
  2430. * Range: `-INF <= y <= INF`
  2431. *
  2432. * It is an error for `x` to be less than or equal to 0.
  2433. *
  2434. * This function operates on single-precision floating point values, use
  2435. * SDL_log10 for double-precision floats.
  2436. *
  2437. * This function may use a different approximation across different versions,
  2438. * platforms and configurations. i.e, it can return a different value given
  2439. * the same input on different machines or operating systems, or if SDL is
  2440. * updated.
  2441. *
  2442. * \param x floating point value. Must be greater than 0.
  2443. * \returns the logarithm of `x`.
  2444. *
  2445. * \threadsafety It is safe to call this function from any thread.
  2446. *
  2447. * \since This function is available since SDL 3.0.0.
  2448. *
  2449. * \sa SDL_log10
  2450. * \sa SDL_logf
  2451. * \sa SDL_powf
  2452. */
  2453. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  2454. /**
  2455. * Split `x` into integer and fractional parts
  2456. *
  2457. * This function operates on double-precision floating point values, use
  2458. * SDL_modff for single-precision floats.
  2459. *
  2460. * \param x floating point value.
  2461. * \param y output pointer to store the integer part of `x`.
  2462. * \returns the fractional part of `x`.
  2463. *
  2464. * \threadsafety It is safe to call this function from any thread.
  2465. *
  2466. * \since This function is available since SDL 3.0.0.
  2467. *
  2468. * \sa SDL_modff
  2469. * \sa SDL_trunc
  2470. * \sa SDL_fmod
  2471. */
  2472. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  2473. /**
  2474. * Split `x` into integer and fractional parts
  2475. *
  2476. * This function operates on single-precision floating point values, use
  2477. * SDL_modf for double-precision floats.
  2478. *
  2479. * \param x floating point value.
  2480. * \param y output pointer to store the integer part of `x`.
  2481. * \returns the fractional part of `x`.
  2482. *
  2483. * \threadsafety It is safe to call this function from any thread.
  2484. *
  2485. * \since This function is available since SDL 3.0.0.
  2486. *
  2487. * \sa SDL_modf
  2488. * \sa SDL_truncf
  2489. * \sa SDL_fmodf
  2490. */
  2491. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  2492. /**
  2493. * Raise `x` to the power `y`
  2494. *
  2495. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2496. *
  2497. * Range: `-INF <= z <= INF`
  2498. *
  2499. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2500. * instead.
  2501. *
  2502. * This function operates on double-precision floating point values, use
  2503. * SDL_powf for single-precision floats.
  2504. *
  2505. * This function may use a different approximation across different versions,
  2506. * platforms and configurations. i.e, it can return a different value given
  2507. * the same input on different machines or operating systems, or if SDL is
  2508. * updated.
  2509. *
  2510. * \param x the base.
  2511. * \param y the exponent.
  2512. * \returns `x` raised to the power `y`.
  2513. *
  2514. * \threadsafety It is safe to call this function from any thread.
  2515. *
  2516. * \since This function is available since SDL 3.0.0.
  2517. *
  2518. * \sa SDL_powf
  2519. * \sa SDL_exp
  2520. * \sa SDL_log
  2521. */
  2522. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  2523. /**
  2524. * Raise `x` to the power `y`
  2525. *
  2526. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2527. *
  2528. * Range: `-INF <= z <= INF`
  2529. *
  2530. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2531. * instead.
  2532. *
  2533. * This function operates on single-precision floating point values, use
  2534. * SDL_powf for double-precision floats.
  2535. *
  2536. * This function may use a different approximation across different versions,
  2537. * platforms and configurations. i.e, it can return a different value given
  2538. * the same input on different machines or operating systems, or if SDL is
  2539. * updated.
  2540. *
  2541. * \param x the base.
  2542. * \param y the exponent.
  2543. * \returns `x` raised to the power `y`.
  2544. *
  2545. * \threadsafety It is safe to call this function from any thread.
  2546. *
  2547. * \since This function is available since SDL 3.0.0.
  2548. *
  2549. * \sa SDL_pow
  2550. * \sa SDL_expf
  2551. * \sa SDL_logf
  2552. */
  2553. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  2554. /**
  2555. * Round `x` to the nearest integer.
  2556. *
  2557. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2558. * rounded away from zero.
  2559. *
  2560. * Domain: `-INF <= x <= INF`
  2561. *
  2562. * Range: `-INF <= y <= INF`, y integer
  2563. *
  2564. * This function operates on double-precision floating point values, use
  2565. * SDL_roundf for single-precision floats. To get the result as an integer
  2566. * type, use SDL_lround.
  2567. *
  2568. * \param x floating point value.
  2569. * \returns the nearest integer to `x`.
  2570. *
  2571. * \threadsafety It is safe to call this function from any thread.
  2572. *
  2573. * \since This function is available since SDL 3.0.0.
  2574. *
  2575. * \sa SDL_roundf
  2576. * \sa SDL_lround
  2577. * \sa SDL_floor
  2578. * \sa SDL_ceil
  2579. * \sa SDL_trunc
  2580. */
  2581. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  2582. /**
  2583. * Round `x` to the nearest integer.
  2584. *
  2585. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2586. * rounded away from zero.
  2587. *
  2588. * Domain: `-INF <= x <= INF`
  2589. *
  2590. * Range: `-INF <= y <= INF`, y integer
  2591. *
  2592. * This function operates on double-precision floating point values, use
  2593. * SDL_roundf for single-precision floats. To get the result as an integer
  2594. * type, use SDL_lroundf.
  2595. *
  2596. * \param x floating point value.
  2597. * \returns the nearest integer to `x`.
  2598. *
  2599. * \threadsafety It is safe to call this function from any thread.
  2600. *
  2601. * \since This function is available since SDL 3.0.0.
  2602. *
  2603. * \sa SDL_round
  2604. * \sa SDL_lroundf
  2605. * \sa SDL_floorf
  2606. * \sa SDL_ceilf
  2607. * \sa SDL_truncf
  2608. */
  2609. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  2610. /**
  2611. * Round `x` to the nearest integer representable as a long
  2612. *
  2613. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2614. * rounded away from zero.
  2615. *
  2616. * Domain: `-INF <= x <= INF`
  2617. *
  2618. * Range: `MIN_LONG <= y <= MAX_LONG`
  2619. *
  2620. * This function operates on double-precision floating point values, use
  2621. * SDL_lround for single-precision floats. To get the result as a
  2622. * floating-point type, use SDL_round.
  2623. *
  2624. * \param x floating point value.
  2625. * \returns the nearest integer to `x`.
  2626. *
  2627. * \threadsafety It is safe to call this function from any thread.
  2628. *
  2629. * \since This function is available since SDL 3.0.0.
  2630. *
  2631. * \sa SDL_lroundf
  2632. * \sa SDL_round
  2633. * \sa SDL_floor
  2634. * \sa SDL_ceil
  2635. * \sa SDL_trunc
  2636. */
  2637. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  2638. /**
  2639. * Round `x` to the nearest integer representable as a long
  2640. *
  2641. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2642. * rounded away from zero.
  2643. *
  2644. * Domain: `-INF <= x <= INF`
  2645. *
  2646. * Range: `MIN_LONG <= y <= MAX_LONG`
  2647. *
  2648. * This function operates on single-precision floating point values, use
  2649. * SDL_lroundf for double-precision floats. To get the result as a
  2650. * floating-point type, use SDL_roundf,
  2651. *
  2652. * \param x floating point value.
  2653. * \returns the nearest integer to `x`.
  2654. *
  2655. * \threadsafety It is safe to call this function from any thread.
  2656. *
  2657. * \since This function is available since SDL 3.0.0.
  2658. *
  2659. * \sa SDL_lround
  2660. * \sa SDL_roundf
  2661. * \sa SDL_floorf
  2662. * \sa SDL_ceilf
  2663. * \sa SDL_truncf
  2664. */
  2665. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  2666. /**
  2667. * Scale `x` by an integer power of two.
  2668. *
  2669. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2670. *
  2671. * Domain: `-INF <= x <= INF`, `n` integer
  2672. *
  2673. * Range: `-INF <= y <= INF`
  2674. *
  2675. * This function operates on double-precision floating point values, use
  2676. * SDL_scalbnf for single-precision floats.
  2677. *
  2678. * \param x floating point value to be scaled.
  2679. * \param n integer exponent.
  2680. * \returns `x * 2^n`.
  2681. *
  2682. * \threadsafety It is safe to call this function from any thread.
  2683. *
  2684. * \since This function is available since SDL 3.0.0.
  2685. *
  2686. * \sa SDL_scalbnf
  2687. * \sa SDL_pow
  2688. */
  2689. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  2690. /**
  2691. * Scale `x` by an integer power of two.
  2692. *
  2693. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2694. *
  2695. * Domain: `-INF <= x <= INF`, `n` integer
  2696. *
  2697. * Range: `-INF <= y <= INF`
  2698. *
  2699. * This function operates on single-precision floating point values, use
  2700. * SDL_scalbn for double-precision floats.
  2701. *
  2702. * \param x floating point value to be scaled.
  2703. * \param n integer exponent.
  2704. * \returns `x * 2^n`.
  2705. *
  2706. * \threadsafety It is safe to call this function from any thread.
  2707. *
  2708. * \since This function is available since SDL 3.0.0.
  2709. *
  2710. * \sa SDL_scalbn
  2711. * \sa SDL_powf
  2712. */
  2713. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  2714. /**
  2715. * Compute the sine of `x`.
  2716. *
  2717. * Domain: `-INF <= x <= INF`
  2718. *
  2719. * Range: `-1 <= y <= 1`
  2720. *
  2721. * This function operates on double-precision floating point values, use
  2722. * SDL_sinf for single-precision floats.
  2723. *
  2724. * This function may use a different approximation across different versions,
  2725. * platforms and configurations. i.e, it can return a different value given
  2726. * the same input on different machines or operating systems, or if SDL is
  2727. * updated.
  2728. *
  2729. * \param x floating point value, in radians.
  2730. * \returns sine of `x`.
  2731. *
  2732. * \threadsafety It is safe to call this function from any thread.
  2733. *
  2734. * \since This function is available since SDL 3.0.0.
  2735. *
  2736. * \sa SDL_sinf
  2737. * \sa SDL_asin
  2738. * \sa SDL_cos
  2739. */
  2740. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  2741. /**
  2742. * Compute the sine of `x`.
  2743. *
  2744. * Domain: `-INF <= x <= INF`
  2745. *
  2746. * Range: `-1 <= y <= 1`
  2747. *
  2748. * This function operates on single-precision floating point values, use
  2749. * SDL_sinf for double-precision floats.
  2750. *
  2751. * This function may use a different approximation across different versions,
  2752. * platforms and configurations. i.e, it can return a different value given
  2753. * the same input on different machines or operating systems, or if SDL is
  2754. * updated.
  2755. *
  2756. * \param x floating point value, in radians.
  2757. * \returns sine of `x`.
  2758. *
  2759. * \threadsafety It is safe to call this function from any thread.
  2760. *
  2761. * \since This function is available since SDL 3.0.0.
  2762. *
  2763. * \sa SDL_sin
  2764. * \sa SDL_asinf
  2765. * \sa SDL_cosf
  2766. */
  2767. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  2768. /**
  2769. * Compute the square root of `x`.
  2770. *
  2771. * Domain: `0 <= x <= INF`
  2772. *
  2773. * Range: `0 <= y <= INF`
  2774. *
  2775. * This function operates on double-precision floating point values, use
  2776. * SDL_sqrtf for single-precision floats.
  2777. *
  2778. * This function may use a different approximation across different versions,
  2779. * platforms and configurations. i.e, it can return a different value given
  2780. * the same input on different machines or operating systems, or if SDL is
  2781. * updated.
  2782. *
  2783. * \param x floating point value. Must be greater than or equal to 0.
  2784. * \returns square root of `x`.
  2785. *
  2786. * \threadsafety It is safe to call this function from any thread.
  2787. *
  2788. * \since This function is available since SDL 3.0.0.
  2789. *
  2790. * \sa SDL_sqrtf
  2791. */
  2792. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  2793. /**
  2794. * Compute the square root of `x`.
  2795. *
  2796. * Domain: `0 <= x <= INF`
  2797. *
  2798. * Range: `0 <= y <= INF`
  2799. *
  2800. * This function operates on single-precision floating point values, use
  2801. * SDL_sqrt for double-precision floats.
  2802. *
  2803. * This function may use a different approximation across different versions,
  2804. * platforms and configurations. i.e, it can return a different value given
  2805. * the same input on different machines or operating systems, or if SDL is
  2806. * updated.
  2807. *
  2808. * \param x floating point value. Must be greater than or equal to 0.
  2809. * \returns square root of `x`.
  2810. *
  2811. * \threadsafety It is safe to call this function from any thread.
  2812. *
  2813. * \since This function is available since SDL 3.0.0.
  2814. *
  2815. * \sa SDL_sqrt
  2816. */
  2817. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  2818. /**
  2819. * Compute the tangent of `x`.
  2820. *
  2821. * Domain: `-INF <= x <= INF`
  2822. *
  2823. * Range: `-INF <= y <= INF`
  2824. *
  2825. * This function operates on double-precision floating point values, use
  2826. * SDL_tanf for single-precision floats.
  2827. *
  2828. * This function may use a different approximation across different versions,
  2829. * platforms and configurations. i.e, it can return a different value given
  2830. * the same input on different machines or operating systems, or if SDL is
  2831. * updated.
  2832. *
  2833. * \param x floating point value, in radians.
  2834. * \returns tangent of `x`.
  2835. *
  2836. * \threadsafety It is safe to call this function from any thread.
  2837. *
  2838. * \since This function is available since SDL 3.0.0.
  2839. *
  2840. * \sa SDL_tanf
  2841. * \sa SDL_sin
  2842. * \sa SDL_cos
  2843. * \sa SDL_atan
  2844. * \sa SDL_atan2
  2845. */
  2846. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  2847. /**
  2848. * Compute the tangent of `x`.
  2849. *
  2850. * Domain: `-INF <= x <= INF`
  2851. *
  2852. * Range: `-INF <= y <= INF`
  2853. *
  2854. * This function operates on single-precision floating point values, use
  2855. * SDL_tanf for double-precision floats.
  2856. *
  2857. * This function may use a different approximation across different versions,
  2858. * platforms and configurations. i.e, it can return a different value given
  2859. * the same input on different machines or operating systems, or if SDL is
  2860. * updated.
  2861. *
  2862. * \param x floating point value, in radians.
  2863. * \returns tangent of `x`.
  2864. *
  2865. * \threadsafety It is safe to call this function from any thread.
  2866. *
  2867. * \since This function is available since SDL 3.0.0.
  2868. *
  2869. * \sa SDL_tan
  2870. * \sa SDL_sinf
  2871. * \sa SDL_cosf
  2872. * \sa SDL_atanf
  2873. * \sa SDL_atan2f
  2874. */
  2875. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  2876. /* The SDL implementation of iconv() returns these error codes */
  2877. #define SDL_ICONV_ERROR (size_t)-1
  2878. #define SDL_ICONV_E2BIG (size_t)-2
  2879. #define SDL_ICONV_EILSEQ (size_t)-3
  2880. #define SDL_ICONV_EINVAL (size_t)-4
  2881. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  2882. /**
  2883. * This function allocates a context for the specified character set
  2884. * conversion.
  2885. *
  2886. * \param tocode The target character encoding, must not be NULL.
  2887. * \param fromcode The source character encoding, must not be NULL.
  2888. * \returns a handle that must be freed with SDL_iconv_close, or
  2889. * SDL_ICONV_ERROR on failure.
  2890. *
  2891. * \since This function is available since SDL 3.0.0.
  2892. *
  2893. * \sa SDL_iconv
  2894. * \sa SDL_iconv_close
  2895. * \sa SDL_iconv_string
  2896. */
  2897. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  2898. const char *fromcode);
  2899. /**
  2900. * This function frees a context used for character set conversion.
  2901. *
  2902. * \param cd The character set conversion handle.
  2903. * \returns 0 on success, or -1 on failure.
  2904. *
  2905. * \since This function is available since SDL 3.0.0.
  2906. *
  2907. * \sa SDL_iconv
  2908. * \sa SDL_iconv_open
  2909. * \sa SDL_iconv_string
  2910. */
  2911. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  2912. /**
  2913. * This function converts text between encodings, reading from and writing to
  2914. * a buffer.
  2915. *
  2916. * It returns the number of succesful conversions.
  2917. *
  2918. * \param cd The character set conversion context, created in
  2919. * SDL_iconv_open().
  2920. * \param inbuf Address of variable that points to the first character of the
  2921. * input sequence.
  2922. * \param inbytesleft The number of bytes in the input buffer.
  2923. * \param outbuf Address of variable that points to the output buffer.
  2924. * \param outbytesleft The number of bytes in the output buffer.
  2925. * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
  2926. * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
  2927. * is returned when an invalid input sequence is encountered, or
  2928. * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  2929. * encountered.
  2930. *
  2931. * On exit:
  2932. *
  2933. * - inbuf will point to the beginning of the next multibyte
  2934. * sequence. On error, this is the location of the problematic
  2935. * input sequence. On success, this is the end of the input
  2936. * sequence. - inbytesleft will be set to the number of bytes left
  2937. * to convert, which will be 0 on success. - outbuf will point to
  2938. * the location where to store the next output byte. - outbytesleft
  2939. * will be set to the number of bytes left in the output buffer.
  2940. *
  2941. * \since This function is available since SDL 3.0.0.
  2942. *
  2943. * \sa SDL_iconv_open
  2944. * \sa SDL_iconv_close
  2945. * \sa SDL_iconv_string
  2946. */
  2947. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  2948. size_t *inbytesleft, char **outbuf,
  2949. size_t *outbytesleft);
  2950. /**
  2951. * Helper function to convert a string's encoding in one call.
  2952. *
  2953. * This function converts a buffer or string between encodings in one pass.
  2954. *
  2955. * The string does not need to be NULL-terminated; this function operates on
  2956. * the number of bytes specified in `inbytesleft` whether there is a NULL
  2957. * character anywhere in the buffer.
  2958. *
  2959. * The returned string is owned by the caller, and should be passed to
  2960. * SDL_free when no longer needed.
  2961. *
  2962. * \param tocode the character encoding of the output string. Examples are
  2963. * "UTF-8", "UCS-4", etc.
  2964. * \param fromcode the character encoding of data in `inbuf`.
  2965. * \param inbuf the string to convert to a different encoding.
  2966. * \param inbytesleft the size of the input string _in bytes_.
  2967. * \returns a new string, converted to the new encoding, or NULL on error.
  2968. *
  2969. * \since This function is available since SDL 3.0.0.
  2970. *
  2971. * \sa SDL_iconv_open
  2972. * \sa SDL_iconv_close
  2973. * \sa SDL_iconv
  2974. */
  2975. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  2976. const char *fromcode,
  2977. const char *inbuf,
  2978. size_t inbytesleft);
  2979. /* Some helper macros for common cases... */
  2980. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  2981. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  2982. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  2983. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  2984. /* force builds using Clang's static analysis tools to use literal C runtime
  2985. here, since there are possibly tests that are ineffective otherwise. */
  2986. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  2987. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  2988. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  2989. size_t strlcpy(char *dst, const char *src, size_t size);
  2990. #endif
  2991. /* The analyzer knows about strlcat even when the system doesn't provide it */
  2992. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  2993. size_t strlcat(char *dst, const char *src, size_t size);
  2994. #endif
  2995. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  2996. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  2997. #endif
  2998. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  2999. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  3000. #endif
  3001. /* Starting LLVM 16, the analyser errors out if these functions do not have
  3002. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  3003. #include <stdio.h>
  3004. #include <stdlib.h>
  3005. #include <strings.h>
  3006. #define SDL_malloc malloc
  3007. #define SDL_calloc calloc
  3008. #define SDL_realloc realloc
  3009. #define SDL_free free
  3010. #ifndef SDL_memcpy
  3011. #define SDL_memcpy memcpy
  3012. #endif
  3013. #ifndef SDL_memmove
  3014. #define SDL_memmove memmove
  3015. #endif
  3016. #ifndef SDL_memset
  3017. #define SDL_memset memset
  3018. #endif
  3019. #define SDL_memcmp memcmp
  3020. #define SDL_strlcpy strlcpy
  3021. #define SDL_strlcat strlcat
  3022. #define SDL_strlen strlen
  3023. #define SDL_wcslen wcslen
  3024. #define SDL_wcslcpy wcslcpy
  3025. #define SDL_wcslcat wcslcat
  3026. #define SDL_strdup strdup
  3027. #define SDL_wcsdup wcsdup
  3028. #define SDL_strchr strchr
  3029. #define SDL_strrchr strrchr
  3030. #define SDL_strstr strstr
  3031. #define SDL_wcsstr wcsstr
  3032. #define SDL_strtok_r strtok_r
  3033. #define SDL_strcmp strcmp
  3034. #define SDL_wcscmp wcscmp
  3035. #define SDL_strncmp strncmp
  3036. #define SDL_wcsncmp wcsncmp
  3037. #define SDL_strcasecmp strcasecmp
  3038. #define SDL_strncasecmp strncasecmp
  3039. #define SDL_strpbrk strpbrk
  3040. #define SDL_sscanf sscanf
  3041. #define SDL_vsscanf vsscanf
  3042. #define SDL_snprintf snprintf
  3043. #define SDL_vsnprintf vsnprintf
  3044. #endif
  3045. /**
  3046. * Multiply two integers, checking for overflow.
  3047. *
  3048. * If `a * b` would overflow, return SDL_FALSE.
  3049. *
  3050. * Otherwise store `a * b` via ret and return SDL_TRUE.
  3051. *
  3052. * \param a the multiplicand.
  3053. * \param b the multiplier.
  3054. * \param ret on non-overflow output, stores the multiplication result. May
  3055. * not be NULL.
  3056. * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without
  3057. * overflow.
  3058. *
  3059. * \threadsafety It is safe to call this function from any thread.
  3060. *
  3061. * \since This function is available since SDL 3.0.0.
  3062. */
  3063. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  3064. {
  3065. if (a != 0 && b > SDL_SIZE_MAX / a) {
  3066. return SDL_FALSE;
  3067. }
  3068. *ret = a * b;
  3069. return SDL_TRUE;
  3070. }
  3071. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3072. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  3073. /* This needs to be wrapped in an inline rather than being a direct #define,
  3074. * because __builtin_mul_overflow() is type-generic, but we want to be
  3075. * consistent about interpreting a and b as size_t. */
  3076. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3077. {
  3078. return (__builtin_mul_overflow(a, b, ret) == 0);
  3079. }
  3080. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  3081. #endif
  3082. #endif
  3083. /**
  3084. * Add two integers, checking for overflow.
  3085. *
  3086. * If `a + b` would overflow, return -1.
  3087. *
  3088. * Otherwise store `a + b` via ret and return 0.
  3089. *
  3090. * \param a the first addend.
  3091. * \param b the second addend.
  3092. * \param ret on non-overflow output, stores the addition result. May not be
  3093. * NULL.
  3094. * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without
  3095. * overflow.
  3096. *
  3097. * \threadsafety It is safe to call this function from any thread.
  3098. *
  3099. * \since This function is available since SDL 3.0.0.
  3100. */
  3101. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  3102. {
  3103. if (b > SDL_SIZE_MAX - a) {
  3104. return SDL_FALSE;
  3105. }
  3106. *ret = a + b;
  3107. return SDL_TRUE;
  3108. }
  3109. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3110. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  3111. /* This needs to be wrapped in an inline rather than being a direct #define,
  3112. * the same as the call to __builtin_mul_overflow() above. */
  3113. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3114. {
  3115. return (__builtin_add_overflow(a, b, ret) == 0);
  3116. }
  3117. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  3118. #endif
  3119. #endif
  3120. /* This is a generic function pointer which should be cast to the type you expect */
  3121. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  3122. /**
  3123. * A generic function pointer.
  3124. *
  3125. * In theory, generic function pointers should use this, instead of `void *`,
  3126. * since some platforms could treat code addresses differently than data
  3127. * addresses. Although in current times no popular platforms make this
  3128. * distinction, it is more correct and portable to use the correct type for a
  3129. * generic pointer.
  3130. *
  3131. * If for some reason you need to force this typedef to be an actual `void *`,
  3132. * perhaps to work around a compiler or existing code, you can define
  3133. * `SDL_FUNCTION_IS_VOID_POINTER` before including any SDL headers.
  3134. *
  3135. * \since This datatype is available since SDL 3.0.0.
  3136. */
  3137. typedef void (*SDL_FunctionPointer)(void);
  3138. #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
  3139. typedef void *SDL_FunctionPointer;
  3140. #else
  3141. typedef void (*SDL_FunctionPointer)(void);
  3142. #endif
  3143. /* Ends C function definitions when using C++ */
  3144. #ifdef __cplusplus
  3145. }
  3146. #endif
  3147. #include <SDL3/SDL_close_code.h>
  3148. #endif /* SDL_stdinc_h_ */