SDL_stdinc.h 101 KB

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