SDL_stdinc.h 140 KB

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