2
0

SDL_stdinc.h 126 KB

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