SDL_stdinc.h 100 KB

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