SDL_stdinc.h 145 KB

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