SDL_stdinc.h 103 KB

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