SDL_stdinc.h 126 KB

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