SDL_stdinc.h 134 KB

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