SDL_stdinc.h 142 KB

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