SDL_stdinc.h 134 KB

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