SDL_stdinc.h 90 KB

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