SDL_stdinc.h 134 KB

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