SDL_stdinc.h 140 KB

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