SDL_stdinc.h 126 KB

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