SDL_stdinc.h 125 KB

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