SDL_stdinc.h 140 KB

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