SDL_stdinc.h 101 KB

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