SDL_stdinc.h 101 KB

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