SDL_stdinc.h 100 KB

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