SDL_stdinc.h 142 KB

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