SDL_stdinc.h 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197
  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. * Searches a string for the first occurence of any character contained in a
  1199. * breakset, and returns a pointer from the string to that character.
  1200. *
  1201. * \param str The null-terminated string to be searched.
  1202. * \param breakset A null-terminated string containing the list of characters
  1203. * to look for.
  1204. * \returns A pointer to the location, in str, of the first occurence of a
  1205. * character present in the breakset, or NULL if none is found.
  1206. *
  1207. * \threadsafety It is safe to call this function from any thread.
  1208. *
  1209. * \since This function is available since SDL 3.0.0.
  1210. */
  1211. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char * SDL_RESTRICT str, const char * SDL_RESTRICT breakset);
  1212. /**
  1213. * The Unicode REPLACEMENT CHARACTER codepoint.
  1214. *
  1215. * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
  1216. * with encoding errors.
  1217. *
  1218. * This tends to render as something like a question mark in most places.
  1219. *
  1220. * \since This macro is available since SDL 3.0.0.
  1221. *
  1222. * \sa SDL_StepUTF8
  1223. */
  1224. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  1225. /**
  1226. * Decode a UTF-8 string, one Unicode codepoint at a time.
  1227. *
  1228. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  1229. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  1230. *
  1231. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  1232. * be adjusted, as well, subtracting the number of bytes consumed.
  1233. *
  1234. * `pslen` is allowed to be NULL, in which case the string _must_ be
  1235. * NULL-terminated, as the function will blindly read until it sees the NULL
  1236. * char.
  1237. *
  1238. * if `*pslen` is zero, it assumes the end of string is reached and returns a
  1239. * zero codepoint regardless of the contents of the string buffer.
  1240. *
  1241. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  1242. * zero, it will not advance `*pstr` or `*pslen` at all.
  1243. *
  1244. * Generally this function is called in a loop until it returns zero,
  1245. * adjusting its parameters each iteration.
  1246. *
  1247. * If an invalid UTF-8 sequence is encountered, this function returns
  1248. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  1249. * (which is to say, a multibyte sequence might produce several
  1250. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  1251. * UTF-8 sequence).
  1252. *
  1253. * Several things can generate invalid UTF-8 sequences, including overlong
  1254. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  1255. * refer to
  1256. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  1257. * for details.
  1258. *
  1259. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  1260. * \param pslen a pointer to the number of bytes in the string, to be read and
  1261. * adjusted. NULL is allowed.
  1262. * \returns the first Unicode codepoint in the string.
  1263. *
  1264. * \threadsafety It is safe to call this function from any thread.
  1265. *
  1266. * \since This function is available since SDL 3.0.0.
  1267. */
  1268. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  1269. /**
  1270. * Convert a single Unicode codepoint to UTF-8.
  1271. *
  1272. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  1273. * function may generate between 1 and 4 bytes of output.
  1274. *
  1275. * This function returns the first byte _after_ the newly-written UTF-8
  1276. * sequence, which is useful for encoding multiple codepoints in a loop, or
  1277. * knowing where to write a NULL-terminator character to end the string (in
  1278. * either case, plan to have a buffer of _more_ than 4 bytes!).
  1279. *
  1280. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  1281. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  1282. * codepoint instead, and not set an error.
  1283. *
  1284. * If `dst` is NULL, this returns NULL immediately without writing to the
  1285. * pointer and without setting an error.
  1286. *
  1287. * \param codepoint a Unicode codepoint to convert to UTF-8.
  1288. * \param dst the location to write the encoded UTF-8. Must point to at least
  1289. * 4 bytes!
  1290. * \returns the first byte past the newly-written UTF-8 sequence.
  1291. *
  1292. * \threadsafety It is safe to call this function from any thread.
  1293. *
  1294. * \since This function is available since SDL 3.0.0.
  1295. */
  1296. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  1297. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  1298. 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);
  1299. 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);
  1300. 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);
  1301. 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);
  1302. 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);
  1303. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  1304. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  1305. /**
  1306. * Seeds the pseudo-random number generator.
  1307. *
  1308. * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
  1309. * of 'random' numbers.
  1310. *
  1311. * \param seed the value to use as a random number seed, or 0 to use
  1312. * SDL_GetPerformanceCounter().
  1313. *
  1314. * \threadsafety This should be called on the same thread that calls
  1315. * SDL_rand*()
  1316. *
  1317. * \since This function is available since SDL 3.0.0.
  1318. *
  1319. * \sa SDL_rand
  1320. * \sa SDL_rand_bits
  1321. * \sa SDL_randf
  1322. */
  1323. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  1324. /**
  1325. * Generate a pseudo-random number less than n for positive n
  1326. *
  1327. * The method used is faster and of better quality than `rand() % n`. Odds are
  1328. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  1329. * much worse as n gets bigger.
  1330. *
  1331. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  1332. * 1..6
  1333. *
  1334. * If you want to generate a pseudo-random number in the full range of Sint32,
  1335. * you should use: (Sint32)SDL_rand_bits()
  1336. *
  1337. * If you want reproducible output, be sure to initialize with SDL_srand()
  1338. * first.
  1339. *
  1340. * There are no guarantees as to the quality of the random sequence produced,
  1341. * and this should not be used for security (cryptography, passwords) or where
  1342. * money is on the line (loot-boxes, casinos). There are many random number
  1343. * libraries available with different characteristics and you should pick one
  1344. * of those to meet any serious needs.
  1345. *
  1346. * \param n the number of possible outcomes. n must be positive.
  1347. * \returns a random value in the range of [0 .. n-1].
  1348. *
  1349. * \threadsafety All calls should be made from a single thread
  1350. *
  1351. * \since This function is available since SDL 3.0.0.
  1352. *
  1353. * \sa SDL_srand
  1354. * \sa SDL_randf
  1355. */
  1356. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  1357. /**
  1358. * Generate a uniform pseudo-random floating point number less than 1.0
  1359. *
  1360. * If you want reproducible output, be sure to initialize with SDL_srand()
  1361. * first.
  1362. *
  1363. * There are no guarantees as to the quality of the random sequence produced,
  1364. * and this should not be used for security (cryptography, passwords) or where
  1365. * money is on the line (loot-boxes, casinos). There are many random number
  1366. * libraries available with different characteristics and you should pick one
  1367. * of those to meet any serious needs.
  1368. *
  1369. * \returns a random value in the range of [0.0, 1.0).
  1370. *
  1371. * \threadsafety All calls should be made from a single thread
  1372. *
  1373. * \since This function is available since SDL 3.0.0.
  1374. *
  1375. * \sa SDL_srand
  1376. * \sa SDL_rand
  1377. */
  1378. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  1379. /**
  1380. * Generate 32 pseudo-random bits.
  1381. *
  1382. * You likely want to use SDL_rand() to get a psuedo-random number instead.
  1383. *
  1384. * There are no guarantees as to the quality of the random sequence produced,
  1385. * and this should not be used for security (cryptography, passwords) or where
  1386. * money is on the line (loot-boxes, casinos). There are many random number
  1387. * libraries available with different characteristics and you should pick one
  1388. * of those to meet any serious needs.
  1389. *
  1390. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  1391. *
  1392. * \threadsafety All calls should be made from a single thread
  1393. *
  1394. * \since This function is available since SDL 3.0.0.
  1395. *
  1396. * \sa SDL_rand
  1397. * \sa SDL_randf
  1398. * \sa SDL_srand
  1399. */
  1400. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  1401. /**
  1402. * Generate a pseudo-random number less than n for positive n
  1403. *
  1404. * The method used is faster and of better quality than `rand() % n`. Odds are
  1405. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  1406. * much worse as n gets bigger.
  1407. *
  1408. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  1409. * 0..5 to 1..6
  1410. *
  1411. * If you want to generate a pseudo-random number in the full range of Sint32,
  1412. * you should use: (Sint32)SDL_rand_bits_r(state)
  1413. *
  1414. * There are no guarantees as to the quality of the random sequence produced,
  1415. * and this should not be used for security (cryptography, passwords) or where
  1416. * money is on the line (loot-boxes, casinos). There are many random number
  1417. * libraries available with different characteristics and you should pick one
  1418. * of those to meet any serious needs.
  1419. *
  1420. * \param state a pointer to the current random number state, this may not be
  1421. * NULL.
  1422. * \param n the number of possible outcomes. n must be positive.
  1423. * \returns a random value in the range of [0 .. n-1].
  1424. *
  1425. * \threadsafety This function is thread-safe, as long as the state pointer
  1426. * isn't shared between threads.
  1427. *
  1428. * \since This function is available since SDL 3.0.0.
  1429. *
  1430. * \sa SDL_rand
  1431. * \sa SDL_rand_bits_r
  1432. * \sa SDL_randf_r
  1433. */
  1434. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  1435. /**
  1436. * Generate a uniform pseudo-random floating point number less than 1.0
  1437. *
  1438. * If you want reproducible output, be sure to initialize with SDL_srand()
  1439. * first.
  1440. *
  1441. * There are no guarantees as to the quality of the random sequence produced,
  1442. * and this should not be used for security (cryptography, passwords) or where
  1443. * money is on the line (loot-boxes, casinos). There are many random number
  1444. * libraries available with different characteristics and you should pick one
  1445. * of those to meet any serious needs.
  1446. *
  1447. * \param state a pointer to the current random number state, this may not be
  1448. * NULL.
  1449. * \returns a random value in the range of [0.0, 1.0).
  1450. *
  1451. * \threadsafety This function is thread-safe, as long as the state pointer
  1452. * isn't shared between threads.
  1453. *
  1454. * \since This function is available since SDL 3.0.0.
  1455. *
  1456. * \sa SDL_rand_bits_r
  1457. * \sa SDL_rand_r
  1458. * \sa SDL_randf
  1459. */
  1460. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  1461. /**
  1462. * Generate 32 pseudo-random bits.
  1463. *
  1464. * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
  1465. *
  1466. * There are no guarantees as to the quality of the random sequence produced,
  1467. * and this should not be used for security (cryptography, passwords) or where
  1468. * money is on the line (loot-boxes, casinos). There are many random number
  1469. * libraries available with different characteristics and you should pick one
  1470. * of those to meet any serious needs.
  1471. *
  1472. * \param state a pointer to the current random number state, this may not be
  1473. * NULL.
  1474. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  1475. *
  1476. * \threadsafety This function is thread-safe, as long as the state pointer
  1477. * isn't shared between threads.
  1478. *
  1479. * \since This function is available since SDL 3.0.0.
  1480. *
  1481. * \sa SDL_rand_r
  1482. * \sa SDL_randf_r
  1483. */
  1484. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  1485. #ifndef SDL_PI_D
  1486. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  1487. #endif
  1488. #ifndef SDL_PI_F
  1489. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  1490. #endif
  1491. /**
  1492. * Compute the arc cosine of `x`.
  1493. *
  1494. * The definition of `y = acos(x)` is `x = cos(y)`.
  1495. *
  1496. * Domain: `-1 <= x <= 1`
  1497. *
  1498. * Range: `0 <= y <= Pi`
  1499. *
  1500. * This function operates on double-precision floating point values, use
  1501. * SDL_acosf for single-precision floats.
  1502. *
  1503. * This function may use a different approximation across different versions,
  1504. * platforms and configurations. i.e, it can return a different value given
  1505. * the same input on different machines or operating systems, or if SDL is
  1506. * updated.
  1507. *
  1508. * \param x floating point value.
  1509. * \returns arc cosine of `x`, in radians.
  1510. *
  1511. * \threadsafety It is safe to call this function from any thread.
  1512. *
  1513. * \since This function is available since SDL 3.0.0.
  1514. *
  1515. * \sa SDL_acosf
  1516. * \sa SDL_asin
  1517. * \sa SDL_cos
  1518. */
  1519. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  1520. /**
  1521. * Compute the arc cosine of `x`.
  1522. *
  1523. * The definition of `y = acos(x)` is `x = cos(y)`.
  1524. *
  1525. * Domain: `-1 <= x <= 1`
  1526. *
  1527. * Range: `0 <= y <= Pi`
  1528. *
  1529. * This function operates on single-precision floating point values, use
  1530. * SDL_acos for double-precision floats.
  1531. *
  1532. * This function may use a different approximation across different versions,
  1533. * platforms and configurations. i.e, it can return a different value given
  1534. * the same input on different machines or operating systems, or if SDL is
  1535. * updated.
  1536. *
  1537. * \param x floating point value.
  1538. * \returns arc cosine of `x`, in radians.
  1539. *
  1540. * \threadsafety It is safe to call this function from any thread.
  1541. *
  1542. * \since This function is available since SDL 3.0.0.
  1543. *
  1544. * \sa SDL_acos
  1545. * \sa SDL_asinf
  1546. * \sa SDL_cosf
  1547. */
  1548. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  1549. /**
  1550. * Compute the arc sine of `x`.
  1551. *
  1552. * The definition of `y = asin(x)` is `x = sin(y)`.
  1553. *
  1554. * Domain: `-1 <= x <= 1`
  1555. *
  1556. * Range: `-Pi/2 <= y <= Pi/2`
  1557. *
  1558. * This function operates on double-precision floating point values, use
  1559. * SDL_asinf for single-precision floats.
  1560. *
  1561. * This function may use a different approximation across different versions,
  1562. * platforms and configurations. i.e, it can return a different value given
  1563. * the same input on different machines or operating systems, or if SDL is
  1564. * updated.
  1565. *
  1566. * \param x floating point value.
  1567. * \returns arc sine of `x`, in radians.
  1568. *
  1569. * \threadsafety It is safe to call this function from any thread.
  1570. *
  1571. * \since This function is available since SDL 3.0.0.
  1572. *
  1573. * \sa SDL_asinf
  1574. * \sa SDL_acos
  1575. * \sa SDL_sin
  1576. */
  1577. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  1578. /**
  1579. * Compute the arc sine of `x`.
  1580. *
  1581. * The definition of `y = asin(x)` is `x = sin(y)`.
  1582. *
  1583. * Domain: `-1 <= x <= 1`
  1584. *
  1585. * Range: `-Pi/2 <= y <= Pi/2`
  1586. *
  1587. * This function operates on single-precision floating point values, use
  1588. * SDL_asin for double-precision floats.
  1589. *
  1590. * This function may use a different approximation across different versions,
  1591. * platforms and configurations. i.e, it can return a different value given
  1592. * the same input on different machines or operating systems, or if SDL is
  1593. * updated.
  1594. *
  1595. * \param x floating point value.
  1596. * \returns arc sine of `x`, in radians.
  1597. *
  1598. * \threadsafety It is safe to call this function from any thread.
  1599. *
  1600. * \since This function is available since SDL 3.0.0.
  1601. *
  1602. * \sa SDL_asin
  1603. * \sa SDL_acosf
  1604. * \sa SDL_sinf
  1605. */
  1606. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  1607. /**
  1608. * Compute the arc tangent of `x`.
  1609. *
  1610. * The definition of `y = atan(x)` is `x = tan(y)`.
  1611. *
  1612. * Domain: `-INF <= x <= INF`
  1613. *
  1614. * Range: `-Pi/2 <= y <= Pi/2`
  1615. *
  1616. * This function operates on double-precision floating point values, use
  1617. * SDL_atanf for single-precision floats.
  1618. *
  1619. * To calculate the arc tangent of y / x, use SDL_atan2.
  1620. *
  1621. * This function may use a different approximation across different versions,
  1622. * platforms and configurations. i.e, it can return a different value given
  1623. * the same input on different machines or operating systems, or if SDL is
  1624. * updated.
  1625. *
  1626. * \param x floating point value.
  1627. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1628. *
  1629. * \threadsafety It is safe to call this function from any thread.
  1630. *
  1631. * \since This function is available since SDL 3.0.0.
  1632. *
  1633. * \sa SDL_atanf
  1634. * \sa SDL_atan2
  1635. * \sa SDL_tan
  1636. */
  1637. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  1638. /**
  1639. * Compute the arc tangent of `x`.
  1640. *
  1641. * The definition of `y = atan(x)` is `x = tan(y)`.
  1642. *
  1643. * Domain: `-INF <= x <= INF`
  1644. *
  1645. * Range: `-Pi/2 <= y <= Pi/2`
  1646. *
  1647. * This function operates on single-precision floating point values, use
  1648. * SDL_atan for dboule-precision floats.
  1649. *
  1650. * To calculate the arc tangent of y / x, use SDL_atan2f.
  1651. *
  1652. * This function may use a different approximation across different versions,
  1653. * platforms and configurations. i.e, it can return a different value given
  1654. * the same input on different machines or operating systems, or if SDL is
  1655. * updated.
  1656. *
  1657. * \param x floating point value.
  1658. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1659. *
  1660. * \threadsafety It is safe to call this function from any thread.
  1661. *
  1662. * \since This function is available since SDL 3.0.0.
  1663. *
  1664. * \sa SDL_atan
  1665. * \sa SDL_atan2f
  1666. * \sa SDL_tanf
  1667. */
  1668. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  1669. /**
  1670. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1671. * the result's quadrant.
  1672. *
  1673. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1674. * of z is determined based on the signs of x and y.
  1675. *
  1676. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1677. *
  1678. * Range: `-Pi/2 <= y <= Pi/2`
  1679. *
  1680. * This function operates on double-precision floating point values, use
  1681. * SDL_atan2f for single-precision floats.
  1682. *
  1683. * To calculate the arc tangent of a single value, use SDL_atan.
  1684. *
  1685. * This function may use a different approximation across different versions,
  1686. * platforms and configurations. i.e, it can return a different value given
  1687. * the same input on different machines or operating systems, or if SDL is
  1688. * updated.
  1689. *
  1690. * \param y floating point value of the numerator (y coordinate).
  1691. * \param x floating point value of the denominator (x coordinate).
  1692. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1693. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1694. *
  1695. * \threadsafety It is safe to call this function from any thread.
  1696. *
  1697. * \since This function is available since SDL 3.0.0.
  1698. *
  1699. * \sa SDL_atan2f
  1700. * \sa SDL_atan
  1701. * \sa SDL_tan
  1702. */
  1703. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  1704. /**
  1705. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1706. * the result's quadrant.
  1707. *
  1708. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1709. * of z is determined based on the signs of x and y.
  1710. *
  1711. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1712. *
  1713. * Range: `-Pi/2 <= y <= Pi/2`
  1714. *
  1715. * This function operates on single-precision floating point values, use
  1716. * SDL_atan2 for double-precision floats.
  1717. *
  1718. * To calculate the arc tangent of a single value, use SDL_atanf.
  1719. *
  1720. * This function may use a different approximation across different versions,
  1721. * platforms and configurations. i.e, it can return a different value given
  1722. * the same input on different machines or operating systems, or if SDL is
  1723. * updated.
  1724. *
  1725. * \param y floating point value of the numerator (y coordinate).
  1726. * \param x floating point value of the denominator (x coordinate).
  1727. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1728. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1729. *
  1730. * \threadsafety It is safe to call this function from any thread.
  1731. *
  1732. * \since This function is available since SDL 3.0.0.
  1733. *
  1734. * \sa SDL_atan2f
  1735. * \sa SDL_atan
  1736. * \sa SDL_tan
  1737. */
  1738. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  1739. /**
  1740. * Compute the ceiling of `x`.
  1741. *
  1742. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1743. * rounded up to the nearest integer.
  1744. *
  1745. * Domain: `-INF <= x <= INF`
  1746. *
  1747. * Range: `-INF <= y <= INF`, y integer
  1748. *
  1749. * This function operates on double-precision floating point values, use
  1750. * SDL_ceilf for single-precision floats.
  1751. *
  1752. * \param x floating point value.
  1753. * \returns the ceiling of `x`.
  1754. *
  1755. * \threadsafety It is safe to call this function from any thread.
  1756. *
  1757. * \since This function is available since SDL 3.0.0.
  1758. *
  1759. * \sa SDL_ceilf
  1760. * \sa SDL_floor
  1761. * \sa SDL_trunc
  1762. * \sa SDL_round
  1763. * \sa SDL_lround
  1764. */
  1765. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  1766. /**
  1767. * Compute the ceiling of `x`.
  1768. *
  1769. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1770. * rounded up to the nearest integer.
  1771. *
  1772. * Domain: `-INF <= x <= INF`
  1773. *
  1774. * Range: `-INF <= y <= INF`, y integer
  1775. *
  1776. * This function operates on single-precision floating point values, use
  1777. * SDL_ceil for double-precision floats.
  1778. *
  1779. * \param x floating point value.
  1780. * \returns the ceiling of `x`.
  1781. *
  1782. * \threadsafety It is safe to call this function from any thread.
  1783. *
  1784. * \since This function is available since SDL 3.0.0.
  1785. *
  1786. * \sa SDL_ceil
  1787. * \sa SDL_floorf
  1788. * \sa SDL_truncf
  1789. * \sa SDL_roundf
  1790. * \sa SDL_lroundf
  1791. */
  1792. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  1793. /**
  1794. * Copy the sign of one floating-point value to another.
  1795. *
  1796. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1797. *
  1798. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1799. *
  1800. * Range: `-INF <= z <= INF`
  1801. *
  1802. * This function operates on double-precision floating point values, use
  1803. * SDL_copysignf for single-precision floats.
  1804. *
  1805. * \param x floating point value to use as the magnitude.
  1806. * \param y floating point value to use as the sign.
  1807. * \returns the floating point value with the sign of y and the magnitude of
  1808. * x.
  1809. *
  1810. * \threadsafety It is safe to call this function from any thread.
  1811. *
  1812. * \since This function is available since SDL 3.0.0.
  1813. *
  1814. * \sa SDL_copysignf
  1815. * \sa SDL_fabs
  1816. */
  1817. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  1818. /**
  1819. * Copy the sign of one floating-point value to another.
  1820. *
  1821. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1822. *
  1823. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1824. *
  1825. * Range: `-INF <= z <= INF`
  1826. *
  1827. * This function operates on single-precision floating point values, use
  1828. * SDL_copysign for double-precision floats.
  1829. *
  1830. * \param x floating point value to use as the magnitude.
  1831. * \param y floating point value to use as the sign.
  1832. * \returns the floating point value with the sign of y and the magnitude of
  1833. * x.
  1834. *
  1835. * \threadsafety It is safe to call this function from any thread.
  1836. *
  1837. * \since This function is available since SDL 3.0.0.
  1838. *
  1839. * \sa SDL_copysignf
  1840. * \sa SDL_fabsf
  1841. */
  1842. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  1843. /**
  1844. * Compute the cosine of `x`.
  1845. *
  1846. * Domain: `-INF <= x <= INF`
  1847. *
  1848. * Range: `-1 <= y <= 1`
  1849. *
  1850. * This function operates on double-precision floating point values, use
  1851. * SDL_cosf for single-precision floats.
  1852. *
  1853. * This function may use a different approximation across different versions,
  1854. * platforms and configurations. i.e, it can return a different value given
  1855. * the same input on different machines or operating systems, or if SDL is
  1856. * updated.
  1857. *
  1858. * \param x floating point value, in radians.
  1859. * \returns cosine of `x`.
  1860. *
  1861. * \threadsafety It is safe to call this function from any thread.
  1862. *
  1863. * \since This function is available since SDL 3.0.0.
  1864. *
  1865. * \sa SDL_cosf
  1866. * \sa SDL_acos
  1867. * \sa SDL_sin
  1868. */
  1869. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  1870. /**
  1871. * Compute the cosine of `x`.
  1872. *
  1873. * Domain: `-INF <= x <= INF`
  1874. *
  1875. * Range: `-1 <= y <= 1`
  1876. *
  1877. * This function operates on single-precision floating point values, use
  1878. * SDL_cos for double-precision floats.
  1879. *
  1880. * This function may use a different approximation across different versions,
  1881. * platforms and configurations. i.e, it can return a different value given
  1882. * the same input on different machines or operating systems, or if SDL is
  1883. * updated.
  1884. *
  1885. * \param x floating point value, in radians.
  1886. * \returns cosine of `x`.
  1887. *
  1888. * \threadsafety It is safe to call this function from any thread.
  1889. *
  1890. * \since This function is available since SDL 3.0.0.
  1891. *
  1892. * \sa SDL_cos
  1893. * \sa SDL_acosf
  1894. * \sa SDL_sinf
  1895. */
  1896. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  1897. /**
  1898. * Compute the exponential of `x`.
  1899. *
  1900. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1901. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  1902. *
  1903. * Domain: `-INF <= x <= INF`
  1904. *
  1905. * Range: `0 <= y <= INF`
  1906. *
  1907. * The output will overflow if `exp(x)` is too large to be represented.
  1908. *
  1909. * This function operates on double-precision floating point values, use
  1910. * SDL_expf for single-precision floats.
  1911. *
  1912. * This function may use a different approximation across different versions,
  1913. * platforms and configurations. i.e, it can return a different value given
  1914. * the same input on different machines or operating systems, or if SDL is
  1915. * updated.
  1916. *
  1917. * \param x floating point value.
  1918. * \returns value of `e^x`.
  1919. *
  1920. * \threadsafety It is safe to call this function from any thread.
  1921. *
  1922. * \since This function is available since SDL 3.0.0.
  1923. *
  1924. * \sa SDL_expf
  1925. * \sa SDL_log
  1926. */
  1927. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  1928. /**
  1929. * Compute the exponential of `x`.
  1930. *
  1931. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1932. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  1933. *
  1934. * Domain: `-INF <= x <= INF`
  1935. *
  1936. * Range: `0 <= y <= INF`
  1937. *
  1938. * The output will overflow if `exp(x)` is too large to be represented.
  1939. *
  1940. * This function operates on single-precision floating point values, use
  1941. * SDL_exp for double-precision floats.
  1942. *
  1943. * This function may use a different approximation across different versions,
  1944. * platforms and configurations. i.e, it can return a different value given
  1945. * the same input on different machines or operating systems, or if SDL is
  1946. * updated.
  1947. *
  1948. * \param x floating point value.
  1949. * \returns value of `e^x`.
  1950. *
  1951. * \threadsafety It is safe to call this function from any thread.
  1952. *
  1953. * \since This function is available since SDL 3.0.0.
  1954. *
  1955. * \sa SDL_exp
  1956. * \sa SDL_logf
  1957. */
  1958. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  1959. /**
  1960. * Compute the absolute value of `x`
  1961. *
  1962. * Domain: `-INF <= x <= INF`
  1963. *
  1964. * Range: `0 <= y <= INF`
  1965. *
  1966. * This function operates on double-precision floating point values, use
  1967. * SDL_copysignf for single-precision floats.
  1968. *
  1969. * \param x floating point value to use as the magnitude.
  1970. * \returns the absolute value of `x`.
  1971. *
  1972. * \threadsafety It is safe to call this function from any thread.
  1973. *
  1974. * \since This function is available since SDL 3.0.0.
  1975. *
  1976. * \sa SDL_fabsf
  1977. */
  1978. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  1979. /**
  1980. * Compute the absolute value of `x`
  1981. *
  1982. * Domain: `-INF <= x <= INF`
  1983. *
  1984. * Range: `0 <= y <= INF`
  1985. *
  1986. * This function operates on single-precision floating point values, use
  1987. * SDL_copysignf for double-precision floats.
  1988. *
  1989. * \param x floating point value to use as the magnitude.
  1990. * \returns the absolute value of `x`.
  1991. *
  1992. * \threadsafety It is safe to call this function from any thread.
  1993. *
  1994. * \since This function is available since SDL 3.0.0.
  1995. *
  1996. * \sa SDL_fabs
  1997. */
  1998. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  1999. /**
  2000. * Compute the floor of `x`.
  2001. *
  2002. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2003. * rounded down to the nearest integer.
  2004. *
  2005. * Domain: `-INF <= x <= INF`
  2006. *
  2007. * Range: `-INF <= y <= INF`, y integer
  2008. *
  2009. * This function operates on double-precision floating point values, use
  2010. * SDL_floorf for single-precision floats.
  2011. *
  2012. * \param x floating point value.
  2013. * \returns the floor of `x`.
  2014. *
  2015. * \threadsafety It is safe to call this function from any thread.
  2016. *
  2017. * \since This function is available since SDL 3.0.0.
  2018. *
  2019. * \sa SDL_floorf
  2020. * \sa SDL_ceil
  2021. * \sa SDL_trunc
  2022. * \sa SDL_round
  2023. * \sa SDL_lround
  2024. */
  2025. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  2026. /**
  2027. * Compute the floor of `x`.
  2028. *
  2029. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2030. * rounded down to the nearest integer.
  2031. *
  2032. * Domain: `-INF <= x <= INF`
  2033. *
  2034. * Range: `-INF <= y <= INF`, y integer
  2035. *
  2036. * This function operates on single-precision floating point values, use
  2037. * SDL_floorf for double-precision floats.
  2038. *
  2039. * \param x floating point value.
  2040. * \returns the floor of `x`.
  2041. *
  2042. * \threadsafety It is safe to call this function from any thread.
  2043. *
  2044. * \since This function is available since SDL 3.0.0.
  2045. *
  2046. * \sa SDL_floor
  2047. * \sa SDL_ceilf
  2048. * \sa SDL_truncf
  2049. * \sa SDL_roundf
  2050. * \sa SDL_lroundf
  2051. */
  2052. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  2053. /**
  2054. * Truncate `x` to an integer.
  2055. *
  2056. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2057. * the fractional part of `x`, leaving only the integer part.
  2058. *
  2059. * Domain: `-INF <= x <= INF`
  2060. *
  2061. * Range: `-INF <= y <= INF`, y integer
  2062. *
  2063. * This function operates on double-precision floating point values, use
  2064. * SDL_truncf for single-precision floats.
  2065. *
  2066. * \param x floating point value.
  2067. * \returns `x` truncated to an integer.
  2068. *
  2069. * \threadsafety It is safe to call this function from any thread.
  2070. *
  2071. * \since This function is available since SDL 3.0.0.
  2072. *
  2073. * \sa SDL_truncf
  2074. * \sa SDL_fmod
  2075. * \sa SDL_ceil
  2076. * \sa SDL_floor
  2077. * \sa SDL_round
  2078. * \sa SDL_lround
  2079. */
  2080. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  2081. /**
  2082. * Truncate `x` to an integer.
  2083. *
  2084. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2085. * the fractional part of `x`, leaving only the integer part.
  2086. *
  2087. * Domain: `-INF <= x <= INF`
  2088. *
  2089. * Range: `-INF <= y <= INF`, y integer
  2090. *
  2091. * This function operates on single-precision floating point values, use
  2092. * SDL_truncf for double-precision floats.
  2093. *
  2094. * \param x floating point value.
  2095. * \returns `x` truncated to an integer.
  2096. *
  2097. * \threadsafety It is safe to call this function from any thread.
  2098. *
  2099. * \since This function is available since SDL 3.0.0.
  2100. *
  2101. * \sa SDL_trunc
  2102. * \sa SDL_fmodf
  2103. * \sa SDL_ceilf
  2104. * \sa SDL_floorf
  2105. * \sa SDL_roundf
  2106. * \sa SDL_lroundf
  2107. */
  2108. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  2109. /**
  2110. * Return the floating-point remainder of `x / y`
  2111. *
  2112. * Divides `x` by `y`, and returns the remainder.
  2113. *
  2114. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  2115. *
  2116. * Range: `-y <= z <= y`
  2117. *
  2118. * This function operates on double-precision floating point values, use
  2119. * SDL_fmodf for single-precision floats.
  2120. *
  2121. * \param x the numerator.
  2122. * \param y the denominator. Must not be 0.
  2123. * \returns the remainder of `x / y`.
  2124. *
  2125. * \threadsafety It is safe to call this function from any thread.
  2126. *
  2127. * \since This function is available since SDL 3.0.0.
  2128. *
  2129. * \sa SDL_fmodf
  2130. * \sa SDL_modf
  2131. * \sa SDL_trunc
  2132. * \sa SDL_ceil
  2133. * \sa SDL_floor
  2134. * \sa SDL_round
  2135. * \sa SDL_lround
  2136. */
  2137. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  2138. /**
  2139. * Return the floating-point remainder of `x / y`
  2140. *
  2141. * Divides `x` by `y`, and returns the remainder.
  2142. *
  2143. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  2144. *
  2145. * Range: `-y <= z <= y`
  2146. *
  2147. * This function operates on single-precision floating point values, use
  2148. * SDL_fmod for single-precision floats.
  2149. *
  2150. * \param x the numerator.
  2151. * \param y the denominator. Must not be 0.
  2152. * \returns the remainder of `x / y`.
  2153. *
  2154. * \threadsafety It is safe to call this function from any thread.
  2155. *
  2156. * \since This function is available since SDL 3.0.0.
  2157. *
  2158. * \sa SDL_fmod
  2159. * \sa SDL_truncf
  2160. * \sa SDL_modff
  2161. * \sa SDL_ceilf
  2162. * \sa SDL_floorf
  2163. * \sa SDL_roundf
  2164. * \sa SDL_lroundf
  2165. */
  2166. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  2167. /**
  2168. * Return whether the value is infinity.
  2169. *
  2170. * \param x double-precision floating point value.
  2171. * \returns non-zero if the value is infinity, 0 otherwise.
  2172. *
  2173. * \threadsafety It is safe to call this function from any thread.
  2174. *
  2175. * \since This function is available since SDL 3.0.0.
  2176. *
  2177. * \sa SDL_isinff
  2178. */
  2179. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  2180. /**
  2181. * Return whether the value is infinity.
  2182. *
  2183. * \param x floating point value.
  2184. * \returns non-zero if the value is infinity, 0 otherwise.
  2185. *
  2186. * \threadsafety It is safe to call this function from any thread.
  2187. *
  2188. * \since This function is available since SDL 3.0.0.
  2189. *
  2190. * \sa SDL_isinf
  2191. */
  2192. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  2193. /**
  2194. * Return whether the value is NaN.
  2195. *
  2196. * \param x double-precision floating point value.
  2197. * \returns non-zero if the value is NaN, 0 otherwise.
  2198. *
  2199. * \threadsafety It is safe to call this function from any thread.
  2200. *
  2201. * \since This function is available since SDL 3.0.0.
  2202. *
  2203. * \sa SDL_isnanf
  2204. */
  2205. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  2206. /**
  2207. * Return whether the value is NaN.
  2208. *
  2209. * \param x floating point value.
  2210. * \returns non-zero if the value is NaN, 0 otherwise.
  2211. *
  2212. * \threadsafety It is safe to call this function from any thread.
  2213. *
  2214. * \since This function is available since SDL 3.0.0.
  2215. *
  2216. * \sa SDL_isnan
  2217. */
  2218. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  2219. /**
  2220. * Compute the natural logarithm of `x`.
  2221. *
  2222. * Domain: `0 < x <= INF`
  2223. *
  2224. * Range: `-INF <= y <= INF`
  2225. *
  2226. * It is an error for `x` to be less than or equal to 0.
  2227. *
  2228. * This function operates on double-precision floating point values, use
  2229. * SDL_logf for single-precision floats.
  2230. *
  2231. * This function may use a different approximation across different versions,
  2232. * platforms and configurations. i.e, it can return a different value given
  2233. * the same input on different machines or operating systems, or if SDL is
  2234. * updated.
  2235. *
  2236. * \param x floating point value. Must be greater than 0.
  2237. * \returns the natural logarithm of `x`.
  2238. *
  2239. * \threadsafety It is safe to call this function from any thread.
  2240. *
  2241. * \since This function is available since SDL 3.0.0.
  2242. *
  2243. * \sa SDL_logf
  2244. * \sa SDL_log10
  2245. * \sa SDL_exp
  2246. */
  2247. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  2248. /**
  2249. * Compute the natural logarithm of `x`.
  2250. *
  2251. * Domain: `0 < x <= INF`
  2252. *
  2253. * Range: `-INF <= y <= INF`
  2254. *
  2255. * It is an error for `x` to be less than or equal to 0.
  2256. *
  2257. * This function operates on single-precision floating point values, use
  2258. * SDL_log for double-precision floats.
  2259. *
  2260. * This function may use a different approximation across different versions,
  2261. * platforms and configurations. i.e, it can return a different value given
  2262. * the same input on different machines or operating systems, or if SDL is
  2263. * updated.
  2264. *
  2265. * \param x floating point value. Must be greater than 0.
  2266. * \returns the natural logarithm of `x`.
  2267. *
  2268. * \threadsafety It is safe to call this function from any thread.
  2269. *
  2270. * \since This function is available since SDL 3.0.0.
  2271. *
  2272. * \sa SDL_log
  2273. * \sa SDL_expf
  2274. */
  2275. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  2276. /**
  2277. * Compute the base-10 logarithm of `x`.
  2278. *
  2279. * Domain: `0 < x <= INF`
  2280. *
  2281. * Range: `-INF <= y <= INF`
  2282. *
  2283. * It is an error for `x` to be less than or equal to 0.
  2284. *
  2285. * This function operates on double-precision floating point values, use
  2286. * SDL_log10f for single-precision floats.
  2287. *
  2288. * This function may use a different approximation across different versions,
  2289. * platforms and configurations. i.e, it can return a different value given
  2290. * the same input on different machines or operating systems, or if SDL is
  2291. * updated.
  2292. *
  2293. * \param x floating point value. Must be greater than 0.
  2294. * \returns the logarithm of `x`.
  2295. *
  2296. * \threadsafety It is safe to call this function from any thread.
  2297. *
  2298. * \since This function is available since SDL 3.0.0.
  2299. *
  2300. * \sa SDL_log10f
  2301. * \sa SDL_log
  2302. * \sa SDL_pow
  2303. */
  2304. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  2305. /**
  2306. * Compute the base-10 logarithm of `x`.
  2307. *
  2308. * Domain: `0 < x <= INF`
  2309. *
  2310. * Range: `-INF <= y <= INF`
  2311. *
  2312. * It is an error for `x` to be less than or equal to 0.
  2313. *
  2314. * This function operates on single-precision floating point values, use
  2315. * SDL_log10 for double-precision floats.
  2316. *
  2317. * This function may use a different approximation across different versions,
  2318. * platforms and configurations. i.e, it can return a different value given
  2319. * the same input on different machines or operating systems, or if SDL is
  2320. * updated.
  2321. *
  2322. * \param x floating point value. Must be greater than 0.
  2323. * \returns the logarithm of `x`.
  2324. *
  2325. * \threadsafety It is safe to call this function from any thread.
  2326. *
  2327. * \since This function is available since SDL 3.0.0.
  2328. *
  2329. * \sa SDL_log10
  2330. * \sa SDL_logf
  2331. * \sa SDL_powf
  2332. */
  2333. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  2334. /**
  2335. * Split `x` into integer and fractional parts
  2336. *
  2337. * This function operates on double-precision floating point values, use
  2338. * SDL_modff for single-precision floats.
  2339. *
  2340. * \param x floating point value.
  2341. * \param y output pointer to store the integer part of `x`.
  2342. * \returns the fractional part of `x`.
  2343. *
  2344. * \threadsafety It is safe to call this function from any thread.
  2345. *
  2346. * \since This function is available since SDL 3.0.0.
  2347. *
  2348. * \sa SDL_modff
  2349. * \sa SDL_trunc
  2350. * \sa SDL_fmod
  2351. */
  2352. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  2353. /**
  2354. * Split `x` into integer and fractional parts
  2355. *
  2356. * This function operates on single-precision floating point values, use
  2357. * SDL_modf for double-precision floats.
  2358. *
  2359. * \param x floating point value.
  2360. * \param y output pointer to store the integer part of `x`.
  2361. * \returns the fractional part of `x`.
  2362. *
  2363. * \threadsafety It is safe to call this function from any thread.
  2364. *
  2365. * \since This function is available since SDL 3.0.0.
  2366. *
  2367. * \sa SDL_modf
  2368. * \sa SDL_truncf
  2369. * \sa SDL_fmodf
  2370. */
  2371. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  2372. /**
  2373. * Raise `x` to the power `y`
  2374. *
  2375. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2376. *
  2377. * Range: `-INF <= z <= INF`
  2378. *
  2379. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2380. * instead.
  2381. *
  2382. * This function operates on double-precision floating point values, use
  2383. * SDL_powf for single-precision floats.
  2384. *
  2385. * This function may use a different approximation across different versions,
  2386. * platforms and configurations. i.e, it can return a different value given
  2387. * the same input on different machines or operating systems, or if SDL is
  2388. * updated.
  2389. *
  2390. * \param x the base.
  2391. * \param y the exponent.
  2392. * \returns `x` raised to the power `y`.
  2393. *
  2394. * \threadsafety It is safe to call this function from any thread.
  2395. *
  2396. * \since This function is available since SDL 3.0.0.
  2397. *
  2398. * \sa SDL_powf
  2399. * \sa SDL_exp
  2400. * \sa SDL_log
  2401. */
  2402. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  2403. /**
  2404. * Raise `x` to the power `y`
  2405. *
  2406. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2407. *
  2408. * Range: `-INF <= z <= INF`
  2409. *
  2410. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2411. * instead.
  2412. *
  2413. * This function operates on single-precision floating point values, use
  2414. * SDL_powf for double-precision floats.
  2415. *
  2416. * This function may use a different approximation across different versions,
  2417. * platforms and configurations. i.e, it can return a different value given
  2418. * the same input on different machines or operating systems, or if SDL is
  2419. * updated.
  2420. *
  2421. * \param x the base.
  2422. * \param y the exponent.
  2423. * \returns `x` raised to the power `y`.
  2424. *
  2425. * \threadsafety It is safe to call this function from any thread.
  2426. *
  2427. * \since This function is available since SDL 3.0.0.
  2428. *
  2429. * \sa SDL_pow
  2430. * \sa SDL_expf
  2431. * \sa SDL_logf
  2432. */
  2433. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  2434. /**
  2435. * Round `x` to the nearest integer.
  2436. *
  2437. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2438. * rounded away from zero.
  2439. *
  2440. * Domain: `-INF <= x <= INF`
  2441. *
  2442. * Range: `-INF <= y <= INF`, y integer
  2443. *
  2444. * This function operates on double-precision floating point values, use
  2445. * SDL_roundf for single-precision floats. To get the result as an integer
  2446. * type, use SDL_lround.
  2447. *
  2448. * \param x floating point value.
  2449. * \returns the nearest integer to `x`.
  2450. *
  2451. * \threadsafety It is safe to call this function from any thread.
  2452. *
  2453. * \since This function is available since SDL 3.0.0.
  2454. *
  2455. * \sa SDL_roundf
  2456. * \sa SDL_lround
  2457. * \sa SDL_floor
  2458. * \sa SDL_ceil
  2459. * \sa SDL_trunc
  2460. */
  2461. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  2462. /**
  2463. * Round `x` to the nearest integer.
  2464. *
  2465. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2466. * rounded away from zero.
  2467. *
  2468. * Domain: `-INF <= x <= INF`
  2469. *
  2470. * Range: `-INF <= y <= INF`, y integer
  2471. *
  2472. * This function operates on double-precision floating point values, use
  2473. * SDL_roundf for single-precision floats. To get the result as an integer
  2474. * type, use SDL_lroundf.
  2475. *
  2476. * \param x floating point value.
  2477. * \returns the nearest integer to `x`.
  2478. *
  2479. * \threadsafety It is safe to call this function from any thread.
  2480. *
  2481. * \since This function is available since SDL 3.0.0.
  2482. *
  2483. * \sa SDL_round
  2484. * \sa SDL_lroundf
  2485. * \sa SDL_floorf
  2486. * \sa SDL_ceilf
  2487. * \sa SDL_truncf
  2488. */
  2489. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  2490. /**
  2491. * Round `x` to the nearest integer representable as a long
  2492. *
  2493. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2494. * rounded away from zero.
  2495. *
  2496. * Domain: `-INF <= x <= INF`
  2497. *
  2498. * Range: `MIN_LONG <= y <= MAX_LONG`
  2499. *
  2500. * This function operates on double-precision floating point values, use
  2501. * SDL_lround for single-precision floats. To get the result as a
  2502. * floating-point type, use SDL_round.
  2503. *
  2504. * \param x floating point value.
  2505. * \returns the nearest integer to `x`.
  2506. *
  2507. * \threadsafety It is safe to call this function from any thread.
  2508. *
  2509. * \since This function is available since SDL 3.0.0.
  2510. *
  2511. * \sa SDL_lroundf
  2512. * \sa SDL_round
  2513. * \sa SDL_floor
  2514. * \sa SDL_ceil
  2515. * \sa SDL_trunc
  2516. */
  2517. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  2518. /**
  2519. * Round `x` to the nearest integer representable as a long
  2520. *
  2521. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2522. * rounded away from zero.
  2523. *
  2524. * Domain: `-INF <= x <= INF`
  2525. *
  2526. * Range: `MIN_LONG <= y <= MAX_LONG`
  2527. *
  2528. * This function operates on single-precision floating point values, use
  2529. * SDL_lroundf for double-precision floats. To get the result as a
  2530. * floating-point type, use SDL_roundf,
  2531. *
  2532. * \param x floating point value.
  2533. * \returns the nearest integer to `x`.
  2534. *
  2535. * \threadsafety It is safe to call this function from any thread.
  2536. *
  2537. * \since This function is available since SDL 3.0.0.
  2538. *
  2539. * \sa SDL_lround
  2540. * \sa SDL_roundf
  2541. * \sa SDL_floorf
  2542. * \sa SDL_ceilf
  2543. * \sa SDL_truncf
  2544. */
  2545. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  2546. /**
  2547. * Scale `x` by an integer power of two.
  2548. *
  2549. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2550. *
  2551. * Domain: `-INF <= x <= INF`, `n` integer
  2552. *
  2553. * Range: `-INF <= y <= INF`
  2554. *
  2555. * This function operates on double-precision floating point values, use
  2556. * SDL_scalbnf for single-precision floats.
  2557. *
  2558. * \param x floating point value to be scaled.
  2559. * \param n integer exponent.
  2560. * \returns `x * 2^n`.
  2561. *
  2562. * \threadsafety It is safe to call this function from any thread.
  2563. *
  2564. * \since This function is available since SDL 3.0.0.
  2565. *
  2566. * \sa SDL_scalbnf
  2567. * \sa SDL_pow
  2568. */
  2569. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  2570. /**
  2571. * Scale `x` by an integer power of two.
  2572. *
  2573. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2574. *
  2575. * Domain: `-INF <= x <= INF`, `n` integer
  2576. *
  2577. * Range: `-INF <= y <= INF`
  2578. *
  2579. * This function operates on single-precision floating point values, use
  2580. * SDL_scalbn for double-precision floats.
  2581. *
  2582. * \param x floating point value to be scaled.
  2583. * \param n integer exponent.
  2584. * \returns `x * 2^n`.
  2585. *
  2586. * \threadsafety It is safe to call this function from any thread.
  2587. *
  2588. * \since This function is available since SDL 3.0.0.
  2589. *
  2590. * \sa SDL_scalbn
  2591. * \sa SDL_powf
  2592. */
  2593. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  2594. /**
  2595. * Compute the sine of `x`.
  2596. *
  2597. * Domain: `-INF <= x <= INF`
  2598. *
  2599. * Range: `-1 <= y <= 1`
  2600. *
  2601. * This function operates on double-precision floating point values, use
  2602. * SDL_sinf for single-precision floats.
  2603. *
  2604. * This function may use a different approximation across different versions,
  2605. * platforms and configurations. i.e, it can return a different value given
  2606. * the same input on different machines or operating systems, or if SDL is
  2607. * updated.
  2608. *
  2609. * \param x floating point value, in radians.
  2610. * \returns sine of `x`.
  2611. *
  2612. * \threadsafety It is safe to call this function from any thread.
  2613. *
  2614. * \since This function is available since SDL 3.0.0.
  2615. *
  2616. * \sa SDL_sinf
  2617. * \sa SDL_asin
  2618. * \sa SDL_cos
  2619. */
  2620. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  2621. /**
  2622. * Compute the sine of `x`.
  2623. *
  2624. * Domain: `-INF <= x <= INF`
  2625. *
  2626. * Range: `-1 <= y <= 1`
  2627. *
  2628. * This function operates on single-precision floating point values, use
  2629. * SDL_sinf for double-precision floats.
  2630. *
  2631. * This function may use a different approximation across different versions,
  2632. * platforms and configurations. i.e, it can return a different value given
  2633. * the same input on different machines or operating systems, or if SDL is
  2634. * updated.
  2635. *
  2636. * \param x floating point value, in radians.
  2637. * \returns sine of `x`.
  2638. *
  2639. * \threadsafety It is safe to call this function from any thread.
  2640. *
  2641. * \since This function is available since SDL 3.0.0.
  2642. *
  2643. * \sa SDL_sin
  2644. * \sa SDL_asinf
  2645. * \sa SDL_cosf
  2646. */
  2647. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  2648. /**
  2649. * Compute the square root of `x`.
  2650. *
  2651. * Domain: `0 <= x <= INF`
  2652. *
  2653. * Range: `0 <= y <= INF`
  2654. *
  2655. * This function operates on double-precision floating point values, use
  2656. * SDL_sqrtf for single-precision floats.
  2657. *
  2658. * This function may use a different approximation across different versions,
  2659. * platforms and configurations. i.e, it can return a different value given
  2660. * the same input on different machines or operating systems, or if SDL is
  2661. * updated.
  2662. *
  2663. * \param x floating point value. Must be greater than or equal to 0.
  2664. * \returns square root of `x`.
  2665. *
  2666. * \threadsafety It is safe to call this function from any thread.
  2667. *
  2668. * \since This function is available since SDL 3.0.0.
  2669. *
  2670. * \sa SDL_sqrtf
  2671. */
  2672. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  2673. /**
  2674. * Compute the square root of `x`.
  2675. *
  2676. * Domain: `0 <= x <= INF`
  2677. *
  2678. * Range: `0 <= y <= INF`
  2679. *
  2680. * This function operates on single-precision floating point values, use
  2681. * SDL_sqrt for double-precision floats.
  2682. *
  2683. * This function may use a different approximation across different versions,
  2684. * platforms and configurations. i.e, it can return a different value given
  2685. * the same input on different machines or operating systems, or if SDL is
  2686. * updated.
  2687. *
  2688. * \param x floating point value. Must be greater than or equal to 0.
  2689. * \returns square root of `x`.
  2690. *
  2691. * \threadsafety It is safe to call this function from any thread.
  2692. *
  2693. * \since This function is available since SDL 3.0.0.
  2694. *
  2695. * \sa SDL_sqrt
  2696. */
  2697. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  2698. /**
  2699. * Compute the tangent of `x`.
  2700. *
  2701. * Domain: `-INF <= x <= INF`
  2702. *
  2703. * Range: `-INF <= y <= INF`
  2704. *
  2705. * This function operates on double-precision floating point values, use
  2706. * SDL_tanf for single-precision floats.
  2707. *
  2708. * This function may use a different approximation across different versions,
  2709. * platforms and configurations. i.e, it can return a different value given
  2710. * the same input on different machines or operating systems, or if SDL is
  2711. * updated.
  2712. *
  2713. * \param x floating point value, in radians.
  2714. * \returns tangent of `x`.
  2715. *
  2716. * \threadsafety It is safe to call this function from any thread.
  2717. *
  2718. * \since This function is available since SDL 3.0.0.
  2719. *
  2720. * \sa SDL_tanf
  2721. * \sa SDL_sin
  2722. * \sa SDL_cos
  2723. * \sa SDL_atan
  2724. * \sa SDL_atan2
  2725. */
  2726. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  2727. /**
  2728. * Compute the tangent of `x`.
  2729. *
  2730. * Domain: `-INF <= x <= INF`
  2731. *
  2732. * Range: `-INF <= y <= INF`
  2733. *
  2734. * This function operates on single-precision floating point values, use
  2735. * SDL_tanf for double-precision floats.
  2736. *
  2737. * This function may use a different approximation across different versions,
  2738. * platforms and configurations. i.e, it can return a different value given
  2739. * the same input on different machines or operating systems, or if SDL is
  2740. * updated.
  2741. *
  2742. * \param x floating point value, in radians.
  2743. * \returns tangent of `x`.
  2744. *
  2745. * \threadsafety It is safe to call this function from any thread.
  2746. *
  2747. * \since This function is available since SDL 3.0.0.
  2748. *
  2749. * \sa SDL_tan
  2750. * \sa SDL_sinf
  2751. * \sa SDL_cosf
  2752. * \sa SDL_atanf
  2753. * \sa SDL_atan2f
  2754. */
  2755. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  2756. /* The SDL implementation of iconv() returns these error codes */
  2757. #define SDL_ICONV_ERROR (size_t)-1
  2758. #define SDL_ICONV_E2BIG (size_t)-2
  2759. #define SDL_ICONV_EILSEQ (size_t)-3
  2760. #define SDL_ICONV_EINVAL (size_t)-4
  2761. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  2762. /**
  2763. * This function allocates a context for the specified character set
  2764. * conversion.
  2765. *
  2766. * \param tocode The target character encoding, must not be NULL.
  2767. * \param fromcode The source character encoding, must not be NULL.
  2768. * \returns a handle that must be freed with SDL_iconv_close, or
  2769. * SDL_ICONV_ERROR on failure.
  2770. *
  2771. * \since This function is available since SDL 3.0.0.
  2772. *
  2773. * \sa SDL_iconv
  2774. * \sa SDL_iconv_close
  2775. * \sa SDL_iconv_string
  2776. */
  2777. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  2778. const char *fromcode);
  2779. /**
  2780. * This function frees a context used for character set conversion.
  2781. *
  2782. * \param cd The character set conversion handle.
  2783. * \returns 0 on success, or -1 on failure.
  2784. *
  2785. * \since This function is available since SDL 3.0.0.
  2786. *
  2787. * \sa SDL_iconv
  2788. * \sa SDL_iconv_open
  2789. * \sa SDL_iconv_string
  2790. */
  2791. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  2792. /**
  2793. * This function converts text between encodings, reading from and writing to
  2794. * a buffer.
  2795. *
  2796. * It returns the number of succesful conversions.
  2797. *
  2798. * \param cd The character set conversion context, created in
  2799. * SDL_iconv_open().
  2800. * \param inbuf Address of variable that points to the first character of the
  2801. * input sequence.
  2802. * \param inbytesleft The number of bytes in the input buffer.
  2803. * \param outbuf Address of variable that points to the output buffer.
  2804. * \param outbytesleft The number of bytes in the output buffer.
  2805. * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
  2806. * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
  2807. * is returned when an invalid input sequence is encountered, or
  2808. * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  2809. * encountered.
  2810. *
  2811. * On exit:
  2812. *
  2813. * - inbuf will point to the beginning of the next multibyte
  2814. * sequence. On error, this is the location of the problematic
  2815. * input sequence. On success, this is the end of the input
  2816. * sequence. - inbytesleft will be set to the number of bytes left
  2817. * to convert, which will be 0 on success. - outbuf will point to
  2818. * the location where to store the next output byte. - outbytesleft
  2819. * will be set to the number of bytes left in the output buffer.
  2820. *
  2821. * \since This function is available since SDL 3.0.0.
  2822. *
  2823. * \sa SDL_iconv_open
  2824. * \sa SDL_iconv_close
  2825. * \sa SDL_iconv_string
  2826. */
  2827. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  2828. size_t *inbytesleft, char **outbuf,
  2829. size_t *outbytesleft);
  2830. /**
  2831. * Helper function to convert a string's encoding in one call.
  2832. *
  2833. * This function converts a buffer or string between encodings in one pass.
  2834. *
  2835. * The string does not need to be NULL-terminated; this function operates on
  2836. * the number of bytes specified in `inbytesleft` whether there is a NULL
  2837. * character anywhere in the buffer.
  2838. *
  2839. * The returned string is owned by the caller, and should be passed to
  2840. * SDL_free when no longer needed.
  2841. *
  2842. * \param tocode the character encoding of the output string. Examples are
  2843. * "UTF-8", "UCS-4", etc.
  2844. * \param fromcode the character encoding of data in `inbuf`.
  2845. * \param inbuf the string to convert to a different encoding.
  2846. * \param inbytesleft the size of the input string _in bytes_.
  2847. * \returns a new string, converted to the new encoding, or NULL on error.
  2848. *
  2849. * \since This function is available since SDL 3.0.0.
  2850. *
  2851. * \sa SDL_iconv_open
  2852. * \sa SDL_iconv_close
  2853. * \sa SDL_iconv
  2854. */
  2855. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  2856. const char *fromcode,
  2857. const char *inbuf,
  2858. size_t inbytesleft);
  2859. /* Some helper macros for common cases... */
  2860. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  2861. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  2862. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  2863. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  2864. /* force builds using Clang's static analysis tools to use literal C runtime
  2865. here, since there are possibly tests that are ineffective otherwise. */
  2866. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  2867. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  2868. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  2869. size_t strlcpy(char *dst, const char *src, size_t size);
  2870. #endif
  2871. /* The analyzer knows about strlcat even when the system doesn't provide it */
  2872. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  2873. size_t strlcat(char *dst, const char *src, size_t size);
  2874. #endif
  2875. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  2876. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  2877. #endif
  2878. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  2879. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  2880. #endif
  2881. /* Starting LLVM 16, the analyser errors out if these functions do not have
  2882. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  2883. #include <stdio.h>
  2884. #include <stdlib.h>
  2885. #include <strings.h>
  2886. #define SDL_malloc malloc
  2887. #define SDL_calloc calloc
  2888. #define SDL_realloc realloc
  2889. #define SDL_free free
  2890. #ifndef SDL_memcpy
  2891. #define SDL_memcpy memcpy
  2892. #endif
  2893. #ifndef SDL_memmove
  2894. #define SDL_memmove memmove
  2895. #endif
  2896. #ifndef SDL_memset
  2897. #define SDL_memset memset
  2898. #endif
  2899. #define SDL_memcmp memcmp
  2900. #define SDL_strlcpy strlcpy
  2901. #define SDL_strlcat strlcat
  2902. #define SDL_strlen strlen
  2903. #define SDL_wcslen wcslen
  2904. #define SDL_wcslcpy wcslcpy
  2905. #define SDL_wcslcat wcslcat
  2906. #define SDL_strdup strdup
  2907. #define SDL_wcsdup wcsdup
  2908. #define SDL_strchr strchr
  2909. #define SDL_strrchr strrchr
  2910. #define SDL_strstr strstr
  2911. #define SDL_wcsstr wcsstr
  2912. #define SDL_strtok_r strtok_r
  2913. #define SDL_strcmp strcmp
  2914. #define SDL_wcscmp wcscmp
  2915. #define SDL_strncmp strncmp
  2916. #define SDL_wcsncmp wcsncmp
  2917. #define SDL_strcasecmp strcasecmp
  2918. #define SDL_strncasecmp strncasecmp
  2919. #define SDL_strpbrk strpbrk
  2920. #define SDL_sscanf sscanf
  2921. #define SDL_vsscanf vsscanf
  2922. #define SDL_snprintf snprintf
  2923. #define SDL_vsnprintf vsnprintf
  2924. #endif
  2925. /**
  2926. * Multiply two integers, checking for overflow.
  2927. *
  2928. * If `a * b` would overflow, return SDL_FALSE.
  2929. *
  2930. * Otherwise store `a * b` via ret and return SDL_TRUE.
  2931. *
  2932. * \param a the multiplicand.
  2933. * \param b the multiplier.
  2934. * \param ret on non-overflow output, stores the multiplication result. May
  2935. * not be NULL.
  2936. * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without
  2937. * overflow.
  2938. *
  2939. * \threadsafety It is safe to call this function from any thread.
  2940. *
  2941. * \since This function is available since SDL 3.0.0.
  2942. */
  2943. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  2944. {
  2945. if (a != 0 && b > SDL_SIZE_MAX / a) {
  2946. return SDL_FALSE;
  2947. }
  2948. *ret = a * b;
  2949. return SDL_TRUE;
  2950. }
  2951. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  2952. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  2953. /* This needs to be wrapped in an inline rather than being a direct #define,
  2954. * because __builtin_mul_overflow() is type-generic, but we want to be
  2955. * consistent about interpreting a and b as size_t. */
  2956. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  2957. {
  2958. return (__builtin_mul_overflow(a, b, ret) == 0);
  2959. }
  2960. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  2961. #endif
  2962. #endif
  2963. /**
  2964. * Add two integers, checking for overflow.
  2965. *
  2966. * If `a + b` would overflow, return -1.
  2967. *
  2968. * Otherwise store `a + b` via ret and return 0.
  2969. *
  2970. * \param a the first addend.
  2971. * \param b the second addend.
  2972. * \param ret on non-overflow output, stores the addition result. May not be
  2973. * NULL.
  2974. * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without
  2975. * overflow.
  2976. *
  2977. * \threadsafety It is safe to call this function from any thread.
  2978. *
  2979. * \since This function is available since SDL 3.0.0.
  2980. */
  2981. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  2982. {
  2983. if (b > SDL_SIZE_MAX - a) {
  2984. return SDL_FALSE;
  2985. }
  2986. *ret = a + b;
  2987. return SDL_TRUE;
  2988. }
  2989. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  2990. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  2991. /* This needs to be wrapped in an inline rather than being a direct #define,
  2992. * the same as the call to __builtin_mul_overflow() above. */
  2993. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  2994. {
  2995. return (__builtin_add_overflow(a, b, ret) == 0);
  2996. }
  2997. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  2998. #endif
  2999. #endif
  3000. /* This is a generic function pointer which should be cast to the type you expect */
  3001. #ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
  3002. typedef void *SDL_FunctionPointer;
  3003. #else
  3004. typedef void (*SDL_FunctionPointer)(void);
  3005. #endif
  3006. /* Ends C function definitions when using C++ */
  3007. #ifdef __cplusplus
  3008. }
  3009. #endif
  3010. #include <SDL3/SDL_close_code.h>
  3011. #endif /* SDL_stdinc_h_ */