SDL_stdinc.h 113 KB

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