SDL_stdinc.h 119 KB

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