SDL_stdinc.h 134 KB

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