SDL_stdinc.h 142 KB

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