SDL_stdinc.h 145 KB

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