SDL_stdinc.h 142 KB

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