SDL_stdinc.h 134 KB

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