SDL_stdinc.h 134 KB

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