SDL_stdinc.h 134 KB

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