SDL_stdinc.h 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryStdinc
  20. *
  21. * This is a general header that includes C language support. It implements a
  22. * subset of the C runtime 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()
  929. * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
  930. * SDL_UnsetEnvironmentVariable() if you want to modify this environment.
  931. *
  932. * \returns a pointer to the environment for the process or NULL on failure;
  933. * call SDL_GetError() for more information.
  934. *
  935. * \threadsafety It is safe to call this function from any thread.
  936. *
  937. * \since This function is available since SDL 3.0.0.
  938. *
  939. * \sa SDL_CleanupEnvironment
  940. * \sa SDL_GetEnvironmentVariable
  941. * \sa SDL_GetEnvironmentVariables
  942. * \sa SDL_SetEnvironmentVariable
  943. * \sa SDL_UnsetEnvironmentVariable
  944. */
  945. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
  946. /**
  947. * Cleanup the process environment.
  948. *
  949. * This is called during SDL_Quit() to free the process environment. If
  950. * SDL_GetEnvironment() is called afterwards, it will automatically create a
  951. * new environment copied from the C runtime environment.
  952. *
  953. * \threadsafety This function is not thread-safe.
  954. *
  955. * \since This function is available since SDL 3.0.0.
  956. *
  957. * \sa SDL_GetEnvironment
  958. */
  959. extern SDL_DECLSPEC void SDLCALL SDL_CleanupEnvironment(void);
  960. /**
  961. * Create a set of environment variables
  962. *
  963. * \param populated SDL_TRUE to initialize it from the C runtime environment,
  964. * SDL_FALSE to create an empty environment.
  965. * \returns a pointer to the new environment or NULL on failure; call
  966. * SDL_GetError() for more information.
  967. *
  968. * \threadsafety If `populated` is SDL_FALSE, it is safe to call this function
  969. * from any thread, otherwise it is safe if no other threads are
  970. * calling setenv() or unsetenv()
  971. *
  972. * \since This function is available since SDL 3.0.0.
  973. *
  974. * \sa SDL_GetEnvironmentVariable
  975. * \sa SDL_GetEnvironmentVariables
  976. * \sa SDL_SetEnvironmentVariable
  977. * \sa SDL_UnsetEnvironmentVariable
  978. * \sa SDL_DestroyEnvironment
  979. */
  980. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(SDL_bool populated);
  981. /**
  982. * Get the value of a variable in the environment.
  983. *
  984. * \param env the environment to query.
  985. * \param name the name of the variable to get.
  986. * \returns a pointer to the value of the variable or NULL if it can't be
  987. * found.
  988. *
  989. * \threadsafety It is safe to call this function from any thread.
  990. *
  991. * \since This function is available since SDL 3.0.0.
  992. *
  993. * \sa SDL_GetEnvironment
  994. * \sa SDL_CreateEnvironment
  995. * \sa SDL_GetEnvironmentVariables
  996. * \sa SDL_SetEnvironmentVariable
  997. * \sa SDL_UnsetEnvironmentVariable
  998. */
  999. extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
  1000. /**
  1001. * Get all variables in the environment.
  1002. *
  1003. * \param env the environment to query.
  1004. * \returns a NULL terminated array of pointers to environment variables in
  1005. * the form "variable=value" or NULL on failure; call SDL_GetError()
  1006. * for more information. This is a single allocation that should be
  1007. * freed with SDL_free() when it is no longer needed.
  1008. *
  1009. * \threadsafety It is safe to call this function from any thread.
  1010. *
  1011. * \since This function is available since SDL 3.0.0.
  1012. *
  1013. * \sa SDL_GetEnvironment
  1014. * \sa SDL_CreateEnvironment
  1015. * \sa SDL_GetEnvironmentVariables
  1016. * \sa SDL_SetEnvironmentVariable
  1017. * \sa SDL_UnsetEnvironmentVariable
  1018. */
  1019. extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
  1020. /**
  1021. * Set the value of a variable in the environment.
  1022. *
  1023. * \param env the environment to modify.
  1024. * \param name the name of the variable to set.
  1025. * \param value the value of the variable to set.
  1026. * \param overwrite SDL_TRUE to overwrite the variable if it exists, SDL_FALSE
  1027. * to return success without setting the variable if it
  1028. * already exists.
  1029. * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
  1030. * for more information.
  1031. *
  1032. * \threadsafety It is safe to call this function from any thread.
  1033. *
  1034. * \since This function is available since SDL 3.0.0.
  1035. *
  1036. * \sa SDL_GetEnvironment
  1037. * \sa SDL_CreateEnvironment
  1038. * \sa SDL_GetEnvironmentVariable
  1039. * \sa SDL_GetEnvironmentVariables
  1040. * \sa SDL_UnsetEnvironmentVariable
  1041. */
  1042. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, SDL_bool overwrite);
  1043. /**
  1044. * Clear a variable from the environment.
  1045. *
  1046. * \param env the environment to modify.
  1047. * \param name the name of the variable to unset.
  1048. * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
  1049. * for more information.
  1050. *
  1051. * \threadsafety It is safe to call this function from any thread.
  1052. *
  1053. * \since This function is available since SDL 3.0.0.
  1054. *
  1055. * \sa SDL_GetEnvironment
  1056. * \sa SDL_CreateEnvironment
  1057. * \sa SDL_GetEnvironmentVariable
  1058. * \sa SDL_GetEnvironmentVariables
  1059. * \sa SDL_SetEnvironmentVariable
  1060. * \sa SDL_UnsetEnvironmentVariable
  1061. */
  1062. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
  1063. /**
  1064. * Destroy a set of environment variables.
  1065. *
  1066. * \param env the environment to destroy.
  1067. *
  1068. * \threadsafety It is safe to call this function from any thread, as long as
  1069. * the environment is no longer in use.
  1070. *
  1071. * \since This function is available since SDL 3.0.0.
  1072. *
  1073. * \sa SDL_CreateEnvironment
  1074. */
  1075. extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
  1076. /**
  1077. * Get the value of a variable in the environment.
  1078. *
  1079. * This function uses SDL's cached copy of the environment and is thread-safe.
  1080. *
  1081. * \param name the name of the variable to get.
  1082. * \returns a pointer to the value of the variable or NULL if it can't be
  1083. * found.
  1084. *
  1085. * \threadsafety It is safe to call this function from any thread.
  1086. *
  1087. * \since This function is available since SDL 3.0.0.
  1088. */
  1089. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
  1090. /**
  1091. * Get the value of a variable in the environment.
  1092. *
  1093. * This function bypasses SDL's cached copy of the environment and is not thread-safe.
  1094. *
  1095. * \param name the name of the variable to get.
  1096. * \returns a pointer to the value of the variable or NULL if it can't be
  1097. * found.
  1098. *
  1099. * \threadsafety This function is not thread safe, consider using
  1100. * SDL_getenv() instead.
  1101. *
  1102. * \since This function is available since SDL 3.0.0.
  1103. *
  1104. * \sa SDL_getenv
  1105. */
  1106. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
  1107. /**
  1108. * Set the value of a variable in the environment.
  1109. *
  1110. * \param name the name of the variable to set.
  1111. * \param value the value of the variable to set.
  1112. * \param overwrite 1 to overwrite the variable if it exists, 0 to return
  1113. * success without setting the variable if it already exists.
  1114. * \returns 0 on success, -1 on error.
  1115. *
  1116. * \threadsafety This function is not thread safe, consider using
  1117. * SDL_SetEnvironmentVariable() instead.
  1118. *
  1119. * \since This function is available since SDL 3.0.0.
  1120. *
  1121. * \sa SDL_SetEnvironmentVariable
  1122. */
  1123. extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
  1124. /**
  1125. * Clear a variable from the environment.
  1126. *
  1127. * \param name the name of the variable to unset.
  1128. * \returns 0 on success, -1 on error.
  1129. *
  1130. * \threadsafety This function is not thread safe, consider using
  1131. * SDL_UnsetEnvironmentVariable() instead.
  1132. *
  1133. * \since This function is available since SDL 3.0.0.
  1134. *
  1135. * \sa SDL_UnsetEnvironmentVariable
  1136. */
  1137. extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
  1138. typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
  1139. extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1140. extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1141. typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
  1142. extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
  1143. 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);
  1144. extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
  1145. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  1146. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  1147. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  1148. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  1149. /**
  1150. * Query if a character is alphabetic (a letter).
  1151. *
  1152. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1153. * for English 'a-z' and 'A-Z' as true.
  1154. *
  1155. * \param x character value to check.
  1156. * \returns non-zero if x falls within the character class, zero otherwise.
  1157. *
  1158. * \threadsafety It is safe to call this function from any thread.
  1159. *
  1160. * \since This function is available since SDL 3.0.0.
  1161. */
  1162. extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
  1163. /**
  1164. * Query if a character is alphabetic (a letter) or a number.
  1165. *
  1166. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1167. * for English 'a-z', 'A-Z', and '0-9' as true.
  1168. *
  1169. * \param x character value to check.
  1170. * \returns non-zero if x falls within the character class, zero otherwise.
  1171. *
  1172. * \threadsafety It is safe to call this function from any thread.
  1173. *
  1174. * \since This function is available since SDL 3.0.0.
  1175. */
  1176. extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
  1177. /**
  1178. * Report if a character is blank (a space or tab).
  1179. *
  1180. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1181. * 0x20 (space) or 0x9 (tab) as true.
  1182. *
  1183. * \param x character value to check.
  1184. * \returns non-zero if x falls within the character class, zero otherwise.
  1185. *
  1186. * \threadsafety It is safe to call this function from any thread.
  1187. *
  1188. * \since This function is available since SDL 3.0.0.
  1189. */
  1190. extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
  1191. /**
  1192. * Report if a character is a control character.
  1193. *
  1194. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1195. * 0 through 0x1F, and 0x7F, as true.
  1196. *
  1197. * \param x character value to check.
  1198. * \returns non-zero if x falls within the character class, zero otherwise.
  1199. *
  1200. * \threadsafety It is safe to call this function from any thread.
  1201. *
  1202. * \since This function is available since SDL 3.0.0.
  1203. */
  1204. extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
  1205. /**
  1206. * Report if a character is a numeric digit.
  1207. *
  1208. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1209. * '0' (0x30) through '9' (0x39), as true.
  1210. *
  1211. * \param x character value to check.
  1212. * \returns non-zero if x falls within the character class, zero otherwise.
  1213. *
  1214. * \threadsafety It is safe to call this function from any thread.
  1215. *
  1216. * \since This function is available since SDL 3.0.0.
  1217. */
  1218. extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
  1219. /**
  1220. * Report if a character is a hexadecimal digit.
  1221. *
  1222. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1223. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  1224. *
  1225. * \param x character value to check.
  1226. * \returns non-zero if x falls within the character class, zero otherwise.
  1227. *
  1228. * \threadsafety It is safe to call this function from any thread.
  1229. *
  1230. * \since This function is available since SDL 3.0.0.
  1231. */
  1232. extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
  1233. /**
  1234. * Report if a character is a punctuation mark.
  1235. *
  1236. * **WARNING**: Regardless of system locale, this is equivalent to
  1237. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  1238. *
  1239. * \param x character value to check.
  1240. * \returns non-zero if x falls within the character class, zero otherwise.
  1241. *
  1242. * \threadsafety It is safe to call this function from any thread.
  1243. *
  1244. * \since This function is available since SDL 3.0.0.
  1245. *
  1246. * \sa SDL_isgraph
  1247. * \sa SDL_isalnum
  1248. */
  1249. extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
  1250. /**
  1251. * Report if a character is whitespace.
  1252. *
  1253. * **WARNING**: Regardless of system locale, this will only treat the
  1254. * following ASCII values as true:
  1255. *
  1256. * - space (0x20)
  1257. * - tab (0x09)
  1258. * - newline (0x0A)
  1259. * - vertical tab (0x0B)
  1260. * - form feed (0x0C)
  1261. * - return (0x0D)
  1262. *
  1263. * \param x character value to check.
  1264. * \returns non-zero if x falls within the character class, zero otherwise.
  1265. *
  1266. * \threadsafety It is safe to call this function from any thread.
  1267. *
  1268. * \since This function is available since SDL 3.0.0.
  1269. */
  1270. extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
  1271. /**
  1272. * Report if a character is upper case.
  1273. *
  1274. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1275. * 'A' through 'Z' 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_isupper(int x);
  1285. /**
  1286. * Report if a character is lower case.
  1287. *
  1288. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1289. * 'a' through 'z' as true.
  1290. *
  1291. * \param x character value to check.
  1292. * \returns non-zero if x falls within the character class, zero otherwise.
  1293. *
  1294. * \threadsafety It is safe to call this function from any thread.
  1295. *
  1296. * \since This function is available since SDL 3.0.0.
  1297. */
  1298. extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
  1299. /**
  1300. * Report if a character is "printable".
  1301. *
  1302. * Be advised that "printable" has a definition that goes back to text
  1303. * terminals from the dawn of computing, making this a sort of special case
  1304. * function that is not suitable for Unicode (or most any) text management.
  1305. *
  1306. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1307. * ' ' (0x20) through '~' (0x7E) as true.
  1308. *
  1309. * \param x character value to check.
  1310. * \returns non-zero if x falls within the character class, zero otherwise.
  1311. *
  1312. * \threadsafety It is safe to call this function from any thread.
  1313. *
  1314. * \since This function is available since SDL 3.0.0.
  1315. */
  1316. extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
  1317. /**
  1318. * Report if a character is any "printable" except space.
  1319. *
  1320. * Be advised that "printable" has a definition that goes back to text
  1321. * terminals from the dawn of computing, making this a sort of special case
  1322. * function that is not suitable for Unicode (or most any) text management.
  1323. *
  1324. * **WARNING**: Regardless of system locale, this is equivalent to
  1325. * `(SDL_isprint(x)) && ((x) != ' ')`.
  1326. *
  1327. * \param x character value to check.
  1328. * \returns non-zero if x falls within the character class, zero otherwise.
  1329. *
  1330. * \threadsafety It is safe to call this function from any thread.
  1331. *
  1332. * \since This function is available since SDL 3.0.0.
  1333. *
  1334. * \sa SDL_isprint
  1335. */
  1336. extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
  1337. /**
  1338. * Convert low-ASCII English letters to uppercase.
  1339. *
  1340. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1341. * values 'a' through 'z' to uppercase.
  1342. *
  1343. * This function returns the uppercase equivalent of `x`. If a character
  1344. * cannot be converted, or is already uppercase, this function returns `x`.
  1345. *
  1346. * \param x character value to check.
  1347. * \returns capitalized version of x, or x if no conversion available.
  1348. *
  1349. * \threadsafety It is safe to call this function from any thread.
  1350. *
  1351. * \since This function is available since SDL 3.0.0.
  1352. */
  1353. extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
  1354. /**
  1355. * Convert low-ASCII English letters to lowercase.
  1356. *
  1357. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1358. * values 'A' through 'Z' to lowercase.
  1359. *
  1360. * This function returns the lowercase equivalent of `x`. If a character
  1361. * cannot be converted, or is already lowercase, this function returns `x`.
  1362. *
  1363. * \param x character value to check.
  1364. * \returns lowercase version of x, or x if no conversion available.
  1365. *
  1366. * \threadsafety It is safe to call this function from any thread.
  1367. *
  1368. * \since This function is available since SDL 3.0.0.
  1369. */
  1370. extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
  1371. extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  1372. extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  1373. /**
  1374. * Copy non-overlapping memory.
  1375. *
  1376. * The memory regions must not overlap. If they do, use SDL_memmove() instead.
  1377. *
  1378. * \param dst The destination memory region. Must not be NULL, and must not
  1379. * overlap with `src`.
  1380. * \param src The source memory region. Must not be NULL, and must not overlap
  1381. * with `dst`.
  1382. * \param len The length in bytes of both `dst` and `src`.
  1383. * \returns `dst`.
  1384. *
  1385. * \threadsafety It is safe to call this function from any thread.
  1386. *
  1387. * \since This function is available since SDL 3.0.0.
  1388. *
  1389. * \sa SDL_memmove
  1390. */
  1391. extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  1392. /* Take advantage of compiler optimizations for memcpy */
  1393. #ifndef SDL_SLOW_MEMCPY
  1394. #ifdef SDL_memcpy
  1395. #undef SDL_memcpy
  1396. #endif
  1397. #define SDL_memcpy memcpy
  1398. #endif
  1399. #define SDL_copyp(dst, src) \
  1400. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  1401. SDL_memcpy((dst), (src), sizeof(*(src)))
  1402. /**
  1403. * Copy memory.
  1404. *
  1405. * It is okay for the memory regions to overlap. If you are confident that the
  1406. * regions never overlap, using SDL_memcpy() may improve performance.
  1407. *
  1408. * \param dst The destination memory region. Must not be NULL.
  1409. * \param src The source memory region. Must not be NULL.
  1410. * \param len The length in bytes of both `dst` and `src`.
  1411. * \returns `dst`.
  1412. *
  1413. * \threadsafety It is safe to call this function from any thread.
  1414. *
  1415. * \since This function is available since SDL 3.0.0.
  1416. *
  1417. * \sa SDL_memcpy
  1418. */
  1419. extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  1420. /* Take advantage of compiler optimizations for memmove */
  1421. #ifndef SDL_SLOW_MEMMOVE
  1422. #ifdef SDL_memmove
  1423. #undef SDL_memmove
  1424. #endif
  1425. #define SDL_memmove memmove
  1426. #endif
  1427. extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  1428. extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  1429. /* Take advantage of compiler optimizations for memset */
  1430. #ifndef SDL_SLOW_MEMSET
  1431. #ifdef SDL_memset
  1432. #undef SDL_memset
  1433. #endif
  1434. #define SDL_memset memset
  1435. #endif
  1436. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  1437. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  1438. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  1439. extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  1440. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  1441. extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  1442. /**
  1443. * Copy a wide string.
  1444. *
  1445. * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
  1446. * appends a null terminator.
  1447. *
  1448. * `src` and `dst` must not overlap.
  1449. *
  1450. * If `maxlen` is 0, no wide characters are copied and no null terminator is
  1451. * written.
  1452. *
  1453. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1454. * with `src`.
  1455. * \param src The null-terminated wide string to copy. Must not be NULL, and
  1456. * must not overlap with `dst`.
  1457. * \param maxlen The length (in wide characters) of the destination buffer.
  1458. * \returns The length (in wide characters, excluding the null terminator) of
  1459. * `src`.
  1460. *
  1461. * \threadsafety It is safe to call this function from any thread.
  1462. *
  1463. * \since This function is available since SDL 3.0.0.
  1464. *
  1465. * \sa SDL_wcslcat
  1466. */
  1467. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1468. /**
  1469. * Concatenate wide strings.
  1470. *
  1471. * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
  1472. * from `src` to the end of the wide string in `dst`, then appends a null
  1473. * terminator.
  1474. *
  1475. * `src` and `dst` must not overlap.
  1476. *
  1477. * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
  1478. * unmodified.
  1479. *
  1480. * \param dst The destination buffer already containing the first
  1481. * null-terminated wide string. Must not be NULL and must not
  1482. * overlap with `src`.
  1483. * \param src The second null-terminated wide string. Must not be NULL, and
  1484. * must not overlap with `dst`.
  1485. * \param maxlen The length (in wide characters) of the destination buffer.
  1486. * \returns The length (in wide characters, excluding the null terminator) of
  1487. * the string in `dst` plus the length of `src`.
  1488. *
  1489. * \threadsafety It is safe to call this function from any thread.
  1490. *
  1491. * \since This function is available since SDL 3.0.0.
  1492. *
  1493. * \sa SDL_wcslcpy
  1494. */
  1495. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1496. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
  1497. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  1498. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  1499. /**
  1500. * Compare two null-terminated wide strings.
  1501. *
  1502. * This only compares wchar_t values until it hits a null-terminating
  1503. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  1504. * depending on your platform's wchar_t size), or uses valid Unicode values.
  1505. *
  1506. * \param str1 the first string to compare. NULL is not permitted!
  1507. * \param str2 the second string to compare. NULL is not permitted!
  1508. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1509. * str1 is "greater than" str2, and zero if the strings match
  1510. * exactly.
  1511. *
  1512. * \threadsafety It is safe to call this function from any thread.
  1513. *
  1514. * \since This function is available since SDL 3.0.0.
  1515. */
  1516. extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  1517. /**
  1518. * Compare two wide strings up to a number of wchar_t values.
  1519. *
  1520. * This only compares wchar_t values; it does not care if the string is
  1521. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  1522. * or uses valid Unicode values.
  1523. *
  1524. * Note that while this function is intended to be used with UTF-16 (or
  1525. * UTF-32, depending on your platform's definition of wchar_t), it is
  1526. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  1527. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  1528. * sequence, it will only compare a portion of the final character.
  1529. *
  1530. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  1531. * match to this number of wide chars (or both have matched to a
  1532. * null-terminator character before this count), they will be considered
  1533. * equal.
  1534. *
  1535. * \param str1 the first string to compare. NULL is not permitted!
  1536. * \param str2 the second string to compare. NULL is not permitted!
  1537. * \param maxlen the maximum number of wchar_t to compare.
  1538. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1539. * str1 is "greater than" str2, and zero if the strings match
  1540. * exactly.
  1541. *
  1542. * \threadsafety It is safe to call this function from any thread.
  1543. *
  1544. * \since This function is available since SDL 3.0.0.
  1545. */
  1546. extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1547. /**
  1548. * Compare two null-terminated wide strings, case-insensitively.
  1549. *
  1550. * This will work with Unicode strings, using a technique called
  1551. * "case-folding" to handle the vast majority of case-sensitive human
  1552. * languages regardless of system locale. It can deal with expanding values: a
  1553. * German Eszett character can compare against two ASCII 's' chars and be
  1554. * considered a match, for example. A notable exception: it does not handle
  1555. * the Turkish 'i' character; human language is complicated!
  1556. *
  1557. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1558. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1559. * handles Unicode, it expects the string to be well-formed and not a
  1560. * null-terminated string of arbitrary bytes. Characters that are not valid
  1561. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1562. * CHARACTER), which is to say two strings of random bits may turn out to
  1563. * match if they convert to the same amount of replacement characters.
  1564. *
  1565. * \param str1 the first string to compare. NULL is not permitted!
  1566. * \param str2 the second string to compare. NULL is not permitted!
  1567. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1568. * str1 is "greater than" str2, and zero if the strings match
  1569. * exactly.
  1570. *
  1571. * \threadsafety It is safe to call this function from any thread.
  1572. *
  1573. * \since This function is available since SDL 3.0.0.
  1574. */
  1575. extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  1576. /**
  1577. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  1578. *
  1579. * This will work with Unicode strings, using a technique called
  1580. * "case-folding" to handle the vast majority of case-sensitive human
  1581. * languages regardless of system locale. It can deal with expanding values: a
  1582. * German Eszett character can compare against two ASCII 's' chars and be
  1583. * considered a match, for example. A notable exception: it does not handle
  1584. * the Turkish 'i' character; human language is complicated!
  1585. *
  1586. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1587. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1588. * handles Unicode, it expects the string to be well-formed and not a
  1589. * null-terminated string of arbitrary bytes. Characters that are not valid
  1590. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1591. * CHARACTER), which is to say two strings of random bits may turn out to
  1592. * match if they convert to the same amount of replacement characters.
  1593. *
  1594. * Note that while this function might deal with variable-sized characters,
  1595. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  1596. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  1597. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  1598. * to overflow a buffer.
  1599. *
  1600. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  1601. * strings match to this number of wchar_t (or both have matched to a
  1602. * null-terminator character before this number of bytes), they will be
  1603. * considered equal.
  1604. *
  1605. * \param str1 the first string to compare. NULL is not permitted!
  1606. * \param str2 the second string to compare. NULL is not permitted!
  1607. * \param maxlen the maximum number of wchar_t values to compare.
  1608. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1609. * str1 is "greater than" str2, and zero if the strings match
  1610. * exactly.
  1611. *
  1612. * \threadsafety It is safe to call this function from any thread.
  1613. *
  1614. * \since This function is available since SDL 3.0.0.
  1615. */
  1616. extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1617. /**
  1618. * Parse a `long` from a wide string.
  1619. *
  1620. * If `str` starts with whitespace, then those whitespace characters are
  1621. * skipped before attempting to parse the number.
  1622. *
  1623. * If the parsed number does not fit inside a `long`, the result is clamped to
  1624. * the minimum and maximum representable `long` values.
  1625. *
  1626. * \param str The null-terminated wide string to read. Must not be NULL.
  1627. * \param endp If not NULL, the address of the first invalid wide character
  1628. * (i.e. the next character after the parsed number) will be
  1629. * written to this pointer.
  1630. * \param base The base of the integer to read. Supported values are 0 and 2
  1631. * to 36 inclusive. If 0, the base will be inferred from the
  1632. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1633. * otherwise).
  1634. * \returns The parsed `long`, or 0 if no number could be parsed.
  1635. *
  1636. * \threadsafety It is safe to call this function from any thread.
  1637. *
  1638. * \since This function is available since SDL 3.0.0.
  1639. *
  1640. * \sa SDL_strtol
  1641. */
  1642. extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  1643. extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  1644. extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  1645. /**
  1646. * Copy a string.
  1647. *
  1648. * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
  1649. * then appends a null terminator.
  1650. *
  1651. * If `maxlen` is 0, no characters are copied and no null terminator is
  1652. * written.
  1653. *
  1654. * If you want to copy an UTF-8 string but need to ensure that multi-byte
  1655. * sequences are not truncated, consider using SDL_utf8strlcpy().
  1656. *
  1657. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1658. * with `src`.
  1659. * \param src The null-terminated string to copy. Must not be NULL, and must
  1660. * not overlap with `dst`.
  1661. * \param maxlen The length (in characters) of the destination buffer.
  1662. * \returns The length (in characters, excluding the null terminator) of
  1663. * `src`.
  1664. *
  1665. * \threadsafety It is safe to call this function from any thread.
  1666. *
  1667. * \since This function is available since SDL 3.0.0.
  1668. *
  1669. * \sa SDL_strlcat
  1670. * \sa SDL_utf8strlcpy
  1671. */
  1672. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1673. /**
  1674. * Copy an UTF-8 string.
  1675. *
  1676. * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
  1677. * also ensuring that the string written to `dst` does not end in a truncated
  1678. * multi-byte sequence. Finally, it appends a null terminator.
  1679. *
  1680. * `src` and `dst` must not overlap.
  1681. *
  1682. * Note that unlike SDL_strlcpy(), this function returns the number of bytes
  1683. * written, not the length of `src`.
  1684. *
  1685. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1686. * with `src`.
  1687. * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
  1688. * must not overlap with `dst`.
  1689. * \param dst_bytes The length (in bytes) of the destination buffer. Must not
  1690. * be 0.
  1691. * \returns The number of bytes written, excluding the null terminator.
  1692. *
  1693. * \threadsafety It is safe to call this function from any thread.
  1694. *
  1695. * \since This function is available since SDL 3.0.0.
  1696. *
  1697. * \sa SDL_strlcpy
  1698. */
  1699. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  1700. /**
  1701. * Concatenate strings.
  1702. *
  1703. * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
  1704. * `src` to the end of the string in `dst`, then appends a null terminator.
  1705. *
  1706. * `src` and `dst` must not overlap.
  1707. *
  1708. * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
  1709. * unmodified.
  1710. *
  1711. * \param dst The destination buffer already containing the first
  1712. * null-terminated string. Must not be NULL and must not overlap
  1713. * with `src`.
  1714. * \param src The second null-terminated string. Must not be NULL, and must
  1715. * not overlap with `dst`.
  1716. * \param maxlen The length (in characters) of the destination buffer.
  1717. * \returns The length (in characters, excluding the null terminator) of the
  1718. * string in `dst` plus the length of `src`.
  1719. *
  1720. * \threadsafety It is safe to call this function from any thread.
  1721. *
  1722. * \since This function is available since SDL 3.0.0.
  1723. *
  1724. * \sa SDL_strlcpy
  1725. */
  1726. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1727. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
  1728. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
  1729. extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
  1730. /**
  1731. * Convert a string to uppercase.
  1732. *
  1733. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1734. * values 'A' through 'Z' to uppercase.
  1735. *
  1736. * This function operates on a null-terminated string of bytes--even if it is
  1737. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  1738. * uppercase equivalents in-place, returning the original `str` pointer.
  1739. *
  1740. * \param str the string to convert in-place. Can not be NULL.
  1741. * \returns the `str` pointer passed into this function.
  1742. *
  1743. * \threadsafety It is safe to call this function from any thread.
  1744. *
  1745. * \since This function is available since SDL 3.0.0.
  1746. *
  1747. * \sa SDL_strlwr
  1748. */
  1749. extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
  1750. /**
  1751. * Convert a string to lowercase.
  1752. *
  1753. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1754. * values 'A' through 'Z' to lowercase.
  1755. *
  1756. * This function operates on a null-terminated string of bytes--even if it is
  1757. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  1758. * lowercase equivalents in-place, returning the original `str` pointer.
  1759. *
  1760. * \param str the string to convert in-place. Can not be NULL.
  1761. * \returns the `str` pointer passed into this function.
  1762. *
  1763. * \threadsafety It is safe to call this function from any thread.
  1764. *
  1765. * \since This function is available since SDL 3.0.0.
  1766. *
  1767. * \sa SDL_strupr
  1768. */
  1769. extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
  1770. extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
  1771. extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
  1772. extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
  1773. extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  1774. extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  1775. extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
  1776. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  1777. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  1778. extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
  1779. extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  1780. extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
  1781. extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  1782. extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
  1783. extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
  1784. /**
  1785. * Parse an `int` from a string.
  1786. *
  1787. * The result of calling `SDL_atoi(str)` is equivalent to
  1788. * `(int)SDL_strtol(str, NULL, 10)`.
  1789. *
  1790. * \param str The null-terminated string to read. Must not be NULL.
  1791. * \returns The parsed `int`.
  1792. *
  1793. * \threadsafety It is safe to call this function from any thread.
  1794. *
  1795. * \since This function is available since SDL 3.0.0.
  1796. *
  1797. * \sa SDL_atof
  1798. * \sa SDL_strtol
  1799. * \sa SDL_strtoul
  1800. * \sa SDL_strtoll
  1801. * \sa SDL_strtoull
  1802. * \sa SDL_strtod
  1803. * \sa SDL_itoa
  1804. */
  1805. extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
  1806. /**
  1807. * Parse a `double` from a string.
  1808. *
  1809. * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
  1810. * NULL)`.
  1811. *
  1812. * \param str The null-terminated string to read. Must not be NULL.
  1813. * \returns The parsed `double`.
  1814. *
  1815. * \threadsafety It is safe to call this function from any thread.
  1816. *
  1817. * \since This function is available since SDL 3.0.0.
  1818. *
  1819. * \sa SDL_atoi
  1820. * \sa SDL_strtol
  1821. * \sa SDL_strtoul
  1822. * \sa SDL_strtoll
  1823. * \sa SDL_strtoull
  1824. * \sa SDL_strtod
  1825. */
  1826. extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
  1827. /**
  1828. * Parse a `long` from a string.
  1829. *
  1830. * If `str` starts with whitespace, then those whitespace characters are
  1831. * skipped before attempting to parse the number.
  1832. *
  1833. * If the parsed number does not fit inside a `long`, the result is clamped to
  1834. * the minimum and maximum representable `long` values.
  1835. *
  1836. * \param str The null-terminated string to read. Must not be NULL.
  1837. * \param endp If not NULL, the address of the first invalid character (i.e.
  1838. * the next character after the parsed number) will be written to
  1839. * this pointer.
  1840. * \param base The base of the integer to read. Supported values are 0 and 2
  1841. * to 36 inclusive. If 0, the base will be inferred from the
  1842. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1843. * otherwise).
  1844. * \returns The parsed `long`, or 0 if no number could be parsed.
  1845. *
  1846. * \threadsafety It is safe to call this function from any thread.
  1847. *
  1848. * \since This function is available since SDL 3.0.0.
  1849. *
  1850. * \sa SDL_atoi
  1851. * \sa SDL_atof
  1852. * \sa SDL_strtoul
  1853. * \sa SDL_strtoll
  1854. * \sa SDL_strtoull
  1855. * \sa SDL_strtod
  1856. * \sa SDL_ltoa
  1857. * \sa SDL_wcstol
  1858. */
  1859. extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  1860. /**
  1861. * Parse an `unsigned 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 an `unsigned long`, the result is
  1867. * clamped to the maximum representable `unsigned long` value.
  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 `unsigned 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_strtoll
  1887. * \sa SDL_strtoull
  1888. * \sa SDL_strtod
  1889. * \sa SDL_ultoa
  1890. */
  1891. extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  1892. /**
  1893. * Parse a `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 a `long long`, the result is
  1899. * clamped to the minimum and maximum representable `long long` values.
  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 `long long`, or 0 if no number could be parsed.
  1910. *
  1911. * \threadsafety It is safe to call this function from any thread.
  1912. *
  1913. * \since This function is available since SDL 3.0.0.
  1914. *
  1915. * \sa SDL_atoi
  1916. * \sa SDL_atof
  1917. * \sa SDL_strtol
  1918. * \sa SDL_strtoul
  1919. * \sa SDL_strtoull
  1920. * \sa SDL_strtod
  1921. * \sa SDL_lltoa
  1922. */
  1923. extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  1924. /**
  1925. * Parse an `unsigned long long` from a string.
  1926. *
  1927. * If `str` starts with whitespace, then those whitespace characters are
  1928. * skipped before attempting to parse the number.
  1929. *
  1930. * If the parsed number does not fit inside an `unsigned long long`, the
  1931. * result is clamped to the maximum representable `unsigned long long` value.
  1932. *
  1933. * \param str The null-terminated string to read. Must not be NULL.
  1934. * \param endp If not NULL, the address of the first invalid character (i.e.
  1935. * the next character after the parsed number) will be written to
  1936. * this pointer.
  1937. * \param base The base of the integer to read. Supported values are 0 and 2
  1938. * to 36 inclusive. If 0, the base will be inferred from the
  1939. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1940. * otherwise).
  1941. * \returns The parsed `unsigned long long`, or 0 if no number could be
  1942. * parsed.
  1943. *
  1944. * \threadsafety It is safe to call this function from any thread.
  1945. *
  1946. * \since This function is available since SDL 3.0.0.
  1947. *
  1948. * \sa SDL_atoi
  1949. * \sa SDL_atof
  1950. * \sa SDL_strtol
  1951. * \sa SDL_strtoll
  1952. * \sa SDL_strtoul
  1953. * \sa SDL_strtod
  1954. * \sa SDL_ulltoa
  1955. */
  1956. extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  1957. /**
  1958. * Parse a `double` from a string.
  1959. *
  1960. * This function makes fewer guarantees than the C runtime `strtod`:
  1961. *
  1962. * - Only decimal notation is guaranteed to be supported. The handling of
  1963. * scientific and hexadecimal notation is unspecified.
  1964. * - Whether or not INF and NAN can be parsed is unspecified.
  1965. * - The precision of the result is unspecified.
  1966. *
  1967. * \param str The null-terminated string to read. Must not be NULL.
  1968. * \param endp If not NULL, the address of the first invalid character (i.e.
  1969. * the next character after the parsed number) will be written to
  1970. * this pointer.
  1971. * \returns The parsed `double`, or 0 if no number could be parsed.
  1972. *
  1973. * \threadsafety It is safe to call this function from any thread.
  1974. *
  1975. * \since This function is available since SDL 3.0.0.
  1976. *
  1977. * \sa SDL_atoi
  1978. * \sa SDL_atof
  1979. * \sa SDL_strtol
  1980. * \sa SDL_strtoll
  1981. * \sa SDL_strtoul
  1982. * \sa SDL_strtoull
  1983. */
  1984. extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  1985. /**
  1986. * Compare two null-terminated UTF-8 strings.
  1987. *
  1988. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  1989. * since effectively this function just compares bytes until it hits a
  1990. * null-terminating character. Also due to the nature of UTF-8, this can be
  1991. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  1992. *
  1993. * \param str1 the first string to compare. NULL is not permitted!
  1994. * \param str2 the second string to compare. NULL is not permitted!
  1995. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1996. * str1 is "greater than" str2, and zero if the strings match
  1997. * exactly.
  1998. *
  1999. * \threadsafety It is safe to call this function from any thread.
  2000. *
  2001. * \since This function is available since SDL 3.0.0.
  2002. */
  2003. extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  2004. /**
  2005. * Compare two UTF-8 strings up to a number of bytes.
  2006. *
  2007. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  2008. * since effectively this function just compares bytes until it hits a
  2009. * null-terminating character. Also due to the nature of UTF-8, this can be
  2010. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  2011. *
  2012. * Note that while this function is intended to be used with UTF-8, it is
  2013. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  2014. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  2015. * compare a portion of the final character.
  2016. *
  2017. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  2018. * match to this number of bytes (or both have matched to a null-terminator
  2019. * character before this number of bytes), they will be considered equal.
  2020. *
  2021. * \param str1 the first string to compare. NULL is not permitted!
  2022. * \param str2 the second string to compare. NULL is not permitted!
  2023. * \param maxlen the maximum number of _bytes_ to compare.
  2024. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2025. * str1 is "greater than" str2, and zero if the strings match
  2026. * exactly.
  2027. *
  2028. * \threadsafety It is safe to call this function from any thread.
  2029. *
  2030. * \since This function is available since SDL 3.0.0.
  2031. */
  2032. extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  2033. /**
  2034. * Compare two null-terminated UTF-8 strings, case-insensitively.
  2035. *
  2036. * This will work with Unicode strings, using a technique called
  2037. * "case-folding" to handle the vast majority of case-sensitive human
  2038. * languages regardless of system locale. It can deal with expanding values: a
  2039. * German Eszett character can compare against two ASCII 's' chars and be
  2040. * considered a match, for example. A notable exception: it does not handle
  2041. * the Turkish 'i' character; human language is complicated!
  2042. *
  2043. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  2044. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  2045. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  2046. * CHARACTER), which is to say two strings of random bits may turn out to
  2047. * match if they convert to the same amount of replacement characters.
  2048. *
  2049. * \param str1 the first string to compare. NULL is not permitted!
  2050. * \param str2 the second string to compare. NULL is not permitted!
  2051. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2052. * str1 is "greater than" str2, and zero if the strings match
  2053. * exactly.
  2054. *
  2055. * \threadsafety It is safe to call this function from any thread.
  2056. *
  2057. * \since This function is available since SDL 3.0.0.
  2058. */
  2059. extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  2060. /**
  2061. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  2062. *
  2063. * This will work with Unicode strings, using a technique called
  2064. * "case-folding" to handle the vast majority of case-sensitive human
  2065. * languages regardless of system locale. It can deal with expanding values: a
  2066. * German Eszett character can compare against two ASCII 's' chars and be
  2067. * considered a match, for example. A notable exception: it does not handle
  2068. * the Turkish 'i' character; human language is complicated!
  2069. *
  2070. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  2071. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  2072. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  2073. * CHARACTER), which is to say two strings of random bits may turn out to
  2074. * match if they convert to the same amount of replacement characters.
  2075. *
  2076. * Note that while this function is intended to be used with UTF-8, `maxlen`
  2077. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  2078. * UTF-8 sequence, it may convert a portion of the final character to one or
  2079. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  2080. * a buffer.
  2081. *
  2082. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  2083. * match to this number of bytes (or both have matched to a null-terminator
  2084. * character before this number of bytes), they will be considered equal.
  2085. *
  2086. * \param str1 the first string to compare. NULL is not permitted!
  2087. * \param str2 the second string to compare. NULL is not permitted!
  2088. * \param maxlen the maximum number of bytes to compare.
  2089. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2090. * str1 is "greater than" str2, and zero if the strings match
  2091. * exactly.
  2092. *
  2093. * \threadsafety It is safe to call this function from any thread.
  2094. *
  2095. * \since This function is available since SDL 3.0.0.
  2096. */
  2097. extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  2098. /**
  2099. * Searches a string for the first occurence of any character contained in a
  2100. * breakset, and returns a pointer from the string to that character.
  2101. *
  2102. * \param str The null-terminated string to be searched. Must not be NULL, and
  2103. * must not overlap with `breakset`.
  2104. * \param breakset A null-terminated string containing the list of characters
  2105. * to look for. Must not be NULL, and must not overlap with
  2106. * `str`.
  2107. * \returns A pointer to the location, in str, of the first occurence of a
  2108. * character present in the breakset, or NULL if none is found.
  2109. *
  2110. * \threadsafety It is safe to call this function from any thread.
  2111. *
  2112. * \since This function is available since SDL 3.0.0.
  2113. */
  2114. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
  2115. /**
  2116. * The Unicode REPLACEMENT CHARACTER codepoint.
  2117. *
  2118. * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
  2119. * with encoding errors.
  2120. *
  2121. * This tends to render as something like a question mark in most places.
  2122. *
  2123. * \since This macro is available since SDL 3.0.0.
  2124. *
  2125. * \sa SDL_StepUTF8
  2126. */
  2127. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  2128. /**
  2129. * Decode a UTF-8 string, one Unicode codepoint at a time.
  2130. *
  2131. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  2132. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  2133. *
  2134. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  2135. * be adjusted, as well, subtracting the number of bytes consumed.
  2136. *
  2137. * `pslen` is allowed to be NULL, in which case the string _must_ be
  2138. * NULL-terminated, as the function will blindly read until it sees the NULL
  2139. * char.
  2140. *
  2141. * if `*pslen` is zero, it assumes the end of string is reached and returns a
  2142. * zero codepoint regardless of the contents of the string buffer.
  2143. *
  2144. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  2145. * zero, it will not advance `*pstr` or `*pslen` at all.
  2146. *
  2147. * Generally this function is called in a loop until it returns zero,
  2148. * adjusting its parameters each iteration.
  2149. *
  2150. * If an invalid UTF-8 sequence is encountered, this function returns
  2151. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  2152. * (which is to say, a multibyte sequence might produce several
  2153. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  2154. * UTF-8 sequence).
  2155. *
  2156. * Several things can generate invalid UTF-8 sequences, including overlong
  2157. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  2158. * refer to
  2159. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  2160. * for details.
  2161. *
  2162. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  2163. * \param pslen a pointer to the number of bytes in the string, to be read and
  2164. * adjusted. NULL is allowed.
  2165. * \returns the first Unicode codepoint in the string.
  2166. *
  2167. * \threadsafety It is safe to call this function from any thread.
  2168. *
  2169. * \since This function is available since SDL 3.0.0.
  2170. */
  2171. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  2172. /**
  2173. * Convert a single Unicode codepoint to UTF-8.
  2174. *
  2175. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  2176. * function may generate between 1 and 4 bytes of output.
  2177. *
  2178. * This function returns the first byte _after_ the newly-written UTF-8
  2179. * sequence, which is useful for encoding multiple codepoints in a loop, or
  2180. * knowing where to write a NULL-terminator character to end the string (in
  2181. * either case, plan to have a buffer of _more_ than 4 bytes!).
  2182. *
  2183. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  2184. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  2185. * codepoint instead, and not set an error.
  2186. *
  2187. * If `dst` is NULL, this returns NULL immediately without writing to the
  2188. * pointer and without setting an error.
  2189. *
  2190. * \param codepoint a Unicode codepoint to convert to UTF-8.
  2191. * \param dst the location to write the encoded UTF-8. Must point to at least
  2192. * 4 bytes!
  2193. * \returns the first byte past the newly-written UTF-8 sequence.
  2194. *
  2195. * \threadsafety It is safe to call this function from any thread.
  2196. *
  2197. * \since This function is available since SDL 3.0.0.
  2198. */
  2199. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  2200. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  2201. 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);
  2202. 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);
  2203. 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);
  2204. 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);
  2205. 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);
  2206. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  2207. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  2208. /**
  2209. * Seeds the pseudo-random number generator.
  2210. *
  2211. * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
  2212. * of 'random' numbers.
  2213. *
  2214. * \param seed the value to use as a random number seed, or 0 to use
  2215. * SDL_GetPerformanceCounter().
  2216. *
  2217. * \threadsafety This should be called on the same thread that calls
  2218. * SDL_rand*()
  2219. *
  2220. * \since This function is available since SDL 3.0.0.
  2221. *
  2222. * \sa SDL_rand
  2223. * \sa SDL_rand_bits
  2224. * \sa SDL_randf
  2225. */
  2226. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  2227. /**
  2228. * Generate a pseudo-random number less than n for positive n
  2229. *
  2230. * The method used is faster and of better quality than `rand() % n`. Odds are
  2231. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  2232. * much worse as n gets bigger.
  2233. *
  2234. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  2235. * 1..6
  2236. *
  2237. * If you want to generate a pseudo-random number in the full range of Sint32,
  2238. * you should use: (Sint32)SDL_rand_bits()
  2239. *
  2240. * If you want reproducible output, be sure to initialize with SDL_srand()
  2241. * first.
  2242. *
  2243. * There are no guarantees as to the quality of the random sequence produced,
  2244. * and this should not be used for security (cryptography, passwords) or where
  2245. * money is on the line (loot-boxes, casinos). There are many random number
  2246. * libraries available with different characteristics and you should pick one
  2247. * of those to meet any serious needs.
  2248. *
  2249. * \param n the number of possible outcomes. n must be positive.
  2250. * \returns a random value in the range of [0 .. n-1].
  2251. *
  2252. * \threadsafety All calls should be made from a single thread
  2253. *
  2254. * \since This function is available since SDL 3.0.0.
  2255. *
  2256. * \sa SDL_srand
  2257. * \sa SDL_randf
  2258. */
  2259. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  2260. /**
  2261. * Generate a uniform pseudo-random floating point number less than 1.0
  2262. *
  2263. * If you want reproducible output, be sure to initialize with SDL_srand()
  2264. * first.
  2265. *
  2266. * There are no guarantees as to the quality of the random sequence produced,
  2267. * and this should not be used for security (cryptography, passwords) or where
  2268. * money is on the line (loot-boxes, casinos). There are many random number
  2269. * libraries available with different characteristics and you should pick one
  2270. * of those to meet any serious needs.
  2271. *
  2272. * \returns a random value in the range of [0.0, 1.0).
  2273. *
  2274. * \threadsafety All calls should be made from a single thread
  2275. *
  2276. * \since This function is available since SDL 3.0.0.
  2277. *
  2278. * \sa SDL_srand
  2279. * \sa SDL_rand
  2280. */
  2281. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  2282. /**
  2283. * Generate 32 pseudo-random bits.
  2284. *
  2285. * You likely want to use SDL_rand() to get a psuedo-random number instead.
  2286. *
  2287. * There are no guarantees as to the quality of the random sequence produced,
  2288. * and this should not be used for security (cryptography, passwords) or where
  2289. * money is on the line (loot-boxes, casinos). There are many random number
  2290. * libraries available with different characteristics and you should pick one
  2291. * of those to meet any serious needs.
  2292. *
  2293. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  2294. *
  2295. * \threadsafety All calls should be made from a single thread
  2296. *
  2297. * \since This function is available since SDL 3.0.0.
  2298. *
  2299. * \sa SDL_rand
  2300. * \sa SDL_randf
  2301. * \sa SDL_srand
  2302. */
  2303. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  2304. /**
  2305. * Generate a pseudo-random number less than n for positive n
  2306. *
  2307. * The method used is faster and of better quality than `rand() % n`. Odds are
  2308. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  2309. * much worse as n gets bigger.
  2310. *
  2311. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  2312. * 0..5 to 1..6
  2313. *
  2314. * If you want to generate a pseudo-random number in the full range of Sint32,
  2315. * you should use: (Sint32)SDL_rand_bits_r(state)
  2316. *
  2317. * There are no guarantees as to the quality of the random sequence produced,
  2318. * and this should not be used for security (cryptography, passwords) or where
  2319. * money is on the line (loot-boxes, casinos). There are many random number
  2320. * libraries available with different characteristics and you should pick one
  2321. * of those to meet any serious needs.
  2322. *
  2323. * \param state a pointer to the current random number state, this may not be
  2324. * NULL.
  2325. * \param n the number of possible outcomes. n must be positive.
  2326. * \returns a random value in the range of [0 .. n-1].
  2327. *
  2328. * \threadsafety This function is thread-safe, as long as the state pointer
  2329. * isn't shared between threads.
  2330. *
  2331. * \since This function is available since SDL 3.0.0.
  2332. *
  2333. * \sa SDL_rand
  2334. * \sa SDL_rand_bits_r
  2335. * \sa SDL_randf_r
  2336. */
  2337. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  2338. /**
  2339. * Generate a uniform pseudo-random floating point number less than 1.0
  2340. *
  2341. * If you want reproducible output, be sure to initialize with SDL_srand()
  2342. * first.
  2343. *
  2344. * There are no guarantees as to the quality of the random sequence produced,
  2345. * and this should not be used for security (cryptography, passwords) or where
  2346. * money is on the line (loot-boxes, casinos). There are many random number
  2347. * libraries available with different characteristics and you should pick one
  2348. * of those to meet any serious needs.
  2349. *
  2350. * \param state a pointer to the current random number state, this may not be
  2351. * NULL.
  2352. * \returns a random value in the range of [0.0, 1.0).
  2353. *
  2354. * \threadsafety This function is thread-safe, as long as the state pointer
  2355. * isn't shared between threads.
  2356. *
  2357. * \since This function is available since SDL 3.0.0.
  2358. *
  2359. * \sa SDL_rand_bits_r
  2360. * \sa SDL_rand_r
  2361. * \sa SDL_randf
  2362. */
  2363. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  2364. /**
  2365. * Generate 32 pseudo-random bits.
  2366. *
  2367. * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
  2368. *
  2369. * There are no guarantees as to the quality of the random sequence produced,
  2370. * and this should not be used for security (cryptography, passwords) or where
  2371. * money is on the line (loot-boxes, casinos). There are many random number
  2372. * libraries available with different characteristics and you should pick one
  2373. * of those to meet any serious needs.
  2374. *
  2375. * \param state a pointer to the current random number state, this may not be
  2376. * NULL.
  2377. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  2378. *
  2379. * \threadsafety This function is thread-safe, as long as the state pointer
  2380. * isn't shared between threads.
  2381. *
  2382. * \since This function is available since SDL 3.0.0.
  2383. *
  2384. * \sa SDL_rand_r
  2385. * \sa SDL_randf_r
  2386. */
  2387. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  2388. #ifndef SDL_PI_D
  2389. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  2390. #endif
  2391. #ifndef SDL_PI_F
  2392. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  2393. #endif
  2394. /**
  2395. * Compute the arc cosine of `x`.
  2396. *
  2397. * The definition of `y = acos(x)` is `x = cos(y)`.
  2398. *
  2399. * Domain: `-1 <= x <= 1`
  2400. *
  2401. * Range: `0 <= y <= Pi`
  2402. *
  2403. * This function operates on double-precision floating point values, use
  2404. * SDL_acosf for single-precision floats.
  2405. *
  2406. * This function may use a different approximation across different versions,
  2407. * platforms and configurations. i.e, it can return a different value given
  2408. * the same input on different machines or operating systems, or if SDL is
  2409. * updated.
  2410. *
  2411. * \param x floating point value.
  2412. * \returns arc cosine of `x`, in radians.
  2413. *
  2414. * \threadsafety It is safe to call this function from any thread.
  2415. *
  2416. * \since This function is available since SDL 3.0.0.
  2417. *
  2418. * \sa SDL_acosf
  2419. * \sa SDL_asin
  2420. * \sa SDL_cos
  2421. */
  2422. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  2423. /**
  2424. * Compute the arc cosine of `x`.
  2425. *
  2426. * The definition of `y = acos(x)` is `x = cos(y)`.
  2427. *
  2428. * Domain: `-1 <= x <= 1`
  2429. *
  2430. * Range: `0 <= y <= Pi`
  2431. *
  2432. * This function operates on single-precision floating point values, use
  2433. * SDL_acos for double-precision floats.
  2434. *
  2435. * This function may use a different approximation across different versions,
  2436. * platforms and configurations. i.e, it can return a different value given
  2437. * the same input on different machines or operating systems, or if SDL is
  2438. * updated.
  2439. *
  2440. * \param x floating point value.
  2441. * \returns arc cosine of `x`, in radians.
  2442. *
  2443. * \threadsafety It is safe to call this function from any thread.
  2444. *
  2445. * \since This function is available since SDL 3.0.0.
  2446. *
  2447. * \sa SDL_acos
  2448. * \sa SDL_asinf
  2449. * \sa SDL_cosf
  2450. */
  2451. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  2452. /**
  2453. * Compute the arc sine of `x`.
  2454. *
  2455. * The definition of `y = asin(x)` is `x = sin(y)`.
  2456. *
  2457. * Domain: `-1 <= x <= 1`
  2458. *
  2459. * Range: `-Pi/2 <= y <= Pi/2`
  2460. *
  2461. * This function operates on double-precision floating point values, use
  2462. * SDL_asinf for single-precision floats.
  2463. *
  2464. * This function may use a different approximation across different versions,
  2465. * platforms and configurations. i.e, it can return a different value given
  2466. * the same input on different machines or operating systems, or if SDL is
  2467. * updated.
  2468. *
  2469. * \param x floating point value.
  2470. * \returns arc sine of `x`, in radians.
  2471. *
  2472. * \threadsafety It is safe to call this function from any thread.
  2473. *
  2474. * \since This function is available since SDL 3.0.0.
  2475. *
  2476. * \sa SDL_asinf
  2477. * \sa SDL_acos
  2478. * \sa SDL_sin
  2479. */
  2480. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  2481. /**
  2482. * Compute the arc sine of `x`.
  2483. *
  2484. * The definition of `y = asin(x)` is `x = sin(y)`.
  2485. *
  2486. * Domain: `-1 <= x <= 1`
  2487. *
  2488. * Range: `-Pi/2 <= y <= Pi/2`
  2489. *
  2490. * This function operates on single-precision floating point values, use
  2491. * SDL_asin for double-precision floats.
  2492. *
  2493. * This function may use a different approximation across different versions,
  2494. * platforms and configurations. i.e, it can return a different value given
  2495. * the same input on different machines or operating systems, or if SDL is
  2496. * updated.
  2497. *
  2498. * \param x floating point value.
  2499. * \returns arc sine of `x`, in radians.
  2500. *
  2501. * \threadsafety It is safe to call this function from any thread.
  2502. *
  2503. * \since This function is available since SDL 3.0.0.
  2504. *
  2505. * \sa SDL_asin
  2506. * \sa SDL_acosf
  2507. * \sa SDL_sinf
  2508. */
  2509. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  2510. /**
  2511. * Compute the arc tangent of `x`.
  2512. *
  2513. * The definition of `y = atan(x)` is `x = tan(y)`.
  2514. *
  2515. * Domain: `-INF <= x <= INF`
  2516. *
  2517. * Range: `-Pi/2 <= y <= Pi/2`
  2518. *
  2519. * This function operates on double-precision floating point values, use
  2520. * SDL_atanf for single-precision floats.
  2521. *
  2522. * To calculate the arc tangent of y / x, use SDL_atan2.
  2523. *
  2524. * This function may use a different approximation across different versions,
  2525. * platforms and configurations. i.e, it can return a different value given
  2526. * the same input on different machines or operating systems, or if SDL is
  2527. * updated.
  2528. *
  2529. * \param x floating point value.
  2530. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  2531. *
  2532. * \threadsafety It is safe to call this function from any thread.
  2533. *
  2534. * \since This function is available since SDL 3.0.0.
  2535. *
  2536. * \sa SDL_atanf
  2537. * \sa SDL_atan2
  2538. * \sa SDL_tan
  2539. */
  2540. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  2541. /**
  2542. * Compute the arc tangent of `x`.
  2543. *
  2544. * The definition of `y = atan(x)` is `x = tan(y)`.
  2545. *
  2546. * Domain: `-INF <= x <= INF`
  2547. *
  2548. * Range: `-Pi/2 <= y <= Pi/2`
  2549. *
  2550. * This function operates on single-precision floating point values, use
  2551. * SDL_atan for dboule-precision floats.
  2552. *
  2553. * To calculate the arc tangent of y / x, use SDL_atan2f.
  2554. *
  2555. * This function may use a different approximation across different versions,
  2556. * platforms and configurations. i.e, it can return a different value given
  2557. * the same input on different machines or operating systems, or if SDL is
  2558. * updated.
  2559. *
  2560. * \param x floating point value.
  2561. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  2562. *
  2563. * \threadsafety It is safe to call this function from any thread.
  2564. *
  2565. * \since This function is available since SDL 3.0.0.
  2566. *
  2567. * \sa SDL_atan
  2568. * \sa SDL_atan2f
  2569. * \sa SDL_tanf
  2570. */
  2571. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  2572. /**
  2573. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  2574. * the result's quadrant.
  2575. *
  2576. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  2577. * of z is determined based on the signs of x and y.
  2578. *
  2579. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2580. *
  2581. * Range: `-Pi/2 <= y <= Pi/2`
  2582. *
  2583. * This function operates on double-precision floating point values, use
  2584. * SDL_atan2f for single-precision floats.
  2585. *
  2586. * To calculate the arc tangent of a single value, use SDL_atan.
  2587. *
  2588. * This function may use a different approximation across different versions,
  2589. * platforms and configurations. i.e, it can return a different value given
  2590. * the same input on different machines or operating systems, or if SDL is
  2591. * updated.
  2592. *
  2593. * \param y floating point value of the numerator (y coordinate).
  2594. * \param x floating point value of the denominator (x coordinate).
  2595. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  2596. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  2597. *
  2598. * \threadsafety It is safe to call this function from any thread.
  2599. *
  2600. * \since This function is available since SDL 3.0.0.
  2601. *
  2602. * \sa SDL_atan2f
  2603. * \sa SDL_atan
  2604. * \sa SDL_tan
  2605. */
  2606. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  2607. /**
  2608. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  2609. * the result's quadrant.
  2610. *
  2611. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  2612. * of z is determined based on the signs of x and y.
  2613. *
  2614. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2615. *
  2616. * Range: `-Pi/2 <= y <= Pi/2`
  2617. *
  2618. * This function operates on single-precision floating point values, use
  2619. * SDL_atan2 for double-precision floats.
  2620. *
  2621. * To calculate the arc tangent of a single value, use SDL_atanf.
  2622. *
  2623. * This function may use a different approximation across different versions,
  2624. * platforms and configurations. i.e, it can return a different value given
  2625. * the same input on different machines or operating systems, or if SDL is
  2626. * updated.
  2627. *
  2628. * \param y floating point value of the numerator (y coordinate).
  2629. * \param x floating point value of the denominator (x coordinate).
  2630. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  2631. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  2632. *
  2633. * \threadsafety It is safe to call this function from any thread.
  2634. *
  2635. * \since This function is available since SDL 3.0.0.
  2636. *
  2637. * \sa SDL_atan2f
  2638. * \sa SDL_atan
  2639. * \sa SDL_tan
  2640. */
  2641. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  2642. /**
  2643. * Compute the ceiling of `x`.
  2644. *
  2645. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  2646. * rounded up to the nearest integer.
  2647. *
  2648. * Domain: `-INF <= x <= INF`
  2649. *
  2650. * Range: `-INF <= y <= INF`, y integer
  2651. *
  2652. * This function operates on double-precision floating point values, use
  2653. * SDL_ceilf for single-precision floats.
  2654. *
  2655. * \param x floating point value.
  2656. * \returns the ceiling of `x`.
  2657. *
  2658. * \threadsafety It is safe to call this function from any thread.
  2659. *
  2660. * \since This function is available since SDL 3.0.0.
  2661. *
  2662. * \sa SDL_ceilf
  2663. * \sa SDL_floor
  2664. * \sa SDL_trunc
  2665. * \sa SDL_round
  2666. * \sa SDL_lround
  2667. */
  2668. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  2669. /**
  2670. * Compute the ceiling of `x`.
  2671. *
  2672. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  2673. * rounded up to the nearest integer.
  2674. *
  2675. * Domain: `-INF <= x <= INF`
  2676. *
  2677. * Range: `-INF <= y <= INF`, y integer
  2678. *
  2679. * This function operates on single-precision floating point values, use
  2680. * SDL_ceil for double-precision floats.
  2681. *
  2682. * \param x floating point value.
  2683. * \returns the ceiling of `x`.
  2684. *
  2685. * \threadsafety It is safe to call this function from any thread.
  2686. *
  2687. * \since This function is available since SDL 3.0.0.
  2688. *
  2689. * \sa SDL_ceil
  2690. * \sa SDL_floorf
  2691. * \sa SDL_truncf
  2692. * \sa SDL_roundf
  2693. * \sa SDL_lroundf
  2694. */
  2695. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  2696. /**
  2697. * Copy the sign of one floating-point value to another.
  2698. *
  2699. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  2700. *
  2701. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  2702. *
  2703. * Range: `-INF <= z <= INF`
  2704. *
  2705. * This function operates on double-precision floating point values, use
  2706. * SDL_copysignf for single-precision floats.
  2707. *
  2708. * \param x floating point value to use as the magnitude.
  2709. * \param y floating point value to use as the sign.
  2710. * \returns the floating point value with the sign of y and the magnitude of
  2711. * x.
  2712. *
  2713. * \threadsafety It is safe to call this function from any thread.
  2714. *
  2715. * \since This function is available since SDL 3.0.0.
  2716. *
  2717. * \sa SDL_copysignf
  2718. * \sa SDL_fabs
  2719. */
  2720. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  2721. /**
  2722. * Copy the sign of one floating-point value to another.
  2723. *
  2724. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  2725. *
  2726. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  2727. *
  2728. * Range: `-INF <= z <= INF`
  2729. *
  2730. * This function operates on single-precision floating point values, use
  2731. * SDL_copysign for double-precision floats.
  2732. *
  2733. * \param x floating point value to use as the magnitude.
  2734. * \param y floating point value to use as the sign.
  2735. * \returns the floating point value with the sign of y and the magnitude of
  2736. * x.
  2737. *
  2738. * \threadsafety It is safe to call this function from any thread.
  2739. *
  2740. * \since This function is available since SDL 3.0.0.
  2741. *
  2742. * \sa SDL_copysignf
  2743. * \sa SDL_fabsf
  2744. */
  2745. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  2746. /**
  2747. * Compute the cosine of `x`.
  2748. *
  2749. * Domain: `-INF <= x <= INF`
  2750. *
  2751. * Range: `-1 <= y <= 1`
  2752. *
  2753. * This function operates on double-precision floating point values, use
  2754. * SDL_cosf for single-precision floats.
  2755. *
  2756. * This function may use a different approximation across different versions,
  2757. * platforms and configurations. i.e, it can return a different value given
  2758. * the same input on different machines or operating systems, or if SDL is
  2759. * updated.
  2760. *
  2761. * \param x floating point value, in radians.
  2762. * \returns cosine of `x`.
  2763. *
  2764. * \threadsafety It is safe to call this function from any thread.
  2765. *
  2766. * \since This function is available since SDL 3.0.0.
  2767. *
  2768. * \sa SDL_cosf
  2769. * \sa SDL_acos
  2770. * \sa SDL_sin
  2771. */
  2772. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  2773. /**
  2774. * Compute the cosine of `x`.
  2775. *
  2776. * Domain: `-INF <= x <= INF`
  2777. *
  2778. * Range: `-1 <= y <= 1`
  2779. *
  2780. * This function operates on single-precision floating point values, use
  2781. * SDL_cos for double-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, in radians.
  2789. * \returns cosine of `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_cos
  2796. * \sa SDL_acosf
  2797. * \sa SDL_sinf
  2798. */
  2799. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  2800. /**
  2801. * Compute the exponential of `x`.
  2802. *
  2803. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2804. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  2805. *
  2806. * Domain: `-INF <= x <= INF`
  2807. *
  2808. * Range: `0 <= y <= INF`
  2809. *
  2810. * The output will overflow if `exp(x)` is too large to be represented.
  2811. *
  2812. * This function operates on double-precision floating point values, use
  2813. * SDL_expf for single-precision floats.
  2814. *
  2815. * This function may use a different approximation across different versions,
  2816. * platforms and configurations. i.e, it can return a different value given
  2817. * the same input on different machines or operating systems, or if SDL is
  2818. * updated.
  2819. *
  2820. * \param x floating point value.
  2821. * \returns value of `e^x`.
  2822. *
  2823. * \threadsafety It is safe to call this function from any thread.
  2824. *
  2825. * \since This function is available since SDL 3.0.0.
  2826. *
  2827. * \sa SDL_expf
  2828. * \sa SDL_log
  2829. */
  2830. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  2831. /**
  2832. * Compute the exponential of `x`.
  2833. *
  2834. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2835. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  2836. *
  2837. * Domain: `-INF <= x <= INF`
  2838. *
  2839. * Range: `0 <= y <= INF`
  2840. *
  2841. * The output will overflow if `exp(x)` is too large to be represented.
  2842. *
  2843. * This function operates on single-precision floating point values, use
  2844. * SDL_exp for double-precision floats.
  2845. *
  2846. * This function may use a different approximation across different versions,
  2847. * platforms and configurations. i.e, it can return a different value given
  2848. * the same input on different machines or operating systems, or if SDL is
  2849. * updated.
  2850. *
  2851. * \param x floating point value.
  2852. * \returns value of `e^x`.
  2853. *
  2854. * \threadsafety It is safe to call this function from any thread.
  2855. *
  2856. * \since This function is available since SDL 3.0.0.
  2857. *
  2858. * \sa SDL_exp
  2859. * \sa SDL_logf
  2860. */
  2861. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  2862. /**
  2863. * Compute the absolute value of `x`
  2864. *
  2865. * Domain: `-INF <= x <= INF`
  2866. *
  2867. * Range: `0 <= y <= INF`
  2868. *
  2869. * This function operates on double-precision floating point values, use
  2870. * SDL_copysignf for single-precision floats.
  2871. *
  2872. * \param x floating point value to use as the magnitude.
  2873. * \returns the absolute value of `x`.
  2874. *
  2875. * \threadsafety It is safe to call this function from any thread.
  2876. *
  2877. * \since This function is available since SDL 3.0.0.
  2878. *
  2879. * \sa SDL_fabsf
  2880. */
  2881. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  2882. /**
  2883. * Compute the absolute value of `x`
  2884. *
  2885. * Domain: `-INF <= x <= INF`
  2886. *
  2887. * Range: `0 <= y <= INF`
  2888. *
  2889. * This function operates on single-precision floating point values, use
  2890. * SDL_copysignf for double-precision floats.
  2891. *
  2892. * \param x floating point value to use as the magnitude.
  2893. * \returns the absolute value of `x`.
  2894. *
  2895. * \threadsafety It is safe to call this function from any thread.
  2896. *
  2897. * \since This function is available since SDL 3.0.0.
  2898. *
  2899. * \sa SDL_fabs
  2900. */
  2901. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  2902. /**
  2903. * Compute the floor of `x`.
  2904. *
  2905. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2906. * rounded down to the nearest integer.
  2907. *
  2908. * Domain: `-INF <= x <= INF`
  2909. *
  2910. * Range: `-INF <= y <= INF`, y integer
  2911. *
  2912. * This function operates on double-precision floating point values, use
  2913. * SDL_floorf for single-precision floats.
  2914. *
  2915. * \param x floating point value.
  2916. * \returns the floor of `x`.
  2917. *
  2918. * \threadsafety It is safe to call this function from any thread.
  2919. *
  2920. * \since This function is available since SDL 3.0.0.
  2921. *
  2922. * \sa SDL_floorf
  2923. * \sa SDL_ceil
  2924. * \sa SDL_trunc
  2925. * \sa SDL_round
  2926. * \sa SDL_lround
  2927. */
  2928. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  2929. /**
  2930. * Compute the floor of `x`.
  2931. *
  2932. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2933. * rounded down to the nearest integer.
  2934. *
  2935. * Domain: `-INF <= x <= INF`
  2936. *
  2937. * Range: `-INF <= y <= INF`, y integer
  2938. *
  2939. * This function operates on single-precision floating point values, use
  2940. * SDL_floorf for double-precision floats.
  2941. *
  2942. * \param x floating point value.
  2943. * \returns the floor of `x`.
  2944. *
  2945. * \threadsafety It is safe to call this function from any thread.
  2946. *
  2947. * \since This function is available since SDL 3.0.0.
  2948. *
  2949. * \sa SDL_floor
  2950. * \sa SDL_ceilf
  2951. * \sa SDL_truncf
  2952. * \sa SDL_roundf
  2953. * \sa SDL_lroundf
  2954. */
  2955. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  2956. /**
  2957. * Truncate `x` to an integer.
  2958. *
  2959. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2960. * the fractional part of `x`, leaving only the integer part.
  2961. *
  2962. * Domain: `-INF <= x <= INF`
  2963. *
  2964. * Range: `-INF <= y <= INF`, y integer
  2965. *
  2966. * This function operates on double-precision floating point values, use
  2967. * SDL_truncf for single-precision floats.
  2968. *
  2969. * \param x floating point value.
  2970. * \returns `x` truncated to an integer.
  2971. *
  2972. * \threadsafety It is safe to call this function from any thread.
  2973. *
  2974. * \since This function is available since SDL 3.0.0.
  2975. *
  2976. * \sa SDL_truncf
  2977. * \sa SDL_fmod
  2978. * \sa SDL_ceil
  2979. * \sa SDL_floor
  2980. * \sa SDL_round
  2981. * \sa SDL_lround
  2982. */
  2983. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  2984. /**
  2985. * Truncate `x` to an integer.
  2986. *
  2987. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2988. * the fractional part of `x`, leaving only the integer part.
  2989. *
  2990. * Domain: `-INF <= x <= INF`
  2991. *
  2992. * Range: `-INF <= y <= INF`, y integer
  2993. *
  2994. * This function operates on single-precision floating point values, use
  2995. * SDL_truncf for double-precision floats.
  2996. *
  2997. * \param x floating point value.
  2998. * \returns `x` truncated to an integer.
  2999. *
  3000. * \threadsafety It is safe to call this function from any thread.
  3001. *
  3002. * \since This function is available since SDL 3.0.0.
  3003. *
  3004. * \sa SDL_trunc
  3005. * \sa SDL_fmodf
  3006. * \sa SDL_ceilf
  3007. * \sa SDL_floorf
  3008. * \sa SDL_roundf
  3009. * \sa SDL_lroundf
  3010. */
  3011. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  3012. /**
  3013. * Return the floating-point remainder of `x / y`
  3014. *
  3015. * Divides `x` by `y`, and returns the remainder.
  3016. *
  3017. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  3018. *
  3019. * Range: `-y <= z <= y`
  3020. *
  3021. * This function operates on double-precision floating point values, use
  3022. * SDL_fmodf for single-precision floats.
  3023. *
  3024. * \param x the numerator.
  3025. * \param y the denominator. Must not be 0.
  3026. * \returns the remainder of `x / y`.
  3027. *
  3028. * \threadsafety It is safe to call this function from any thread.
  3029. *
  3030. * \since This function is available since SDL 3.0.0.
  3031. *
  3032. * \sa SDL_fmodf
  3033. * \sa SDL_modf
  3034. * \sa SDL_trunc
  3035. * \sa SDL_ceil
  3036. * \sa SDL_floor
  3037. * \sa SDL_round
  3038. * \sa SDL_lround
  3039. */
  3040. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  3041. /**
  3042. * Return the floating-point remainder of `x / y`
  3043. *
  3044. * Divides `x` by `y`, and returns the remainder.
  3045. *
  3046. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  3047. *
  3048. * Range: `-y <= z <= y`
  3049. *
  3050. * This function operates on single-precision floating point values, use
  3051. * SDL_fmod for single-precision floats.
  3052. *
  3053. * \param x the numerator.
  3054. * \param y the denominator. Must not be 0.
  3055. * \returns the remainder of `x / y`.
  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_fmod
  3062. * \sa SDL_truncf
  3063. * \sa SDL_modff
  3064. * \sa SDL_ceilf
  3065. * \sa SDL_floorf
  3066. * \sa SDL_roundf
  3067. * \sa SDL_lroundf
  3068. */
  3069. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  3070. /**
  3071. * Return whether the value is infinity.
  3072. *
  3073. * \param x double-precision floating point value.
  3074. * \returns non-zero if the value is infinity, 0 otherwise.
  3075. *
  3076. * \threadsafety It is safe to call this function from any thread.
  3077. *
  3078. * \since This function is available since SDL 3.0.0.
  3079. *
  3080. * \sa SDL_isinff
  3081. */
  3082. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  3083. /**
  3084. * Return whether the value is infinity.
  3085. *
  3086. * \param x floating point value.
  3087. * \returns non-zero if the value is infinity, 0 otherwise.
  3088. *
  3089. * \threadsafety It is safe to call this function from any thread.
  3090. *
  3091. * \since This function is available since SDL 3.0.0.
  3092. *
  3093. * \sa SDL_isinf
  3094. */
  3095. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  3096. /**
  3097. * Return whether the value is NaN.
  3098. *
  3099. * \param x double-precision floating point value.
  3100. * \returns non-zero if the value is NaN, 0 otherwise.
  3101. *
  3102. * \threadsafety It is safe to call this function from any thread.
  3103. *
  3104. * \since This function is available since SDL 3.0.0.
  3105. *
  3106. * \sa SDL_isnanf
  3107. */
  3108. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  3109. /**
  3110. * Return whether the value is NaN.
  3111. *
  3112. * \param x floating point value.
  3113. * \returns non-zero if the value is NaN, 0 otherwise.
  3114. *
  3115. * \threadsafety It is safe to call this function from any thread.
  3116. *
  3117. * \since This function is available since SDL 3.0.0.
  3118. *
  3119. * \sa SDL_isnan
  3120. */
  3121. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  3122. /**
  3123. * Compute the natural logarithm of `x`.
  3124. *
  3125. * Domain: `0 < x <= INF`
  3126. *
  3127. * Range: `-INF <= y <= INF`
  3128. *
  3129. * It is an error for `x` to be less than or equal to 0.
  3130. *
  3131. * This function operates on double-precision floating point values, use
  3132. * SDL_logf for single-precision floats.
  3133. *
  3134. * This function may use a different approximation across different versions,
  3135. * platforms and configurations. i.e, it can return a different value given
  3136. * the same input on different machines or operating systems, or if SDL is
  3137. * updated.
  3138. *
  3139. * \param x floating point value. Must be greater than 0.
  3140. * \returns the natural logarithm of `x`.
  3141. *
  3142. * \threadsafety It is safe to call this function from any thread.
  3143. *
  3144. * \since This function is available since SDL 3.0.0.
  3145. *
  3146. * \sa SDL_logf
  3147. * \sa SDL_log10
  3148. * \sa SDL_exp
  3149. */
  3150. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  3151. /**
  3152. * Compute the natural logarithm of `x`.
  3153. *
  3154. * Domain: `0 < x <= INF`
  3155. *
  3156. * Range: `-INF <= y <= INF`
  3157. *
  3158. * It is an error for `x` to be less than or equal to 0.
  3159. *
  3160. * This function operates on single-precision floating point values, use
  3161. * SDL_log for double-precision floats.
  3162. *
  3163. * This function may use a different approximation across different versions,
  3164. * platforms and configurations. i.e, it can return a different value given
  3165. * the same input on different machines or operating systems, or if SDL is
  3166. * updated.
  3167. *
  3168. * \param x floating point value. Must be greater than 0.
  3169. * \returns the natural logarithm of `x`.
  3170. *
  3171. * \threadsafety It is safe to call this function from any thread.
  3172. *
  3173. * \since This function is available since SDL 3.0.0.
  3174. *
  3175. * \sa SDL_log
  3176. * \sa SDL_expf
  3177. */
  3178. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  3179. /**
  3180. * Compute the base-10 logarithm of `x`.
  3181. *
  3182. * Domain: `0 < x <= INF`
  3183. *
  3184. * Range: `-INF <= y <= INF`
  3185. *
  3186. * It is an error for `x` to be less than or equal to 0.
  3187. *
  3188. * This function operates on double-precision floating point values, use
  3189. * SDL_log10f for single-precision floats.
  3190. *
  3191. * This function may use a different approximation across different versions,
  3192. * platforms and configurations. i.e, it can return a different value given
  3193. * the same input on different machines or operating systems, or if SDL is
  3194. * updated.
  3195. *
  3196. * \param x floating point value. Must be greater than 0.
  3197. * \returns the logarithm of `x`.
  3198. *
  3199. * \threadsafety It is safe to call this function from any thread.
  3200. *
  3201. * \since This function is available since SDL 3.0.0.
  3202. *
  3203. * \sa SDL_log10f
  3204. * \sa SDL_log
  3205. * \sa SDL_pow
  3206. */
  3207. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  3208. /**
  3209. * Compute the base-10 logarithm of `x`.
  3210. *
  3211. * Domain: `0 < x <= INF`
  3212. *
  3213. * Range: `-INF <= y <= INF`
  3214. *
  3215. * It is an error for `x` to be less than or equal to 0.
  3216. *
  3217. * This function operates on single-precision floating point values, use
  3218. * SDL_log10 for double-precision floats.
  3219. *
  3220. * This function may use a different approximation across different versions,
  3221. * platforms and configurations. i.e, it can return a different value given
  3222. * the same input on different machines or operating systems, or if SDL is
  3223. * updated.
  3224. *
  3225. * \param x floating point value. Must be greater than 0.
  3226. * \returns the logarithm of `x`.
  3227. *
  3228. * \threadsafety It is safe to call this function from any thread.
  3229. *
  3230. * \since This function is available since SDL 3.0.0.
  3231. *
  3232. * \sa SDL_log10
  3233. * \sa SDL_logf
  3234. * \sa SDL_powf
  3235. */
  3236. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  3237. /**
  3238. * Split `x` into integer and fractional parts
  3239. *
  3240. * This function operates on double-precision floating point values, use
  3241. * SDL_modff for single-precision floats.
  3242. *
  3243. * \param x floating point value.
  3244. * \param y output pointer to store the integer part of `x`.
  3245. * \returns the fractional part of `x`.
  3246. *
  3247. * \threadsafety It is safe to call this function from any thread.
  3248. *
  3249. * \since This function is available since SDL 3.0.0.
  3250. *
  3251. * \sa SDL_modff
  3252. * \sa SDL_trunc
  3253. * \sa SDL_fmod
  3254. */
  3255. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  3256. /**
  3257. * Split `x` into integer and fractional parts
  3258. *
  3259. * This function operates on single-precision floating point values, use
  3260. * SDL_modf for double-precision floats.
  3261. *
  3262. * \param x floating point value.
  3263. * \param y output pointer to store the integer part of `x`.
  3264. * \returns the fractional part of `x`.
  3265. *
  3266. * \threadsafety It is safe to call this function from any thread.
  3267. *
  3268. * \since This function is available since SDL 3.0.0.
  3269. *
  3270. * \sa SDL_modf
  3271. * \sa SDL_truncf
  3272. * \sa SDL_fmodf
  3273. */
  3274. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  3275. /**
  3276. * Raise `x` to the power `y`
  3277. *
  3278. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  3279. *
  3280. * Range: `-INF <= z <= INF`
  3281. *
  3282. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  3283. * instead.
  3284. *
  3285. * This function operates on double-precision floating point values, use
  3286. * SDL_powf for single-precision floats.
  3287. *
  3288. * This function may use a different approximation across different versions,
  3289. * platforms and configurations. i.e, it can return a different value given
  3290. * the same input on different machines or operating systems, or if SDL is
  3291. * updated.
  3292. *
  3293. * \param x the base.
  3294. * \param y the exponent.
  3295. * \returns `x` raised to the power `y`.
  3296. *
  3297. * \threadsafety It is safe to call this function from any thread.
  3298. *
  3299. * \since This function is available since SDL 3.0.0.
  3300. *
  3301. * \sa SDL_powf
  3302. * \sa SDL_exp
  3303. * \sa SDL_log
  3304. */
  3305. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  3306. /**
  3307. * Raise `x` to the power `y`
  3308. *
  3309. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  3310. *
  3311. * Range: `-INF <= z <= INF`
  3312. *
  3313. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  3314. * instead.
  3315. *
  3316. * This function operates on single-precision floating point values, use
  3317. * SDL_powf for double-precision floats.
  3318. *
  3319. * This function may use a different approximation across different versions,
  3320. * platforms and configurations. i.e, it can return a different value given
  3321. * the same input on different machines or operating systems, or if SDL is
  3322. * updated.
  3323. *
  3324. * \param x the base.
  3325. * \param y the exponent.
  3326. * \returns `x` raised to the power `y`.
  3327. *
  3328. * \threadsafety It is safe to call this function from any thread.
  3329. *
  3330. * \since This function is available since SDL 3.0.0.
  3331. *
  3332. * \sa SDL_pow
  3333. * \sa SDL_expf
  3334. * \sa SDL_logf
  3335. */
  3336. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  3337. /**
  3338. * Round `x` to the nearest integer.
  3339. *
  3340. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3341. * rounded away from zero.
  3342. *
  3343. * Domain: `-INF <= x <= INF`
  3344. *
  3345. * Range: `-INF <= y <= INF`, y integer
  3346. *
  3347. * This function operates on double-precision floating point values, use
  3348. * SDL_roundf for single-precision floats. To get the result as an integer
  3349. * type, use SDL_lround.
  3350. *
  3351. * \param x floating point value.
  3352. * \returns the nearest integer to `x`.
  3353. *
  3354. * \threadsafety It is safe to call this function from any thread.
  3355. *
  3356. * \since This function is available since SDL 3.0.0.
  3357. *
  3358. * \sa SDL_roundf
  3359. * \sa SDL_lround
  3360. * \sa SDL_floor
  3361. * \sa SDL_ceil
  3362. * \sa SDL_trunc
  3363. */
  3364. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  3365. /**
  3366. * Round `x` to the nearest integer.
  3367. *
  3368. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3369. * rounded away from zero.
  3370. *
  3371. * Domain: `-INF <= x <= INF`
  3372. *
  3373. * Range: `-INF <= y <= INF`, y integer
  3374. *
  3375. * This function operates on double-precision floating point values, use
  3376. * SDL_roundf for single-precision floats. To get the result as an integer
  3377. * type, use SDL_lroundf.
  3378. *
  3379. * \param x floating point value.
  3380. * \returns the nearest integer to `x`.
  3381. *
  3382. * \threadsafety It is safe to call this function from any thread.
  3383. *
  3384. * \since This function is available since SDL 3.0.0.
  3385. *
  3386. * \sa SDL_round
  3387. * \sa SDL_lroundf
  3388. * \sa SDL_floorf
  3389. * \sa SDL_ceilf
  3390. * \sa SDL_truncf
  3391. */
  3392. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  3393. /**
  3394. * Round `x` to the nearest integer representable as a long
  3395. *
  3396. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3397. * rounded away from zero.
  3398. *
  3399. * Domain: `-INF <= x <= INF`
  3400. *
  3401. * Range: `MIN_LONG <= y <= MAX_LONG`
  3402. *
  3403. * This function operates on double-precision floating point values, use
  3404. * SDL_lround for single-precision floats. To get the result as a
  3405. * floating-point type, use SDL_round.
  3406. *
  3407. * \param x floating point value.
  3408. * \returns the nearest integer to `x`.
  3409. *
  3410. * \threadsafety It is safe to call this function from any thread.
  3411. *
  3412. * \since This function is available since SDL 3.0.0.
  3413. *
  3414. * \sa SDL_lroundf
  3415. * \sa SDL_round
  3416. * \sa SDL_floor
  3417. * \sa SDL_ceil
  3418. * \sa SDL_trunc
  3419. */
  3420. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  3421. /**
  3422. * Round `x` to the nearest integer representable as a long
  3423. *
  3424. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3425. * rounded away from zero.
  3426. *
  3427. * Domain: `-INF <= x <= INF`
  3428. *
  3429. * Range: `MIN_LONG <= y <= MAX_LONG`
  3430. *
  3431. * This function operates on single-precision floating point values, use
  3432. * SDL_lroundf for double-precision floats. To get the result as a
  3433. * floating-point type, use SDL_roundf,
  3434. *
  3435. * \param x floating point value.
  3436. * \returns the nearest integer to `x`.
  3437. *
  3438. * \threadsafety It is safe to call this function from any thread.
  3439. *
  3440. * \since This function is available since SDL 3.0.0.
  3441. *
  3442. * \sa SDL_lround
  3443. * \sa SDL_roundf
  3444. * \sa SDL_floorf
  3445. * \sa SDL_ceilf
  3446. * \sa SDL_truncf
  3447. */
  3448. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  3449. /**
  3450. * Scale `x` by an integer power of two.
  3451. *
  3452. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  3453. *
  3454. * Domain: `-INF <= x <= INF`, `n` integer
  3455. *
  3456. * Range: `-INF <= y <= INF`
  3457. *
  3458. * This function operates on double-precision floating point values, use
  3459. * SDL_scalbnf for single-precision floats.
  3460. *
  3461. * \param x floating point value to be scaled.
  3462. * \param n integer exponent.
  3463. * \returns `x * 2^n`.
  3464. *
  3465. * \threadsafety It is safe to call this function from any thread.
  3466. *
  3467. * \since This function is available since SDL 3.0.0.
  3468. *
  3469. * \sa SDL_scalbnf
  3470. * \sa SDL_pow
  3471. */
  3472. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  3473. /**
  3474. * Scale `x` by an integer power of two.
  3475. *
  3476. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  3477. *
  3478. * Domain: `-INF <= x <= INF`, `n` integer
  3479. *
  3480. * Range: `-INF <= y <= INF`
  3481. *
  3482. * This function operates on single-precision floating point values, use
  3483. * SDL_scalbn for double-precision floats.
  3484. *
  3485. * \param x floating point value to be scaled.
  3486. * \param n integer exponent.
  3487. * \returns `x * 2^n`.
  3488. *
  3489. * \threadsafety It is safe to call this function from any thread.
  3490. *
  3491. * \since This function is available since SDL 3.0.0.
  3492. *
  3493. * \sa SDL_scalbn
  3494. * \sa SDL_powf
  3495. */
  3496. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  3497. /**
  3498. * Compute the sine of `x`.
  3499. *
  3500. * Domain: `-INF <= x <= INF`
  3501. *
  3502. * Range: `-1 <= y <= 1`
  3503. *
  3504. * This function operates on double-precision floating point values, use
  3505. * SDL_sinf for single-precision floats.
  3506. *
  3507. * This function may use a different approximation across different versions,
  3508. * platforms and configurations. i.e, it can return a different value given
  3509. * the same input on different machines or operating systems, or if SDL is
  3510. * updated.
  3511. *
  3512. * \param x floating point value, in radians.
  3513. * \returns sine of `x`.
  3514. *
  3515. * \threadsafety It is safe to call this function from any thread.
  3516. *
  3517. * \since This function is available since SDL 3.0.0.
  3518. *
  3519. * \sa SDL_sinf
  3520. * \sa SDL_asin
  3521. * \sa SDL_cos
  3522. */
  3523. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  3524. /**
  3525. * Compute the sine of `x`.
  3526. *
  3527. * Domain: `-INF <= x <= INF`
  3528. *
  3529. * Range: `-1 <= y <= 1`
  3530. *
  3531. * This function operates on single-precision floating point values, use
  3532. * SDL_sinf for double-precision floats.
  3533. *
  3534. * This function may use a different approximation across different versions,
  3535. * platforms and configurations. i.e, it can return a different value given
  3536. * the same input on different machines or operating systems, or if SDL is
  3537. * updated.
  3538. *
  3539. * \param x floating point value, in radians.
  3540. * \returns sine of `x`.
  3541. *
  3542. * \threadsafety It is safe to call this function from any thread.
  3543. *
  3544. * \since This function is available since SDL 3.0.0.
  3545. *
  3546. * \sa SDL_sin
  3547. * \sa SDL_asinf
  3548. * \sa SDL_cosf
  3549. */
  3550. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  3551. /**
  3552. * Compute the square root of `x`.
  3553. *
  3554. * Domain: `0 <= x <= INF`
  3555. *
  3556. * Range: `0 <= y <= INF`
  3557. *
  3558. * This function operates on double-precision floating point values, use
  3559. * SDL_sqrtf for single-precision floats.
  3560. *
  3561. * This function may use a different approximation across different versions,
  3562. * platforms and configurations. i.e, it can return a different value given
  3563. * the same input on different machines or operating systems, or if SDL is
  3564. * updated.
  3565. *
  3566. * \param x floating point value. Must be greater than or equal to 0.
  3567. * \returns square root of `x`.
  3568. *
  3569. * \threadsafety It is safe to call this function from any thread.
  3570. *
  3571. * \since This function is available since SDL 3.0.0.
  3572. *
  3573. * \sa SDL_sqrtf
  3574. */
  3575. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  3576. /**
  3577. * Compute the square root of `x`.
  3578. *
  3579. * Domain: `0 <= x <= INF`
  3580. *
  3581. * Range: `0 <= y <= INF`
  3582. *
  3583. * This function operates on single-precision floating point values, use
  3584. * SDL_sqrt for double-precision floats.
  3585. *
  3586. * This function may use a different approximation across different versions,
  3587. * platforms and configurations. i.e, it can return a different value given
  3588. * the same input on different machines or operating systems, or if SDL is
  3589. * updated.
  3590. *
  3591. * \param x floating point value. Must be greater than or equal to 0.
  3592. * \returns square root of `x`.
  3593. *
  3594. * \threadsafety It is safe to call this function from any thread.
  3595. *
  3596. * \since This function is available since SDL 3.0.0.
  3597. *
  3598. * \sa SDL_sqrt
  3599. */
  3600. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  3601. /**
  3602. * Compute the tangent of `x`.
  3603. *
  3604. * Domain: `-INF <= x <= INF`
  3605. *
  3606. * Range: `-INF <= y <= INF`
  3607. *
  3608. * This function operates on double-precision floating point values, use
  3609. * SDL_tanf for single-precision floats.
  3610. *
  3611. * This function may use a different approximation across different versions,
  3612. * platforms and configurations. i.e, it can return a different value given
  3613. * the same input on different machines or operating systems, or if SDL is
  3614. * updated.
  3615. *
  3616. * \param x floating point value, in radians.
  3617. * \returns tangent of `x`.
  3618. *
  3619. * \threadsafety It is safe to call this function from any thread.
  3620. *
  3621. * \since This function is available since SDL 3.0.0.
  3622. *
  3623. * \sa SDL_tanf
  3624. * \sa SDL_sin
  3625. * \sa SDL_cos
  3626. * \sa SDL_atan
  3627. * \sa SDL_atan2
  3628. */
  3629. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  3630. /**
  3631. * Compute the tangent of `x`.
  3632. *
  3633. * Domain: `-INF <= x <= INF`
  3634. *
  3635. * Range: `-INF <= y <= INF`
  3636. *
  3637. * This function operates on single-precision floating point values, use
  3638. * SDL_tanf for double-precision floats.
  3639. *
  3640. * This function may use a different approximation across different versions,
  3641. * platforms and configurations. i.e, it can return a different value given
  3642. * the same input on different machines or operating systems, or if SDL is
  3643. * updated.
  3644. *
  3645. * \param x floating point value, in radians.
  3646. * \returns tangent of `x`.
  3647. *
  3648. * \threadsafety It is safe to call this function from any thread.
  3649. *
  3650. * \since This function is available since SDL 3.0.0.
  3651. *
  3652. * \sa SDL_tan
  3653. * \sa SDL_sinf
  3654. * \sa SDL_cosf
  3655. * \sa SDL_atanf
  3656. * \sa SDL_atan2f
  3657. */
  3658. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  3659. /* The SDL implementation of iconv() returns these error codes */
  3660. #define SDL_ICONV_ERROR (size_t)-1
  3661. #define SDL_ICONV_E2BIG (size_t)-2
  3662. #define SDL_ICONV_EILSEQ (size_t)-3
  3663. #define SDL_ICONV_EINVAL (size_t)-4
  3664. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  3665. /**
  3666. * This function allocates a context for the specified character set
  3667. * conversion.
  3668. *
  3669. * \param tocode The target character encoding, must not be NULL.
  3670. * \param fromcode The source character encoding, must not be NULL.
  3671. * \returns a handle that must be freed with SDL_iconv_close, or
  3672. * SDL_ICONV_ERROR on failure.
  3673. *
  3674. * \since This function is available since SDL 3.0.0.
  3675. *
  3676. * \sa SDL_iconv
  3677. * \sa SDL_iconv_close
  3678. * \sa SDL_iconv_string
  3679. */
  3680. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  3681. const char *fromcode);
  3682. /**
  3683. * This function frees a context used for character set conversion.
  3684. *
  3685. * \param cd The character set conversion handle.
  3686. * \returns 0 on success, or -1 on failure.
  3687. *
  3688. * \since This function is available since SDL 3.0.0.
  3689. *
  3690. * \sa SDL_iconv
  3691. * \sa SDL_iconv_open
  3692. * \sa SDL_iconv_string
  3693. */
  3694. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  3695. /**
  3696. * This function converts text between encodings, reading from and writing to
  3697. * a buffer.
  3698. *
  3699. * It returns the number of succesful conversions.
  3700. *
  3701. * \param cd The character set conversion context, created in
  3702. * SDL_iconv_open().
  3703. * \param inbuf Address of variable that points to the first character of the
  3704. * input sequence.
  3705. * \param inbytesleft The number of bytes in the input buffer.
  3706. * \param outbuf Address of variable that points to the output buffer.
  3707. * \param outbytesleft The number of bytes in the output buffer.
  3708. * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
  3709. * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
  3710. * is returned when an invalid input sequence is encountered, or
  3711. * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  3712. * encountered.
  3713. *
  3714. * On exit:
  3715. *
  3716. * - inbuf will point to the beginning of the next multibyte
  3717. * sequence. On error, this is the location of the problematic
  3718. * input sequence. On success, this is the end of the input
  3719. * sequence. - inbytesleft will be set to the number of bytes left
  3720. * to convert, which will be 0 on success. - outbuf will point to
  3721. * the location where to store the next output byte. - outbytesleft
  3722. * will be set to the number of bytes left in the output buffer.
  3723. *
  3724. * \since This function is available since SDL 3.0.0.
  3725. *
  3726. * \sa SDL_iconv_open
  3727. * \sa SDL_iconv_close
  3728. * \sa SDL_iconv_string
  3729. */
  3730. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  3731. size_t *inbytesleft, char **outbuf,
  3732. size_t *outbytesleft);
  3733. /**
  3734. * Helper function to convert a string's encoding in one call.
  3735. *
  3736. * This function converts a buffer or string between encodings in one pass.
  3737. *
  3738. * The string does not need to be NULL-terminated; this function operates on
  3739. * the number of bytes specified in `inbytesleft` whether there is a NULL
  3740. * character anywhere in the buffer.
  3741. *
  3742. * The returned string is owned by the caller, and should be passed to
  3743. * SDL_free when no longer needed.
  3744. *
  3745. * \param tocode the character encoding of the output string. Examples are
  3746. * "UTF-8", "UCS-4", etc.
  3747. * \param fromcode the character encoding of data in `inbuf`.
  3748. * \param inbuf the string to convert to a different encoding.
  3749. * \param inbytesleft the size of the input string _in bytes_.
  3750. * \returns a new string, converted to the new encoding, or NULL on error.
  3751. *
  3752. * \since This function is available since SDL 3.0.0.
  3753. *
  3754. * \sa SDL_iconv_open
  3755. * \sa SDL_iconv_close
  3756. * \sa SDL_iconv
  3757. */
  3758. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  3759. const char *fromcode,
  3760. const char *inbuf,
  3761. size_t inbytesleft);
  3762. /* Some helper macros for common cases... */
  3763. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  3764. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  3765. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  3766. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  3767. /* force builds using Clang's static analysis tools to use literal C runtime
  3768. here, since there are possibly tests that are ineffective otherwise. */
  3769. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  3770. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  3771. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  3772. size_t strlcpy(char *dst, const char *src, size_t size);
  3773. #endif
  3774. /* The analyzer knows about strlcat even when the system doesn't provide it */
  3775. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  3776. size_t strlcat(char *dst, const char *src, size_t size);
  3777. #endif
  3778. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  3779. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  3780. #endif
  3781. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  3782. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  3783. #endif
  3784. /* Starting LLVM 16, the analyser errors out if these functions do not have
  3785. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  3786. #include <stdio.h>
  3787. #include <stdlib.h>
  3788. #include <strings.h>
  3789. #define SDL_malloc malloc
  3790. #define SDL_calloc calloc
  3791. #define SDL_realloc realloc
  3792. #define SDL_free free
  3793. #ifndef SDL_memcpy
  3794. #define SDL_memcpy memcpy
  3795. #endif
  3796. #ifndef SDL_memmove
  3797. #define SDL_memmove memmove
  3798. #endif
  3799. #ifndef SDL_memset
  3800. #define SDL_memset memset
  3801. #endif
  3802. #define SDL_memcmp memcmp
  3803. #define SDL_strlcpy strlcpy
  3804. #define SDL_strlcat strlcat
  3805. #define SDL_strlen strlen
  3806. #define SDL_wcslen wcslen
  3807. #define SDL_wcslcpy wcslcpy
  3808. #define SDL_wcslcat wcslcat
  3809. #define SDL_strdup strdup
  3810. #define SDL_wcsdup wcsdup
  3811. #define SDL_strchr strchr
  3812. #define SDL_strrchr strrchr
  3813. #define SDL_strstr strstr
  3814. #define SDL_wcsstr wcsstr
  3815. #define SDL_strtok_r strtok_r
  3816. #define SDL_strcmp strcmp
  3817. #define SDL_wcscmp wcscmp
  3818. #define SDL_strncmp strncmp
  3819. #define SDL_wcsncmp wcsncmp
  3820. #define SDL_strcasecmp strcasecmp
  3821. #define SDL_strncasecmp strncasecmp
  3822. #define SDL_strpbrk strpbrk
  3823. #define SDL_sscanf sscanf
  3824. #define SDL_vsscanf vsscanf
  3825. #define SDL_snprintf snprintf
  3826. #define SDL_vsnprintf vsnprintf
  3827. #endif
  3828. /**
  3829. * Multiply two integers, checking for overflow.
  3830. *
  3831. * If `a * b` would overflow, return SDL_FALSE.
  3832. *
  3833. * Otherwise store `a * b` via ret and return SDL_TRUE.
  3834. *
  3835. * \param a the multiplicand.
  3836. * \param b the multiplier.
  3837. * \param ret on non-overflow output, stores the multiplication result. May
  3838. * not be NULL.
  3839. * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without
  3840. * overflow.
  3841. *
  3842. * \threadsafety It is safe to call this function from any thread.
  3843. *
  3844. * \since This function is available since SDL 3.0.0.
  3845. */
  3846. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  3847. {
  3848. if (a != 0 && b > SDL_SIZE_MAX / a) {
  3849. return SDL_FALSE;
  3850. }
  3851. *ret = a * b;
  3852. return SDL_TRUE;
  3853. }
  3854. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3855. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  3856. /* This needs to be wrapped in an inline rather than being a direct #define,
  3857. * because __builtin_mul_overflow() is type-generic, but we want to be
  3858. * consistent about interpreting a and b as size_t. */
  3859. SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3860. {
  3861. return (__builtin_mul_overflow(a, b, ret) == 0);
  3862. }
  3863. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  3864. #endif
  3865. #endif
  3866. /**
  3867. * Add two integers, checking for overflow.
  3868. *
  3869. * If `a + b` would overflow, return -1.
  3870. *
  3871. * Otherwise store `a + b` via ret and return 0.
  3872. *
  3873. * \param a the first addend.
  3874. * \param b the second addend.
  3875. * \param ret on non-overflow output, stores the addition result. May not be
  3876. * NULL.
  3877. * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without
  3878. * overflow.
  3879. *
  3880. * \threadsafety It is safe to call this function from any thread.
  3881. *
  3882. * \since This function is available since SDL 3.0.0.
  3883. */
  3884. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  3885. {
  3886. if (b > SDL_SIZE_MAX - a) {
  3887. return SDL_FALSE;
  3888. }
  3889. *ret = a + b;
  3890. return SDL_TRUE;
  3891. }
  3892. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3893. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  3894. /* This needs to be wrapped in an inline rather than being a direct #define,
  3895. * the same as the call to __builtin_mul_overflow() above. */
  3896. SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3897. {
  3898. return (__builtin_add_overflow(a, b, ret) == 0);
  3899. }
  3900. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  3901. #endif
  3902. #endif
  3903. /* This is a generic function pointer which should be cast to the type you expect */
  3904. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  3905. /**
  3906. * A generic function pointer.
  3907. *
  3908. * In theory, generic function pointers should use this, instead of `void *`,
  3909. * since some platforms could treat code addresses differently than data
  3910. * addresses. Although in current times no popular platforms make this
  3911. * distinction, it is more correct and portable to use the correct type for a
  3912. * generic pointer.
  3913. *
  3914. * If for some reason you need to force this typedef to be an actual `void *`,
  3915. * perhaps to work around a compiler or existing code, you can define
  3916. * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
  3917. *
  3918. * \since This datatype is available since SDL 3.0.0.
  3919. */
  3920. typedef void (*SDL_FunctionPointer)(void);
  3921. #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
  3922. typedef void *SDL_FunctionPointer;
  3923. #else
  3924. typedef void (*SDL_FunctionPointer)(void);
  3925. #endif
  3926. /* Ends C function definitions when using C++ */
  3927. #ifdef __cplusplus
  3928. }
  3929. #endif
  3930. #include <SDL3/SDL_close_code.h>
  3931. #endif /* SDL_stdinc_h_ */