SDL_stdinc.h 103 KB

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