SDL_stdinc.h 108 KB

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