SDL_stdinc.h 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735
  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. #ifndef SDL_PI_D
  1162. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  1163. #endif
  1164. #ifndef SDL_PI_F
  1165. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  1166. #endif
  1167. /**
  1168. * Compute the arc cosine of `x`.
  1169. *
  1170. * The definition of `y = acos(x)` is `x = cos(y)`.
  1171. *
  1172. * Domain: `-1 <= x <= 1`
  1173. *
  1174. * Range: `0 <= y <= Pi`
  1175. *
  1176. * This function operates on double-precision floating point values, use
  1177. * SDL_acosf for single-precision floats.
  1178. *
  1179. * This function may use a different approximation across different versions,
  1180. * platforms and configurations. i.e, it can return a different value given
  1181. * the same input on different machines or operating systems, or if SDL is
  1182. * updated.
  1183. *
  1184. * \param x floating point value
  1185. * \returns arc cosine of `x`, in radians
  1186. *
  1187. * \threadsafety It is safe to call this function from any thread.
  1188. *
  1189. * \since This function is available since SDL 3.0.0.
  1190. *
  1191. * \sa SDL_acosf
  1192. * \sa SDL_asin
  1193. * \sa SDL_cos
  1194. */
  1195. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  1196. /**
  1197. * Compute the arc cosine of `x`.
  1198. *
  1199. * The definition of `y = acos(x)` is `x = cos(y)`.
  1200. *
  1201. * Domain: `-1 <= x <= 1`
  1202. *
  1203. * Range: `0 <= y <= Pi`
  1204. *
  1205. * This function operates on single-precision floating point values, use
  1206. * SDL_acos for double-precision floats.
  1207. *
  1208. * This function may use a different approximation across different versions,
  1209. * platforms and configurations. i.e, it can return a different value given
  1210. * the same input on different machines or operating systems, or if SDL is
  1211. * updated.
  1212. *
  1213. * \param x floating point value.
  1214. * \returns arc cosine of `x`, in radians
  1215. *
  1216. * \threadsafety It is safe to call this function from any thread.
  1217. *
  1218. * \since This function is available since SDL 3.0.0.
  1219. *
  1220. * \sa SDL_acos
  1221. * \sa SDL_asinf
  1222. * \sa SDL_cosf
  1223. */
  1224. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  1225. /**
  1226. * Compute the arc sine of `x`.
  1227. *
  1228. * The definition of `y = asin(x)` is `x = sin(y)`.
  1229. *
  1230. * Domain: `-1 <= x <= 1`
  1231. *
  1232. * Range: `-Pi/2 <= y <= Pi/2`
  1233. *
  1234. * This function operates on double-precision floating point values, use
  1235. * SDL_asinf for single-precision floats.
  1236. *
  1237. * This function may use a different approximation across different versions,
  1238. * platforms and configurations. i.e, it can return a different value given
  1239. * the same input on different machines or operating systems, or if SDL is
  1240. * updated.
  1241. *
  1242. * \param x floating point value.
  1243. * \returns arc sine of `x`, in radians.
  1244. *
  1245. * \threadsafety It is safe to call this function from any thread.
  1246. *
  1247. * \since This function is available since SDL 3.0.0.
  1248. *
  1249. * \sa SDL_asinf
  1250. * \sa SDL_acos
  1251. * \sa SDL_sin
  1252. */
  1253. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  1254. /**
  1255. * Compute the arc sine of `x`.
  1256. *
  1257. * The definition of `y = asin(x)` is `x = sin(y)`.
  1258. *
  1259. * Domain: `-1 <= x <= 1`
  1260. *
  1261. * Range: `-Pi/2 <= y <= Pi/2`
  1262. *
  1263. * This function operates on single-precision floating point values, use
  1264. * SDL_asin for double-precision floats.
  1265. *
  1266. * This function may use a different approximation across different versions,
  1267. * platforms and configurations. i.e, it can return a different value given
  1268. * the same input on different machines or operating systems, or if SDL is
  1269. * updated.
  1270. *
  1271. * \param x floating point value.
  1272. * \returns arc sine of `x`, in radians.
  1273. *
  1274. * \threadsafety It is safe to call this function from any thread.
  1275. *
  1276. * \since This function is available since SDL 3.0.0.
  1277. *
  1278. * \sa SDL_asin
  1279. * \sa SDL_acosf
  1280. * \sa SDL_sinf
  1281. */
  1282. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  1283. /**
  1284. * Compute the arc tangent of `x`.
  1285. *
  1286. * The definition of `y = atan(x)` is `x = tan(y)`.
  1287. *
  1288. * Domain: `-INF <= x <= INF`
  1289. *
  1290. * Range: `-Pi/2 <= y <= Pi/2`
  1291. *
  1292. * This function operates on double-precision floating point values, use
  1293. * SDL_atanf for single-precision floats.
  1294. *
  1295. * To calculate the arc tangent of y / x, use SDL_atan2.
  1296. *
  1297. * This function may use a different approximation across different versions,
  1298. * platforms and configurations. i.e, it can return a different value given
  1299. * the same input on different machines or operating systems, or if SDL is
  1300. * updated.
  1301. *
  1302. * \param x floating point value.
  1303. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1304. *
  1305. * \threadsafety It is safe to call this function from any thread.
  1306. *
  1307. * \since This function is available since SDL 3.0.0.
  1308. *
  1309. * \sa SDL_atanf
  1310. * \sa SDL_atan2
  1311. * \sa SDL_tan
  1312. */
  1313. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  1314. /**
  1315. * Compute the arc tangent of `x`.
  1316. *
  1317. * The definition of `y = atan(x)` is `x = tan(y)`.
  1318. *
  1319. * Domain: `-INF <= x <= INF`
  1320. *
  1321. * Range: `-Pi/2 <= y <= Pi/2`
  1322. *
  1323. * This function operates on single-precision floating point values, use
  1324. * SDL_atan for dboule-precision floats.
  1325. *
  1326. * To calculate the arc tangent of y / x, use SDL_atan2f.
  1327. *
  1328. * This function may use a different approximation across different versions,
  1329. * platforms and configurations. i.e, it can return a different value given
  1330. * the same input on different machines or operating systems, or if SDL is
  1331. * updated.
  1332. *
  1333. * \param x floating point value.
  1334. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`
  1335. *
  1336. * \threadsafety It is safe to call this function from any thread.
  1337. *
  1338. * \since This function is available since SDL 3.0.0.
  1339. *
  1340. * \sa SDL_atan
  1341. * \sa SDL_atan2f
  1342. * \sa SDL_tanf
  1343. */
  1344. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  1345. /**
  1346. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1347. * the result's quadrant.
  1348. *
  1349. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1350. * of z is determined based on the signs of x and y.
  1351. *
  1352. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1353. *
  1354. * Range: `-Pi/2 <= y <= Pi/2`
  1355. *
  1356. * This function operates on double-precision floating point values, use
  1357. * SDL_atan2f for single-precision floats.
  1358. *
  1359. * To calculate the arc tangent of a single value, use SDL_atan.
  1360. *
  1361. * This function may use a different approximation across different versions,
  1362. * platforms and configurations. i.e, it can return a different value given
  1363. * the same input on different machines or operating systems, or if SDL is
  1364. * updated.
  1365. *
  1366. * \param y floating point value of the numerator (y coordinate)
  1367. * \param x floating point value of the denominator (x coordinate).
  1368. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1369. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1370. *
  1371. * \threadsafety It is safe to call this function from any thread.
  1372. *
  1373. * \since This function is available since SDL 3.0.0.
  1374. *
  1375. * \sa SDL_atan2f
  1376. * \sa SDL_atan
  1377. * \sa SDL_tan
  1378. */
  1379. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  1380. /**
  1381. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1382. * the result's quadrant.
  1383. *
  1384. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1385. * of z is determined based on the signs of x and y.
  1386. *
  1387. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1388. *
  1389. * Range: `-Pi/2 <= y <= Pi/2`
  1390. *
  1391. * This function operates on single-precision floating point values, use
  1392. * SDL_atan2 for double-precision floats.
  1393. *
  1394. * To calculate the arc tangent of a single value, use SDL_atanf.
  1395. *
  1396. * This function may use a different approximation across different versions,
  1397. * platforms and configurations. i.e, it can return a different value given
  1398. * the same input on different machines or operating systems, or if SDL is
  1399. * updated.
  1400. *
  1401. * \param y floating point value of the numerator (y coordinate)
  1402. * \param x floating point value of the denominator (x coordinate).
  1403. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1404. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1405. *
  1406. * \threadsafety It is safe to call this function from any thread.
  1407. *
  1408. * \since This function is available since SDL 3.0.0.
  1409. *
  1410. * \sa SDL_atan2f
  1411. * \sa SDL_atan
  1412. * \sa SDL_tan
  1413. */
  1414. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  1415. /**
  1416. * Compute the ceiling of `x`.
  1417. *
  1418. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1419. * rounded up to the nearest integer.
  1420. *
  1421. * Domain: `-INF <= x <= INF`
  1422. *
  1423. * Range: `-INF <= y <= INF`, y integer
  1424. *
  1425. * This function operates on double-precision floating point values, use
  1426. * SDL_ceilf for single-precision floats.
  1427. *
  1428. * \param x floating point value
  1429. * \returns the ceiling of `x`
  1430. *
  1431. * \threadsafety It is safe to call this function from any thread.
  1432. *
  1433. * \since This function is available since SDL 3.0.0.
  1434. *
  1435. * \sa SDL_ceilf
  1436. * \sa SDL_floor
  1437. * \sa SDL_trunc
  1438. * \sa SDL_round
  1439. * \sa SDL_lround
  1440. */
  1441. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  1442. /**
  1443. * Compute the ceiling of `x`.
  1444. *
  1445. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1446. * rounded up to the nearest integer.
  1447. *
  1448. * Domain: `-INF <= x <= INF`
  1449. *
  1450. * Range: `-INF <= y <= INF`, y integer
  1451. *
  1452. * This function operates on single-precision floating point values, use
  1453. * SDL_ceil for double-precision floats.
  1454. *
  1455. * \param x floating point value
  1456. * \returns the ceiling of `x`
  1457. *
  1458. * \threadsafety It is safe to call this function from any thread.
  1459. *
  1460. * \since This function is available since SDL 3.0.0.
  1461. *
  1462. * \sa SDL_ceil
  1463. * \sa SDL_floorf
  1464. * \sa SDL_truncf
  1465. * \sa SDL_roundf
  1466. * \sa SDL_lroundf
  1467. */
  1468. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  1469. /**
  1470. * Copy the sign of one floating-point value to another.
  1471. *
  1472. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1473. *
  1474. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1475. *
  1476. * Range: `-INF <= z <= INF`
  1477. *
  1478. * This function operates on double-precision floating point values, use
  1479. * SDL_copysignf for single-precision floats.
  1480. *
  1481. * \param x floating point value to use as the magnitude
  1482. * \param y floating point value to use as the sign
  1483. * \returns the floating point value with the sign of y and the magnitude of x
  1484. *
  1485. * \threadsafety It is safe to call this function from any thread.
  1486. *
  1487. * \since This function is available since SDL 3.0.0.
  1488. *
  1489. * \sa SDL_copysignf
  1490. * \sa SDL_fabs
  1491. */
  1492. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  1493. /**
  1494. * Copy the sign of one floating-point value to another.
  1495. *
  1496. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1497. *
  1498. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1499. *
  1500. * Range: `-INF <= z <= INF`
  1501. *
  1502. * This function operates on single-precision floating point values, use
  1503. * SDL_copysign for double-precision floats.
  1504. *
  1505. * \param x floating point value to use as the magnitude
  1506. * \param y floating point value to use as the sign
  1507. * \returns the floating point value with the sign of y and the magnitude of x
  1508. *
  1509. * \threadsafety It is safe to call this function from any thread.
  1510. *
  1511. * \since This function is available since SDL 3.0.0.
  1512. *
  1513. * \sa SDL_copysignf
  1514. * \sa SDL_fabsf
  1515. */
  1516. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  1517. /**
  1518. * Compute the cosine of `x`.
  1519. *
  1520. * Domain: `-INF <= x <= INF`
  1521. *
  1522. * Range: `-1 <= y <= 1`
  1523. *
  1524. * This function operates on double-precision floating point values, use
  1525. * SDL_cosf for single-precision floats.
  1526. *
  1527. * This function may use a different approximation across different versions,
  1528. * platforms and configurations. i.e, it can return a different value given
  1529. * the same input on different machines or operating systems, or if SDL is
  1530. * updated.
  1531. *
  1532. * \param x floating point value, in radians
  1533. * \returns cosine of `x`
  1534. *
  1535. * \threadsafety It is safe to call this function from any thread.
  1536. *
  1537. * \since This function is available since SDL 3.0.0.
  1538. *
  1539. * \sa SDL_cosf
  1540. * \sa SDL_acos
  1541. * \sa SDL_sin
  1542. */
  1543. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  1544. /**
  1545. * Compute the cosine of `x`.
  1546. *
  1547. * Domain: `-INF <= x <= INF`
  1548. *
  1549. * Range: `-1 <= y <= 1`
  1550. *
  1551. * This function operates on single-precision floating point values, use
  1552. * SDL_cos for double-precision floats.
  1553. *
  1554. * This function may use a different approximation across different versions,
  1555. * platforms and configurations. i.e, it can return a different value given
  1556. * the same input on different machines or operating systems, or if SDL is
  1557. * updated.
  1558. *
  1559. * \param x floating point value, in radians
  1560. * \returns cosine of `x`
  1561. *
  1562. * \threadsafety It is safe to call this function from any thread.
  1563. *
  1564. * \since This function is available since SDL 3.0.0.
  1565. *
  1566. * \sa SDL_cos
  1567. * \sa SDL_acosf
  1568. * \sa SDL_sinf
  1569. */
  1570. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  1571. /**
  1572. * Compute the exponential of `x`.
  1573. *
  1574. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1575. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  1576. *
  1577. * Domain: `-INF <= x <= INF`
  1578. *
  1579. * Range: `0 <= y <= INF`
  1580. *
  1581. * The output will overflow if `exp(x)` is too large to be represented.
  1582. *
  1583. * This function operates on double-precision floating point values, use
  1584. * SDL_expf 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
  1592. * \returns value of `e^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_expf
  1599. * \sa SDL_log
  1600. */
  1601. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  1602. /**
  1603. * Compute the exponential of `x`.
  1604. *
  1605. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1606. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  1607. *
  1608. * Domain: `-INF <= x <= INF`
  1609. *
  1610. * Range: `0 <= y <= INF`
  1611. *
  1612. * The output will overflow if `exp(x)` is too large to be represented.
  1613. *
  1614. * This function operates on single-precision floating point values, use
  1615. * SDL_exp for double-precision floats.
  1616. *
  1617. * This function may use a different approximation across different versions,
  1618. * platforms and configurations. i.e, it can return a different value given
  1619. * the same input on different machines or operating systems, or if SDL is
  1620. * updated.
  1621. *
  1622. * \param x floating point value
  1623. * \returns value of `e^x`
  1624. *
  1625. * \threadsafety It is safe to call this function from any thread.
  1626. *
  1627. * \since This function is available since SDL 3.0.0.
  1628. *
  1629. * \sa SDL_exp
  1630. * \sa SDL_logf
  1631. */
  1632. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  1633. /**
  1634. * Compute the absolute value of `x`
  1635. *
  1636. * Domain: `-INF <= x <= INF`
  1637. *
  1638. * Range: `0 <= y <= INF`
  1639. *
  1640. * This function operates on double-precision floating point values, use
  1641. * SDL_copysignf for single-precision floats.
  1642. *
  1643. * \param x floating point value to use as the magnitude
  1644. * \returns the absolute value of `x`
  1645. *
  1646. * \threadsafety It is safe to call this function from any thread.
  1647. *
  1648. * \since This function is available since SDL 3.0.0.
  1649. *
  1650. * \sa SDL_fabsf
  1651. */
  1652. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  1653. /**
  1654. * Compute the absolute value of `x`
  1655. *
  1656. * Domain: `-INF <= x <= INF`
  1657. *
  1658. * Range: `0 <= y <= INF`
  1659. *
  1660. * This function operates on single-precision floating point values, use
  1661. * SDL_copysignf for double-precision floats.
  1662. *
  1663. * \param x floating point value to use as the magnitude
  1664. * \returns the absolute value of `x`
  1665. *
  1666. * \threadsafety It is safe to call this function from any thread.
  1667. *
  1668. * \since This function is available since SDL 3.0.0.
  1669. *
  1670. * \sa SDL_fabs
  1671. */
  1672. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  1673. /**
  1674. * Compute the floor of `x`.
  1675. *
  1676. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  1677. * rounded down to the nearest integer.
  1678. *
  1679. * Domain: `-INF <= x <= INF`
  1680. *
  1681. * Range: `-INF <= y <= INF`, y integer
  1682. *
  1683. * This function operates on double-precision floating point values, use
  1684. * SDL_floorf for single-precision floats.
  1685. *
  1686. * \param x floating point value
  1687. * \returns the floor of `x`
  1688. *
  1689. * \threadsafety It is safe to call this function from any thread.
  1690. *
  1691. * \since This function is available since SDL 3.0.0.
  1692. *
  1693. * \sa SDL_floorf
  1694. * \sa SDL_ceil
  1695. * \sa SDL_trunc
  1696. * \sa SDL_round
  1697. * \sa SDL_lround
  1698. */
  1699. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  1700. /**
  1701. * Compute the floor of `x`.
  1702. *
  1703. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  1704. * rounded down to the nearest integer.
  1705. *
  1706. * Domain: `-INF <= x <= INF`
  1707. *
  1708. * Range: `-INF <= y <= INF`, y integer
  1709. *
  1710. * This function operates on single-precision floating point values, use
  1711. * SDL_floorf for double-precision floats.
  1712. *
  1713. * \param x floating point value
  1714. * \returns the floor of `x`
  1715. *
  1716. * \threadsafety It is safe to call this function from any thread.
  1717. *
  1718. * \since This function is available since SDL 3.0.0.
  1719. *
  1720. * \sa SDL_floor
  1721. * \sa SDL_ceilf
  1722. * \sa SDL_truncf
  1723. * \sa SDL_roundf
  1724. * \sa SDL_lroundf
  1725. */
  1726. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  1727. /**
  1728. * Truncate `x` to an integer.
  1729. *
  1730. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  1731. * the fractional part of `x`, leaving only the integer part.
  1732. *
  1733. * Domain: `-INF <= x <= INF`
  1734. *
  1735. * Range: `-INF <= y <= INF`, y integer
  1736. *
  1737. * This function operates on double-precision floating point values, use
  1738. * SDL_truncf for single-precision floats.
  1739. *
  1740. * \param x floating point value
  1741. * \returns `x` truncated to an integer
  1742. *
  1743. * \threadsafety It is safe to call this function from any thread.
  1744. *
  1745. * \since This function is available since SDL 3.0.0.
  1746. *
  1747. * \sa SDL_truncf
  1748. * \sa SDL_fmod
  1749. * \sa SDL_ceil
  1750. * \sa SDL_floor
  1751. * \sa SDL_round
  1752. * \sa SDL_lround
  1753. */
  1754. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  1755. /**
  1756. * Truncate `x` to an integer.
  1757. *
  1758. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  1759. * the fractional part of `x`, leaving only the integer part.
  1760. *
  1761. * Domain: `-INF <= x <= INF`
  1762. *
  1763. * Range: `-INF <= y <= INF`, y integer
  1764. *
  1765. * This function operates on single-precision floating point values, use
  1766. * SDL_truncf for double-precision floats.
  1767. *
  1768. * \param x floating point value
  1769. * \returns `x` truncated to an integer
  1770. *
  1771. * \threadsafety It is safe to call this function from any thread.
  1772. *
  1773. * \since This function is available since SDL 3.0.0.
  1774. *
  1775. * \sa SDL_trunc
  1776. * \sa SDL_fmodf
  1777. * \sa SDL_ceilf
  1778. * \sa SDL_floorf
  1779. * \sa SDL_roundf
  1780. * \sa SDL_lroundf
  1781. */
  1782. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  1783. /**
  1784. * Return the floating-point remainder of `x / y`
  1785. *
  1786. * Divides `x` by `y`, and returns the remainder.
  1787. *
  1788. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  1789. *
  1790. * Range: `-y <= z <= y`
  1791. *
  1792. * This function operates on double-precision floating point values, use
  1793. * SDL_fmodf for single-precision floats.
  1794. *
  1795. * \param x the numerator
  1796. * \param y the denominator. Must not be 0.
  1797. * \returns the remainder of `x / y`
  1798. *
  1799. * \threadsafety It is safe to call this function from any thread.
  1800. *
  1801. * \since This function is available since SDL 3.0.0.
  1802. *
  1803. * \sa SDL_fmodf
  1804. * \sa SDL_modf
  1805. * \sa SDL_trunc
  1806. * \sa SDL_ceil
  1807. * \sa SDL_floor
  1808. * \sa SDL_round
  1809. * \sa SDL_lround
  1810. */
  1811. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  1812. /**
  1813. * Return the floating-point remainder of `x / y`
  1814. *
  1815. * Divides `x` by `y`, and returns the remainder.
  1816. *
  1817. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  1818. *
  1819. * Range: `-y <= z <= y`
  1820. *
  1821. * This function operates on single-precision floating point values, use
  1822. * SDL_fmod for single-precision floats.
  1823. *
  1824. * \param x the numerator
  1825. * \param y the denominator. Must not be 0.
  1826. * \returns the remainder of `x / y`
  1827. *
  1828. * \threadsafety It is safe to call this function from any thread.
  1829. *
  1830. * \since This function is available since SDL 3.0.0.
  1831. *
  1832. * \sa SDL_fmod
  1833. * \sa SDL_truncf
  1834. * \sa SDL_modff
  1835. * \sa SDL_ceilf
  1836. * \sa SDL_floorf
  1837. * \sa SDL_roundf
  1838. * \sa SDL_lroundf
  1839. */
  1840. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  1841. /**
  1842. * Compute the natural logarithm of `x`.
  1843. *
  1844. * Domain: `0 < x <= INF`
  1845. *
  1846. * Range: `-INF <= y <= INF`
  1847. *
  1848. * It is an error for `x` to be less than or equal to 0.
  1849. *
  1850. * This function operates on double-precision floating point values, use
  1851. * SDL_logf for single-precision floats.
  1852. *
  1853. * This function may use a different approximation across different versions,
  1854. * platforms and configurations. i.e, it can return a different value given
  1855. * the same input on different machines or operating systems, or if SDL is
  1856. * updated.
  1857. *
  1858. * \param x floating point value. Must be greater than 0.
  1859. * \returns the natural logarithm of `x`
  1860. *
  1861. * \threadsafety It is safe to call this function from any thread.
  1862. *
  1863. * \since This function is available since SDL 3.0.0.
  1864. *
  1865. * \sa SDL_logf
  1866. * \sa SDL_log10
  1867. * \sa SDL_exp
  1868. */
  1869. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  1870. /**
  1871. * Compute the natural logarithm of `x`.
  1872. *
  1873. * Domain: `0 < x <= INF`
  1874. *
  1875. * Range: `-INF <= y <= INF`
  1876. *
  1877. * It is an error for `x` to be less than or equal to 0.
  1878. *
  1879. * This function operates on single-precision floating point values, use
  1880. * SDL_log for double-precision floats.
  1881. *
  1882. * This function may use a different approximation across different versions,
  1883. * platforms and configurations. i.e, it can return a different value given
  1884. * the same input on different machines or operating systems, or if SDL is
  1885. * updated.
  1886. *
  1887. * \param x floating point value. Must be greater than 0.
  1888. * \returns the natural logarithm of `x`
  1889. *
  1890. * \threadsafety It is safe to call this function from any thread.
  1891. *
  1892. * \since This function is available since SDL 3.0.0.
  1893. *
  1894. * \sa SDL_log
  1895. * \sa SDL_expf
  1896. */
  1897. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  1898. /**
  1899. * Compute the base-10 logarithm of `x`.
  1900. *
  1901. * Domain: `0 < x <= INF`
  1902. *
  1903. * Range: `-INF <= y <= INF`
  1904. *
  1905. * It is an error for `x` to be less than or equal to 0.
  1906. *
  1907. * This function operates on double-precision floating point values, use
  1908. * SDL_log10f for single-precision floats.
  1909. *
  1910. * This function may use a different approximation across different versions,
  1911. * platforms and configurations. i.e, it can return a different value given
  1912. * the same input on different machines or operating systems, or if SDL is
  1913. * updated.
  1914. *
  1915. * \param x floating point value. Must be greater than 0.
  1916. * \returns the logarithm of `x`
  1917. *
  1918. * \threadsafety It is safe to call this function from any thread.
  1919. *
  1920. * \since This function is available since SDL 3.0.0.
  1921. *
  1922. * \sa SDL_log10f
  1923. * \sa SDL_log
  1924. * \sa SDL_pow
  1925. */
  1926. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  1927. /**
  1928. * Compute the base-10 logarithm of `x`.
  1929. *
  1930. * Domain: `0 < x <= INF`
  1931. *
  1932. * Range: `-INF <= y <= INF`
  1933. *
  1934. * It is an error for `x` to be less than or equal to 0.
  1935. *
  1936. * This function operates on single-precision floating point values, use
  1937. * SDL_log10 for double-precision floats.
  1938. *
  1939. * This function may use a different approximation across different versions,
  1940. * platforms and configurations. i.e, it can return a different value given
  1941. * the same input on different machines or operating systems, or if SDL is
  1942. * updated.
  1943. *
  1944. * \param x floating point value. Must be greater than 0.
  1945. * \returns the logarithm of `x`
  1946. *
  1947. * \threadsafety It is safe to call this function from any thread.
  1948. *
  1949. * \since This function is available since SDL 3.0.0.
  1950. *
  1951. * \sa SDL_log10
  1952. * \sa SDL_logf
  1953. * \sa SDL_powf
  1954. */
  1955. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  1956. /**
  1957. * Split `x` into integer and fractional parts
  1958. *
  1959. * This function operates on double-precision floating point values, use
  1960. * SDL_modff for single-precision floats.
  1961. *
  1962. * \param x floating point value
  1963. * \param y output pointer to store the integer part of `x`
  1964. * \returns the fractional part of `x`
  1965. *
  1966. * \threadsafety It is safe to call this function from any thread.
  1967. *
  1968. * \since This function is available since SDL 3.0.0.
  1969. *
  1970. * \sa SDL_modff
  1971. * \sa SDL_trunc
  1972. * \sa SDL_fmod
  1973. */
  1974. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  1975. /**
  1976. * Split `x` into integer and fractional parts
  1977. *
  1978. * This function operates on single-precision floating point values, use
  1979. * SDL_modf for double-precision floats.
  1980. *
  1981. * \param x floating point value
  1982. * \param y output pointer to store the integer part of `x`
  1983. * \returns the fractional part of `x`
  1984. *
  1985. * \threadsafety It is safe to call this function from any thread.
  1986. *
  1987. * \since This function is available since SDL 3.0.0.
  1988. *
  1989. * \sa SDL_modf
  1990. * \sa SDL_truncf
  1991. * \sa SDL_fmodf
  1992. */
  1993. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  1994. /**
  1995. * Raise `x` to the power `y`
  1996. *
  1997. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1998. *
  1999. * Range: `-INF <= z <= INF`
  2000. *
  2001. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2002. * instead.
  2003. *
  2004. * This function operates on double-precision floating point values, use
  2005. * SDL_powf for single-precision floats.
  2006. *
  2007. * This function may use a different approximation across different versions,
  2008. * platforms and configurations. i.e, it can return a different value given
  2009. * the same input on different machines or operating systems, or if SDL is
  2010. * updated.
  2011. *
  2012. * \param x the base
  2013. * \param y the exponent
  2014. * \returns `x` raised to the power `y`
  2015. *
  2016. * \threadsafety It is safe to call this function from any thread.
  2017. *
  2018. * \since This function is available since SDL 3.0.0.
  2019. *
  2020. * \sa SDL_powf
  2021. * \sa SDL_exp
  2022. * \sa SDL_log
  2023. */
  2024. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  2025. /**
  2026. * Raise `x` to the power `y`
  2027. *
  2028. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2029. *
  2030. * Range: `-INF <= z <= INF`
  2031. *
  2032. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  2033. * instead.
  2034. *
  2035. * This function operates on single-precision floating point values, use
  2036. * SDL_powf for double-precision floats.
  2037. *
  2038. * This function may use a different approximation across different versions,
  2039. * platforms and configurations. i.e, it can return a different value given
  2040. * the same input on different machines or operating systems, or if SDL is
  2041. * updated.
  2042. *
  2043. * \param x the base
  2044. * \param y the exponent
  2045. * \returns `x` raised to the power `y`
  2046. *
  2047. * \threadsafety It is safe to call this function from any thread.
  2048. *
  2049. * \since This function is available since SDL 3.0.0.
  2050. *
  2051. * \sa SDL_pow
  2052. * \sa SDL_expf
  2053. * \sa SDL_logf
  2054. */
  2055. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  2056. /**
  2057. * Round `x` to the nearest integer.
  2058. *
  2059. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2060. * rounded away from zero.
  2061. *
  2062. * Domain: `-INF <= x <= INF`
  2063. *
  2064. * Range: `-INF <= y <= INF`, y integer
  2065. *
  2066. * This function operates on double-precision floating point values, use
  2067. * SDL_roundf for single-precision floats. To get the result as an integer
  2068. * type, use SDL_lround.
  2069. *
  2070. * \param x floating point value
  2071. * \returns the nearest integer to `x`
  2072. *
  2073. * \threadsafety It is safe to call this function from any thread.
  2074. *
  2075. * \since This function is available since SDL 3.0.0.
  2076. *
  2077. * \sa SDL_roundf
  2078. * \sa SDL_lround
  2079. * \sa SDL_floor
  2080. * \sa SDL_ceil
  2081. * \sa SDL_trunc
  2082. */
  2083. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  2084. /**
  2085. * Round `x` to the nearest integer.
  2086. *
  2087. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2088. * rounded away from zero.
  2089. *
  2090. * Domain: `-INF <= x <= INF`
  2091. *
  2092. * Range: `-INF <= y <= INF`, y integer
  2093. *
  2094. * This function operates on double-precision floating point values, use
  2095. * SDL_roundf for single-precision floats. To get the result as an integer
  2096. * type, use SDL_lroundf.
  2097. *
  2098. * \param x floating point value
  2099. * \returns the nearest integer to `x`
  2100. *
  2101. * \threadsafety It is safe to call this function from any thread.
  2102. *
  2103. * \since This function is available since SDL 3.0.0.
  2104. *
  2105. * \sa SDL_round
  2106. * \sa SDL_lroundf
  2107. * \sa SDL_floorf
  2108. * \sa SDL_ceilf
  2109. * \sa SDL_truncf
  2110. */
  2111. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  2112. /**
  2113. * Round `x` to the nearest integer representable as a long
  2114. *
  2115. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2116. * rounded away from zero.
  2117. *
  2118. * Domain: `-INF <= x <= INF`
  2119. *
  2120. * Range: `MIN_LONG <= y <= MAX_LONG`
  2121. *
  2122. * This function operates on double-precision floating point values, use
  2123. * SDL_lround for single-precision floats. To get the result as a
  2124. * floating-point type, use SDL_round.
  2125. *
  2126. * \param x floating point value
  2127. * \returns the nearest integer to `x`
  2128. *
  2129. * \threadsafety It is safe to call this function from any thread.
  2130. *
  2131. * \since This function is available since SDL 3.0.0.
  2132. *
  2133. * \sa SDL_lroundf
  2134. * \sa SDL_round
  2135. * \sa SDL_floor
  2136. * \sa SDL_ceil
  2137. * \sa SDL_trunc
  2138. */
  2139. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  2140. /**
  2141. * Round `x` to the nearest integer representable as a long
  2142. *
  2143. * Rounds `x` to the nearest integer. Values halfway between integers will be
  2144. * rounded away from zero.
  2145. *
  2146. * Domain: `-INF <= x <= INF`
  2147. *
  2148. * Range: `MIN_LONG <= y <= MAX_LONG`
  2149. *
  2150. * This function operates on single-precision floating point values, use
  2151. * SDL_lroundf for double-precision floats. To get the result as a
  2152. * floating-point type, use SDL_roundf,
  2153. *
  2154. * \param x floating point value
  2155. * \returns the nearest integer to `x`
  2156. *
  2157. * \threadsafety It is safe to call this function from any thread.
  2158. *
  2159. * \since This function is available since SDL 3.0.0.
  2160. *
  2161. * \sa SDL_lround
  2162. * \sa SDL_roundf
  2163. * \sa SDL_floorf
  2164. * \sa SDL_ceilf
  2165. * \sa SDL_truncf
  2166. */
  2167. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  2168. /**
  2169. * Scale `x` by an integer power of two.
  2170. *
  2171. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2172. *
  2173. * Domain: `-INF <= x <= INF`, `n` integer
  2174. *
  2175. * Range: `-INF <= y <= INF`
  2176. *
  2177. * This function operates on double-precision floating point values, use
  2178. * SDL_scalbnf for single-precision floats.
  2179. *
  2180. * \param x floating point value to be scaled
  2181. * \param n integer exponent
  2182. * \returns `x * 2^n`
  2183. *
  2184. * \threadsafety It is safe to call this function from any thread.
  2185. *
  2186. * \since This function is available since SDL 3.0.0.
  2187. *
  2188. * \sa SDL_scalbnf
  2189. * \sa SDL_pow
  2190. */
  2191. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  2192. /**
  2193. * Scale `x` by an integer power of two.
  2194. *
  2195. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2196. *
  2197. * Domain: `-INF <= x <= INF`, `n` integer
  2198. *
  2199. * Range: `-INF <= y <= INF`
  2200. *
  2201. * This function operates on single-precision floating point values, use
  2202. * SDL_scalbn for double-precision floats.
  2203. *
  2204. * \param x floating point value to be scaled
  2205. * \param n integer exponent
  2206. * \returns `x * 2^n`
  2207. *
  2208. * \threadsafety It is safe to call this function from any thread.
  2209. *
  2210. * \since This function is available since SDL 3.0.0.
  2211. *
  2212. * \sa SDL_scalbn
  2213. * \sa SDL_powf
  2214. */
  2215. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  2216. /**
  2217. * Compute the sine of `x`.
  2218. *
  2219. * Domain: `-INF <= x <= INF`
  2220. *
  2221. * Range: `-1 <= y <= 1`
  2222. *
  2223. * This function operates on double-precision floating point values, use
  2224. * SDL_sinf for single-precision floats.
  2225. *
  2226. * This function may use a different approximation across different versions,
  2227. * platforms and configurations. i.e, it can return a different value given
  2228. * the same input on different machines or operating systems, or if SDL is
  2229. * updated.
  2230. *
  2231. * \param x floating point value, in radians
  2232. * \returns sine of `x`
  2233. *
  2234. * \threadsafety It is safe to call this function from any thread.
  2235. *
  2236. * \since This function is available since SDL 3.0.0.
  2237. *
  2238. * \sa SDL_sinf
  2239. * \sa SDL_asin
  2240. * \sa SDL_cos
  2241. */
  2242. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  2243. /**
  2244. * Compute the sine of `x`.
  2245. *
  2246. * Domain: `-INF <= x <= INF`
  2247. *
  2248. * Range: `-1 <= y <= 1`
  2249. *
  2250. * This function operates on single-precision floating point values, use
  2251. * SDL_sinf for double-precision floats.
  2252. *
  2253. * This function may use a different approximation across different versions,
  2254. * platforms and configurations. i.e, it can return a different value given
  2255. * the same input on different machines or operating systems, or if SDL is
  2256. * updated.
  2257. *
  2258. * \param x floating point value, in radians
  2259. * \returns sine of `x`
  2260. *
  2261. * \threadsafety It is safe to call this function from any thread.
  2262. *
  2263. * \since This function is available since SDL 3.0.0.
  2264. *
  2265. * \sa SDL_sin
  2266. * \sa SDL_asinf
  2267. * \sa SDL_cosf
  2268. */
  2269. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  2270. /**
  2271. * Compute the square root of `x`.
  2272. *
  2273. * Domain: `0 <= x <= INF`
  2274. *
  2275. * Range: `0 <= y <= INF`
  2276. *
  2277. * This function operates on double-precision floating point values, use
  2278. * SDL_sqrtf for single-precision floats.
  2279. *
  2280. * This function may use a different approximation across different versions,
  2281. * platforms and configurations. i.e, it can return a different value given
  2282. * the same input on different machines or operating systems, or if SDL is
  2283. * updated.
  2284. *
  2285. * \param x floating point value. Must be greater than or equal to 0.
  2286. * \returns square root of `x`
  2287. *
  2288. * \threadsafety It is safe to call this function from any thread.
  2289. *
  2290. * \since This function is available since SDL 3.0.0.
  2291. *
  2292. * \sa SDL_sqrtf
  2293. */
  2294. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  2295. /**
  2296. * Compute the square root of `x`.
  2297. *
  2298. * Domain: `0 <= x <= INF`
  2299. *
  2300. * Range: `0 <= y <= INF`
  2301. *
  2302. * This function operates on single-precision floating point values, use
  2303. * SDL_sqrt for double-precision floats.
  2304. *
  2305. * This function may use a different approximation across different versions,
  2306. * platforms and configurations. i.e, it can return a different value given
  2307. * the same input on different machines or operating systems, or if SDL is
  2308. * updated.
  2309. *
  2310. * \param x floating point value. Must be greater than or equal to 0.
  2311. * \returns square root of `x`
  2312. *
  2313. * \threadsafety It is safe to call this function from any thread.
  2314. *
  2315. * \since This function is available since SDL 3.0.0.
  2316. *
  2317. * \sa SDL_sqrt
  2318. */
  2319. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  2320. /**
  2321. * Compute the tangent of `x`.
  2322. *
  2323. * Domain: `-INF <= x <= INF`
  2324. *
  2325. * Range: `-INF <= y <= INF`
  2326. *
  2327. * This function operates on double-precision floating point values, use
  2328. * SDL_tanf for single-precision floats.
  2329. *
  2330. * This function may use a different approximation across different versions,
  2331. * platforms and configurations. i.e, it can return a different value given
  2332. * the same input on different machines or operating systems, or if SDL is
  2333. * updated.
  2334. *
  2335. * \param x floating point value, in radians
  2336. * \returns tangent of `x`
  2337. *
  2338. * \threadsafety It is safe to call this function from any thread.
  2339. *
  2340. * \since This function is available since SDL 3.0.0.
  2341. *
  2342. * \sa SDL_tanf
  2343. * \sa SDL_sin
  2344. * \sa SDL_cos
  2345. * \sa SDL_atan
  2346. * \sa SDL_atan2
  2347. */
  2348. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  2349. /**
  2350. * Compute the tangent of `x`.
  2351. *
  2352. * Domain: `-INF <= x <= INF`
  2353. *
  2354. * Range: `-INF <= y <= INF`
  2355. *
  2356. * This function operates on single-precision floating point values, use
  2357. * SDL_tanf for double-precision floats.
  2358. *
  2359. * This function may use a different approximation across different versions,
  2360. * platforms and configurations. i.e, it can return a different value given
  2361. * the same input on different machines or operating systems, or if SDL is
  2362. * updated.
  2363. *
  2364. * \param x floating point value, in radians
  2365. * \returns tangent of `x`
  2366. *
  2367. * \threadsafety It is safe to call this function from any thread.
  2368. *
  2369. * \since This function is available since SDL 3.0.0.
  2370. *
  2371. * \sa SDL_tan
  2372. * \sa SDL_sinf
  2373. * \sa SDL_cosf
  2374. * \sa SDL_atanf
  2375. * \sa SDL_atan2f
  2376. */
  2377. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  2378. /* The SDL implementation of iconv() returns these error codes */
  2379. #define SDL_ICONV_ERROR (size_t)-1
  2380. #define SDL_ICONV_E2BIG (size_t)-2
  2381. #define SDL_ICONV_EILSEQ (size_t)-3
  2382. #define SDL_ICONV_EINVAL (size_t)-4
  2383. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  2384. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  2385. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  2386. const char *fromcode);
  2387. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  2388. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  2389. size_t * inbytesleft, char **outbuf,
  2390. size_t * outbytesleft);
  2391. /**
  2392. * Helper function to convert a string's encoding in one call.
  2393. *
  2394. * This function converts a buffer or string between encodings in one pass.
  2395. *
  2396. * The string does not need to be NULL-terminated; this function operates on
  2397. * the number of bytes specified in `inbytesleft` whether there is a NULL
  2398. * character anywhere in the buffer.
  2399. *
  2400. * The returned string is owned by the caller, and should be passed to
  2401. * SDL_free when no longer needed.
  2402. *
  2403. * \param tocode the character encoding of the output string. Examples are
  2404. * "UTF-8", "UCS-4", etc.
  2405. * \param fromcode the character encoding of data in `inbuf`.
  2406. * \param inbuf the string to convert to a different encoding.
  2407. * \param inbytesleft the size of the input string _in bytes_.
  2408. * \returns a new string, converted to the new encoding, or NULL on error.
  2409. *
  2410. * \since This function is available since SDL 3.0.0.
  2411. */
  2412. extern SDL_DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  2413. const char *fromcode,
  2414. const char *inbuf,
  2415. size_t inbytesleft);
  2416. /* Some helper macros for common cases... */
  2417. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  2418. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  2419. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  2420. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  2421. /* force builds using Clang's static analysis tools to use literal C runtime
  2422. here, since there are possibly tests that are ineffective otherwise. */
  2423. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  2424. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  2425. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  2426. size_t strlcpy(char* dst, const char* src, size_t size);
  2427. #endif
  2428. /* The analyzer knows about strlcat even when the system doesn't provide it */
  2429. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  2430. size_t strlcat(char* dst, const char* src, size_t size);
  2431. #endif
  2432. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  2433. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  2434. #endif
  2435. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  2436. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  2437. #endif
  2438. /* Starting LLVM 16, the analyser errors out if these functions do not have
  2439. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  2440. #include <stdlib.h>
  2441. #include <stdio.h>
  2442. #define SDL_malloc malloc
  2443. #define SDL_calloc calloc
  2444. #define SDL_realloc realloc
  2445. #define SDL_free free
  2446. #ifndef SDL_memcpy
  2447. #define SDL_memcpy memcpy
  2448. #endif
  2449. #ifndef SDL_memmove
  2450. #define SDL_memmove memmove
  2451. #endif
  2452. #ifndef SDL_memset
  2453. #define SDL_memset memset
  2454. #endif
  2455. #define SDL_memcmp memcmp
  2456. #define SDL_strlcpy strlcpy
  2457. #define SDL_strlcat strlcat
  2458. #define SDL_strlen strlen
  2459. #define SDL_wcslen wcslen
  2460. #define SDL_wcslcpy wcslcpy
  2461. #define SDL_wcslcat wcslcat
  2462. #define SDL_strdup strdup
  2463. #define SDL_wcsdup wcsdup
  2464. #define SDL_strchr strchr
  2465. #define SDL_strrchr strrchr
  2466. #define SDL_strstr strstr
  2467. #define SDL_wcsstr wcsstr
  2468. #define SDL_strtok_r strtok_r
  2469. #define SDL_strcmp strcmp
  2470. #define SDL_wcscmp wcscmp
  2471. #define SDL_strncmp strncmp
  2472. #define SDL_wcsncmp wcsncmp
  2473. #define SDL_strcasecmp strcasecmp
  2474. #define SDL_strncasecmp strncasecmp
  2475. #define SDL_sscanf sscanf
  2476. #define SDL_vsscanf vsscanf
  2477. #define SDL_snprintf snprintf
  2478. #define SDL_vsnprintf vsnprintf
  2479. #endif
  2480. /**
  2481. * Multiply two integers, checking for overflow.
  2482. *
  2483. * If `a * b` would overflow, return -1.
  2484. *
  2485. * Otherwise store `a * b` via ret and return 0.
  2486. *
  2487. * \param a the multiplicand
  2488. * \param b the multiplier
  2489. * \param ret on non-overflow output, stores the multiplication result. May
  2490. * not be NULL.
  2491. * \returns -1 on overflow, 0 if result doesn't overflow.
  2492. *
  2493. * \threadsafety It is safe to call this function from any thread.
  2494. *
  2495. * \since This function is available since SDL 3.0.0.
  2496. */
  2497. SDL_FORCE_INLINE int SDL_size_mul_overflow (size_t a,
  2498. size_t b,
  2499. size_t *ret)
  2500. {
  2501. if (a != 0 && b > SDL_SIZE_MAX / a) {
  2502. return -1;
  2503. }
  2504. *ret = a * b;
  2505. return 0;
  2506. }
  2507. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  2508. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  2509. /* This needs to be wrapped in an inline rather than being a direct #define,
  2510. * because __builtin_mul_overflow() is type-generic, but we want to be
  2511. * consistent about interpreting a and b as size_t. */
  2512. SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a,
  2513. size_t b,
  2514. size_t *ret)
  2515. {
  2516. return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1;
  2517. }
  2518. #define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret))
  2519. #endif
  2520. #endif
  2521. /**
  2522. * Add two integers, checking for overflow.
  2523. *
  2524. * If `a + b` would overflow, return -1.
  2525. *
  2526. * Otherwise store `a + b` via ret and return 0.
  2527. *
  2528. * \param a the first addend.
  2529. * \param b the second addend.
  2530. * \param ret on non-overflow output, stores the addition result. May not be
  2531. * NULL.
  2532. * \returns -1 on overflow, 0 if result doesn't overflow.
  2533. *
  2534. * \threadsafety It is safe to call this function from any thread.
  2535. *
  2536. * \since This function is available since SDL 3.0.0.
  2537. */
  2538. SDL_FORCE_INLINE int SDL_size_add_overflow (size_t a,
  2539. size_t b,
  2540. size_t *ret)
  2541. {
  2542. if (b > SDL_SIZE_MAX - a) {
  2543. return -1;
  2544. }
  2545. *ret = a + b;
  2546. return 0;
  2547. }
  2548. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  2549. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  2550. /* This needs to be wrapped in an inline rather than being a direct #define,
  2551. * the same as the call to __builtin_mul_overflow() above. */
  2552. SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
  2553. size_t b,
  2554. size_t *ret)
  2555. {
  2556. return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1;
  2557. }
  2558. #define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
  2559. #endif
  2560. #endif
  2561. /* This is a generic function pointer which should be cast to the type you expect */
  2562. #ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
  2563. typedef void *SDL_FunctionPointer;
  2564. #else
  2565. typedef void (*SDL_FunctionPointer)(void);
  2566. #endif
  2567. /* Ends C function definitions when using C++ */
  2568. #ifdef __cplusplus
  2569. }
  2570. #endif
  2571. #include <SDL3/SDL_close_code.h>
  2572. #endif /* SDL_stdinc_h_ */