SDL_stdinc.h 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. * SDL provides its own implementation of some of the most important C runtime
  22. * functions.
  23. *
  24. * Using these functions allows an app to have access to common C
  25. * functionality without depending on a specific C runtime (or a C runtime at
  26. * all). More importantly, the SDL implementations work identically across
  27. * platforms, so apps can avoid surprises like snprintf() behaving differently
  28. * between Windows and Linux builds, or itoa() only existing on some
  29. * platforms.
  30. *
  31. * For many of the most common functions, like SDL_memcpy, SDL might just call
  32. * through to the usual C runtime behind the scenes, if it makes sense to do
  33. * so (if it's faster and always available/reliable on a given platform),
  34. * reducing library size and offering the most optimized option.
  35. *
  36. * SDL also offers other C-runtime-adjacent functionality in this header that
  37. * either isn't, strictly speaking, part of any C runtime standards, like
  38. * SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better
  39. * options, like SDL_strlcpy(), which functions as a safer form of strcpy().
  40. */
  41. #ifndef SDL_stdinc_h_
  42. #define SDL_stdinc_h_
  43. #include <SDL3/SDL_platform_defines.h>
  44. #include <stdarg.h>
  45. #include <stdint.h>
  46. #include <string.h>
  47. #include <wchar.h>
  48. #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  49. defined(SDL_INCLUDE_INTTYPES_H)
  50. #include <inttypes.h>
  51. #endif
  52. #ifndef __cplusplus
  53. #if defined(__has_include) && !defined(SDL_INCLUDE_STDBOOL_H)
  54. #if __has_include(<stdbool.h>)
  55. #define SDL_INCLUDE_STDBOOL_H
  56. #endif
  57. #endif
  58. #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  59. (defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \
  60. defined(SDL_INCLUDE_STDBOOL_H)
  61. #include <stdbool.h>
  62. #elif !defined(__bool_true_false_are_defined) && !defined(bool)
  63. #define bool unsigned char
  64. #define false 0
  65. #define true 1
  66. #define __bool_true_false_are_defined 1
  67. #endif
  68. #endif /* !__cplusplus */
  69. #ifndef SDL_DISABLE_ALLOCA
  70. # ifndef alloca
  71. # ifdef HAVE_ALLOCA_H
  72. # include <alloca.h>
  73. # elif defined(SDL_PLATFORM_NETBSD)
  74. # if defined(__STRICT_ANSI__)
  75. # define SDL_DISABLE_ALLOCA
  76. # else
  77. # include <stdlib.h>
  78. # endif
  79. # elif defined(__GNUC__)
  80. # define alloca __builtin_alloca
  81. # elif defined(_MSC_VER)
  82. # include <malloc.h>
  83. # define alloca _alloca
  84. # elif defined(__WATCOMC__)
  85. # include <malloc.h>
  86. # elif defined(__BORLANDC__)
  87. # include <malloc.h>
  88. # elif defined(__DMC__)
  89. # include <stdlib.h>
  90. # elif defined(SDL_PLATFORM_AIX)
  91. # pragma alloca
  92. # elif defined(__MRC__)
  93. void *alloca(unsigned);
  94. # else
  95. void *alloca(size_t);
  96. # endif
  97. # endif
  98. #endif
  99. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  100. /**
  101. * The largest value that a `size_t` can hold for the target platform.
  102. *
  103. * `size_t` is generally the same size as a pointer in modern times, but this
  104. * can get weird on very old and very esoteric machines. For example, on a
  105. * 16-bit Intel 286, you might have a 32-bit "far" pointer (16-bit segment
  106. * plus 16-bit offset), but `size_t` is 16 bits, because it can only deal with
  107. * the offset into an individual segment.
  108. *
  109. * In modern times, it's generally expected to cover an entire linear address
  110. * space. But be careful!
  111. *
  112. * \since This macro is available since SDL 3.1.3.
  113. */
  114. #define SDL_SIZE_MAX SIZE_MAX
  115. #elif defined(SIZE_MAX)
  116. # define SDL_SIZE_MAX SIZE_MAX
  117. #else
  118. # define SDL_SIZE_MAX ((size_t) -1)
  119. #endif
  120. #ifndef SDL_COMPILE_TIME_ASSERT
  121. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  122. /**
  123. * A compile-time assertion.
  124. *
  125. * This can check constant values _known to the compiler at build time_ for
  126. * correctness, and end the compile with the error if they fail.
  127. *
  128. * Often times these are used to verify basic truths, like the size of a
  129. * datatype is what is expected:
  130. *
  131. * ```c
  132. * SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
  133. * ```
  134. *
  135. * The `name` parameter must be a valid C symbol, and must be unique across
  136. * all compile-time asserts in the same compilation unit (one run of the
  137. * compiler), or the build might fail with cryptic errors on some targets.
  138. * This is used with a C language trick that works on older compilers that
  139. * don't support better assertion techniques.
  140. *
  141. * If you need an assertion that operates at runtime, on variable data, you
  142. * should try SDL_assert instead.
  143. *
  144. * \param name a unique identifier for this assertion.
  145. * \param x the value to test. Must be a boolean value.
  146. *
  147. * \threadsafety This macro doesn't generate any code to run.
  148. *
  149. * \since This macro is available since SDL 3.1.3.
  150. *
  151. * \sa SDL_assert
  152. */
  153. #define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
  154. #elif defined(__cplusplus)
  155. /* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
  156. #if (__cplusplus >= 201103L)
  157. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  158. #endif
  159. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
  160. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  161. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  162. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  163. #endif
  164. #endif /* !SDL_COMPILE_TIME_ASSERT */
  165. #ifndef SDL_COMPILE_TIME_ASSERT
  166. /* universal, but may trigger -Wunused-local-typedefs */
  167. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  168. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  169. #endif
  170. /**
  171. * The number of elements in a static array.
  172. *
  173. * This will compile but return incorrect results for a pointer to an array;
  174. * it has to be an array the compiler knows the size of.
  175. *
  176. * This macro looks like it double-evaluates the argument, but it does so
  177. * inside of `sizeof`, so there are no side-effects here, as expressions do
  178. * not actually run any code in these cases.
  179. *
  180. * \since This macro is available since SDL 3.1.3.
  181. */
  182. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  183. /**
  184. * Macro useful for building other macros with strings in them.
  185. *
  186. * For example:
  187. *
  188. * ```c
  189. * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
  190. * ```
  191. *
  192. * \param arg the text to turn into a string literal.
  193. *
  194. * \since This macro is available since SDL 3.1.3.
  195. */
  196. #define SDL_STRINGIFY_ARG(arg) #arg
  197. /**
  198. * \name Cast operators
  199. *
  200. * Use proper C++ casts when compiled as C++ to be compatible with the option
  201. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  202. */
  203. /* @{ */
  204. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  205. /**
  206. * Handle a Reinterpret Cast properly whether using C or C++.
  207. *
  208. * If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
  209. *
  210. * If compiled as C, this macro does a normal C-style cast.
  211. *
  212. * This is helpful to avoid compiler warnings in C++.
  213. *
  214. * \param type the type to cast the expression to.
  215. * \param expression the expression to cast to a different type.
  216. * \returns `expression`, cast to `type`.
  217. *
  218. * \threadsafety It is safe to call this macro from any thread.
  219. *
  220. * \since This macro is available since SDL 3.1.3.
  221. *
  222. * \sa SDL_static_cast
  223. * \sa SDL_const_cast
  224. */
  225. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
  226. /**
  227. * Handle a Static Cast properly whether using C or C++.
  228. *
  229. * If compiled as C++, this macro offers a proper C++ static_cast<>.
  230. *
  231. * If compiled as C, this macro does a normal C-style cast.
  232. *
  233. * This is helpful to avoid compiler warnings in C++.
  234. *
  235. * \param type the type to cast the expression to.
  236. * \param expression the expression to cast to a different type.
  237. * \returns `expression`, cast to `type`.
  238. *
  239. * \threadsafety It is safe to call this macro from any thread.
  240. *
  241. * \since This macro is available since SDL 3.1.3.
  242. *
  243. * \sa SDL_reinterpret_cast
  244. * \sa SDL_const_cast
  245. */
  246. #define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
  247. /**
  248. * Handle a Const Cast properly whether using C or C++.
  249. *
  250. * If compiled as C++, this macro offers a proper C++ const_cast<>.
  251. *
  252. * If compiled as C, this macro does a normal C-style cast.
  253. *
  254. * This is helpful to avoid compiler warnings in C++.
  255. *
  256. * \param type the type to cast the expression to.
  257. * \param expression the expression to cast to a different type.
  258. * \returns `expression`, cast to `type`.
  259. *
  260. * \threadsafety It is safe to call this macro from any thread.
  261. *
  262. * \since This macro is available since SDL 3.1.3.
  263. *
  264. * \sa SDL_reinterpret_cast
  265. * \sa SDL_static_cast
  266. */
  267. #define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
  268. #elif defined(__cplusplus)
  269. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  270. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  271. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  272. #else
  273. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  274. #define SDL_static_cast(type, expression) ((type)(expression))
  275. #define SDL_const_cast(type, expression) ((type)(expression))
  276. #endif
  277. /* @} *//* Cast operators */
  278. /**
  279. * Define a four character code as a Uint32.
  280. *
  281. * \param A the first ASCII character.
  282. * \param B the second ASCII character.
  283. * \param C the third ASCII character.
  284. * \param D the fourth ASCII character.
  285. * \returns the four characters converted into a Uint32, one character
  286. * per-byte.
  287. *
  288. * \threadsafety It is safe to call this macro from any thread.
  289. *
  290. * \since This macro is available since SDL 3.1.3.
  291. */
  292. #define SDL_FOURCC(A, B, C, D) \
  293. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  294. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  295. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  296. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  297. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  298. /**
  299. * Append the 64 bit integer suffix to a signed integer literal.
  300. *
  301. * This helps compilers that might believe a integer literal larger than
  302. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
  303. * instead of `0xFFFFFFFF1` by itself.
  304. *
  305. * \since This macro is available since SDL 3.1.3.
  306. *
  307. * \sa SDL_UINT64_C
  308. */
  309. #define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
  310. /**
  311. * Append the 64 bit integer suffix to an unsigned integer literal.
  312. *
  313. * This helps compilers that might believe a integer literal larger than
  314. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
  315. * instead of `0xFFFFFFFF1` by itself.
  316. *
  317. * \since This macro is available since SDL 3.1.3.
  318. *
  319. * \sa SDL_SINT64_C
  320. */
  321. #define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
  322. #else /* !SDL_WIKI_DOCUMENTATION_SECTION */
  323. #ifndef SDL_SINT64_C
  324. #if defined(INT64_C)
  325. #define SDL_SINT64_C(c) INT64_C(c)
  326. #elif defined(_MSC_VER)
  327. #define SDL_SINT64_C(c) c ## i64
  328. #elif defined(__LP64__) || defined(_LP64)
  329. #define SDL_SINT64_C(c) c ## L
  330. #else
  331. #define SDL_SINT64_C(c) c ## LL
  332. #endif
  333. #endif /* !SDL_SINT64_C */
  334. #ifndef SDL_UINT64_C
  335. #if defined(UINT64_C)
  336. #define SDL_UINT64_C(c) UINT64_C(c)
  337. #elif defined(_MSC_VER)
  338. #define SDL_UINT64_C(c) c ## ui64
  339. #elif defined(__LP64__) || defined(_LP64)
  340. #define SDL_UINT64_C(c) c ## UL
  341. #else
  342. #define SDL_UINT64_C(c) c ## ULL
  343. #endif
  344. #endif /* !SDL_UINT64_C */
  345. #endif /* !SDL_WIKI_DOCUMENTATION_SECTION */
  346. /**
  347. * \name Basic data types
  348. */
  349. /* @{ */
  350. /**
  351. * A signed 8-bit integer type.
  352. *
  353. * \since This macro is available since SDL 3.1.3.
  354. */
  355. typedef int8_t Sint8;
  356. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  357. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  358. /**
  359. * An unsigned 8-bit integer type.
  360. *
  361. * \since This macro is available since SDL 3.1.3.
  362. */
  363. typedef uint8_t Uint8;
  364. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  365. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  366. /**
  367. * A signed 16-bit integer type.
  368. *
  369. * \since This macro is available since SDL 3.1.3.
  370. */
  371. typedef int16_t Sint16;
  372. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  373. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  374. /**
  375. * An unsigned 16-bit integer type.
  376. *
  377. * \since This macro is available since SDL 3.1.3.
  378. */
  379. typedef uint16_t Uint16;
  380. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  381. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  382. /**
  383. * A signed 32-bit integer type.
  384. *
  385. * \since This macro is available since SDL 3.1.3.
  386. */
  387. typedef int32_t Sint32;
  388. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  389. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  390. /**
  391. * An unsigned 32-bit integer type.
  392. *
  393. * \since This macro is available since SDL 3.1.3.
  394. */
  395. typedef uint32_t Uint32;
  396. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  397. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  398. /**
  399. * A signed 64-bit integer type.
  400. *
  401. * \since This macro is available since SDL 3.1.3.
  402. *
  403. * \sa SDL_SINT64_C
  404. */
  405. typedef int64_t Sint64;
  406. #define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
  407. #define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
  408. /**
  409. * An unsigned 64-bit integer type.
  410. *
  411. * \since This macro is available since SDL 3.1.3.
  412. *
  413. * \sa SDL_UINT64_C
  414. */
  415. typedef uint64_t Uint64;
  416. #define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
  417. #define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
  418. /**
  419. * SDL times are signed, 64-bit integers representing nanoseconds since the
  420. * Unix epoch (Jan 1, 1970).
  421. *
  422. * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
  423. * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
  424. * SDL_TimeToWindows() and SDL_TimeFromWindows().
  425. *
  426. * \since This macro is available since SDL 3.1.3.
  427. *
  428. * \sa SDL_MAX_SINT64
  429. * \sa SDL_MIN_SINT64
  430. */
  431. typedef Sint64 SDL_Time;
  432. #define SDL_MAX_TIME SDL_MAX_SINT64
  433. #define SDL_MIN_TIME SDL_MIN_SINT64
  434. /* @} *//* Basic data types */
  435. /**
  436. * \name Floating-point constants
  437. */
  438. /* @{ */
  439. #ifdef FLT_EPSILON
  440. #define SDL_FLT_EPSILON FLT_EPSILON
  441. #else
  442. /**
  443. * Epsilon constant, used for comparing floating-point numbers.
  444. *
  445. * Equals by default to platform-defined `FLT_EPSILON`, or
  446. * `1.1920928955078125e-07F` if that's not available.
  447. *
  448. * \since This macro is available since SDL 3.1.3.
  449. */
  450. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  451. #endif
  452. /* @} *//* Floating-point constants */
  453. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  454. /**
  455. * A printf-formatting string for an Sint64 value.
  456. *
  457. * Use it like this:
  458. *
  459. * ```c
  460. * SDL_Log("There are %" SDL_PRIs64 " bottles of beer on the wall.", bottles);
  461. * ```
  462. *
  463. * \since This macro is available since SDL 3.1.3.
  464. */
  465. #define SDL_PRIs64 "lld"
  466. /**
  467. * A printf-formatting string for a Uint64 value.
  468. *
  469. * Use it like this:
  470. *
  471. * ```c
  472. * SDL_Log("There are %" SDL_PRIu64 " bottles of beer on the wall.", bottles);
  473. * ```
  474. *
  475. * \since This macro is available since SDL 3.1.3.
  476. */
  477. #define SDL_PRIu64 "llu"
  478. /**
  479. * A printf-formatting string for a Uint64 value as lower-case hexadecimal.
  480. *
  481. * Use it like this:
  482. *
  483. * ```c
  484. * SDL_Log("There are %" SDL_PRIx64 " bottles of beer on the wall.", bottles);
  485. * ```
  486. *
  487. * \since This macro is available since SDL 3.1.3.
  488. */
  489. #define SDL_PRIx64 "llx"
  490. /**
  491. * A printf-formatting string for a Uint64 value as upper-case hexadecimal.
  492. *
  493. * Use it like this:
  494. *
  495. * ```c
  496. * SDL_Log("There are %" SDL_PRIX64 " bottles of beer on the wall.", bottles);
  497. * ```
  498. *
  499. * \since This macro is available since SDL 3.1.3.
  500. */
  501. #define SDL_PRIX64 "llX"
  502. /**
  503. * A printf-formatting string for an Sint32 value.
  504. *
  505. * Use it like this:
  506. *
  507. * ```c
  508. * SDL_Log("There are %" SDL_PRIs32 " bottles of beer on the wall.", bottles);
  509. * ```
  510. *
  511. * \since This macro is available since SDL 3.1.3.
  512. */
  513. #define SDL_PRIs32 "d"
  514. /**
  515. * A printf-formatting string for a Uint32 value.
  516. *
  517. * Use it like this:
  518. *
  519. * ```c
  520. * SDL_Log("There are %" SDL_PRIu32 " bottles of beer on the wall.", bottles);
  521. * ```
  522. *
  523. * \since This macro is available since SDL 3.1.3.
  524. */
  525. #define SDL_PRIu32 "u"
  526. /**
  527. * A printf-formatting string for a Uint32 value as lower-case hexadecimal.
  528. *
  529. * Use it like this:
  530. *
  531. * ```c
  532. * SDL_Log("There are %" SDL_PRIx32 " bottles of beer on the wall.", bottles);
  533. * ```
  534. *
  535. * \since This macro is available since SDL 3.1.3.
  536. */
  537. #define SDL_PRIx32 "x"
  538. /**
  539. * A printf-formatting string for a Uint32 value as upper-case hexadecimal.
  540. *
  541. * Use it like this:
  542. *
  543. * ```c
  544. * SDL_Log("There are %" SDL_PRIX32 " bottles of beer on the wall.", bottles);
  545. * ```
  546. *
  547. * \since This macro is available since SDL 3.1.3.
  548. */
  549. #define SDL_PRIX32 "X"
  550. /**
  551. * A printf-formatting string prefix for a `long long` value.
  552. *
  553. * This is just the prefix! You probably actually want SDL_PRILLd, SDL_PRILLu,
  554. * SDL_PRILLx, or SDL_PRILLX instead.
  555. *
  556. * Use it like this:
  557. *
  558. * ```c
  559. * SDL_Log("There are %" SDL_PRILL_PREFIX "d bottles of beer on the wall.", bottles);
  560. * ```
  561. *
  562. * \since This macro is available since SDL 3.1.3.
  563. */
  564. #define SDL_PRILL_PREFIX "ll"
  565. /**
  566. * A printf-formatting string for a `long long` value.
  567. *
  568. * Use it like this:
  569. *
  570. * ```c
  571. * SDL_Log("There are %" SDL_PRILLd " bottles of beer on the wall.", bottles);
  572. * ```
  573. *
  574. * \since This macro is available since SDL 3.1.3.
  575. */
  576. #define SDL_PRILLd SDL_PRILL_PREFIX "d"
  577. /**
  578. * A printf-formatting string for a `unsigned long long` value.
  579. *
  580. * Use it like this:
  581. *
  582. * ```c
  583. * SDL_Log("There are %" SDL_PRILLu " bottles of beer on the wall.", bottles);
  584. * ```
  585. *
  586. * \since This macro is available since SDL 3.1.3.
  587. */
  588. #define SDL_PRILLu SDL_PRILL_PREFIX "u"
  589. /**
  590. * A printf-formatting string for an `unsigned long long` value as lower-case
  591. * hexadecimal.
  592. *
  593. * Use it like this:
  594. *
  595. * ```c
  596. * SDL_Log("There are %" SDL_PRILLx " bottles of beer on the wall.", bottles);
  597. * ```
  598. *
  599. * \since This macro is available since SDL 3.1.3.
  600. */
  601. #define SDL_PRILLx SDL_PRILL_PREFIX "x"
  602. /**
  603. * A printf-formatting string for an `unsigned long long` value as upper-case
  604. * hexadecimal.
  605. *
  606. * Use it like this:
  607. *
  608. * ```c
  609. * SDL_Log("There are %" SDL_PRILLX " bottles of beer on the wall.", bottles);
  610. * ```
  611. *
  612. * \since This macro is available since SDL 3.1.3.
  613. */
  614. #define SDL_PRILLX SDL_PRILL_PREFIX "X"
  615. #endif /* SDL_WIKI_DOCUMENTATION_SECTION */
  616. /* Make sure we have macros for printing width-based integers.
  617. * <inttypes.h> should define these but this is not true all platforms.
  618. * (for example win32) */
  619. #ifndef SDL_PRIs64
  620. #if defined(SDL_PLATFORM_WINDOWS)
  621. #define SDL_PRIs64 "I64d"
  622. #elif defined(PRId64)
  623. #define SDL_PRIs64 PRId64
  624. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
  625. #define SDL_PRIs64 "ld"
  626. #else
  627. #define SDL_PRIs64 "lld"
  628. #endif
  629. #endif
  630. #ifndef SDL_PRIu64
  631. #if defined(SDL_PLATFORM_WINDOWS)
  632. #define SDL_PRIu64 "I64u"
  633. #elif defined(PRIu64)
  634. #define SDL_PRIu64 PRIu64
  635. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE) && !defined(__EMSCRIPTEN__)
  636. #define SDL_PRIu64 "lu"
  637. #else
  638. #define SDL_PRIu64 "llu"
  639. #endif
  640. #endif
  641. #ifndef SDL_PRIx64
  642. #if defined(SDL_PLATFORM_WINDOWS)
  643. #define SDL_PRIx64 "I64x"
  644. #elif defined(PRIx64)
  645. #define SDL_PRIx64 PRIx64
  646. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  647. #define SDL_PRIx64 "lx"
  648. #else
  649. #define SDL_PRIx64 "llx"
  650. #endif
  651. #endif
  652. #ifndef SDL_PRIX64
  653. #if defined(SDL_PLATFORM_WINDOWS)
  654. #define SDL_PRIX64 "I64X"
  655. #elif defined(PRIX64)
  656. #define SDL_PRIX64 PRIX64
  657. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  658. #define SDL_PRIX64 "lX"
  659. #else
  660. #define SDL_PRIX64 "llX"
  661. #endif
  662. #endif
  663. #ifndef SDL_PRIs32
  664. #ifdef PRId32
  665. #define SDL_PRIs32 PRId32
  666. #else
  667. #define SDL_PRIs32 "d"
  668. #endif
  669. #endif
  670. #ifndef SDL_PRIu32
  671. #ifdef PRIu32
  672. #define SDL_PRIu32 PRIu32
  673. #else
  674. #define SDL_PRIu32 "u"
  675. #endif
  676. #endif
  677. #ifndef SDL_PRIx32
  678. #ifdef PRIx32
  679. #define SDL_PRIx32 PRIx32
  680. #else
  681. #define SDL_PRIx32 "x"
  682. #endif
  683. #endif
  684. #ifndef SDL_PRIX32
  685. #ifdef PRIX32
  686. #define SDL_PRIX32 PRIX32
  687. #else
  688. #define SDL_PRIX32 "X"
  689. #endif
  690. #endif
  691. /* Specifically for the `long long` -- SDL-specific. */
  692. #ifdef SDL_PLATFORM_WINDOWS
  693. SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */
  694. #define SDL_PRILL_PREFIX "I64"
  695. #else
  696. #define SDL_PRILL_PREFIX "ll"
  697. #endif
  698. #ifndef SDL_PRILLd
  699. #define SDL_PRILLd SDL_PRILL_PREFIX "d"
  700. #endif
  701. #ifndef SDL_PRILLu
  702. #define SDL_PRILLu SDL_PRILL_PREFIX "u"
  703. #endif
  704. #ifndef SDL_PRILLx
  705. #define SDL_PRILLx SDL_PRILL_PREFIX "x"
  706. #endif
  707. #ifndef SDL_PRILLX
  708. #define SDL_PRILLX SDL_PRILL_PREFIX "X"
  709. #endif
  710. /* Annotations to help code analysis tools */
  711. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  712. /**
  713. * Macro that annotates function params with input buffer size.
  714. *
  715. * If we were to annotate `memcpy`:
  716. *
  717. * ```c
  718. * void *memcpy(void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  719. * ```
  720. *
  721. * This notes that `src` should be `len` bytes in size and is only read by the
  722. * function. The compiler or other analysis tools can warn when this doesn't
  723. * appear to be the case.
  724. *
  725. * On compilers without this annotation mechanism, this is defined to nothing.
  726. *
  727. * \since This macro is available since SDL 3.1.3.
  728. */
  729. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  730. /**
  731. * Macro that annotates function params with input/output string buffer size.
  732. *
  733. * If we were to annotate `strlcat`:
  734. *
  735. * ```c
  736. * size_t strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  737. * ```
  738. *
  739. * This notes that `dst` is a null-terminated C string, should be `maxlen`
  740. * bytes in size, and is both read from and written to by the function. The
  741. * compiler or other analysis tools can warn when this doesn't appear to be
  742. * the case.
  743. *
  744. * On compilers without this annotation mechanism, this is defined to nothing.
  745. *
  746. * \since This macro is available since SDL 3.1.3.
  747. */
  748. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  749. /**
  750. * Macro that annotates function params with output string buffer size.
  751. *
  752. * If we were to annotate `snprintf`:
  753. *
  754. * ```c
  755. * int snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, ...);
  756. * ```
  757. *
  758. * This notes that `text` is a null-terminated C string, should be `maxlen`
  759. * bytes in size, and is only written to by the function. The compiler or
  760. * other analysis tools can warn when this doesn't appear to be the case.
  761. *
  762. * On compilers without this annotation mechanism, this is defined to nothing.
  763. *
  764. * \since This macro is available since SDL 3.1.3.
  765. */
  766. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  767. /**
  768. * Macro that annotates function params with output buffer size.
  769. *
  770. * If we were to annotate `wcsncpy`:
  771. *
  772. * ```c
  773. * char *wcscpy(SDL_OUT_CAP(bufsize) wchar_t *dst, const wchar_t *src, size_t bufsize);
  774. * ```
  775. *
  776. * This notes that `dst` should have a capacity of `bufsize` wchar_t in size,
  777. * and is only written to by the function. The compiler or other analysis
  778. * tools can warn when this doesn't appear to be the case.
  779. *
  780. * This operates on counts of objects, not bytes. Use SDL_OUT_BYTECAP for
  781. * bytes.
  782. *
  783. * On compilers without this annotation mechanism, this is defined to nothing.
  784. *
  785. * \since This macro is available since SDL 3.1.3.
  786. */
  787. #define SDL_OUT_CAP(x) _Out_cap_(x)
  788. /**
  789. * Macro that annotates function params with output buffer size.
  790. *
  791. * If we were to annotate `memcpy`:
  792. *
  793. * ```c
  794. * void *memcpy(SDL_OUT_BYTECAP(bufsize) void *dst, const void *src, size_t bufsize);
  795. * ```
  796. *
  797. * This notes that `dst` should have a capacity of `bufsize` bytes in size,
  798. * and is only written to by the function. The compiler or other analysis
  799. * tools can warn when this doesn't appear to be the case.
  800. *
  801. * On compilers without this annotation mechanism, this is defined to nothing.
  802. *
  803. * \since This macro is available since SDL 3.1.3.
  804. */
  805. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  806. /**
  807. * Macro that annotates function params with output buffer string size.
  808. *
  809. * If we were to annotate `strcpy`:
  810. *
  811. * ```c
  812. * char *strcpy(SDL_OUT_Z_BYTECAP(bufsize) char *dst, const char *src, size_t bufsize);
  813. * ```
  814. *
  815. * This notes that `dst` should have a capacity of `bufsize` bytes in size,
  816. * and a zero-terminated string is written to it by the function. The compiler
  817. * or other analysis tools can warn when this doesn't appear to be the case.
  818. *
  819. * On compilers without this annotation mechanism, this is defined to nothing.
  820. *
  821. * \since This macro is available since SDL 3.1.3.
  822. */
  823. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  824. /**
  825. * Macro that annotates function params as printf-style format strings.
  826. *
  827. * If we were to annotate `fprintf`:
  828. *
  829. * ```c
  830. * int fprintf(FILE *f, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
  831. * ```
  832. *
  833. * This notes that `fmt` should be a printf-style format string. The compiler
  834. * or other analysis tools can warn when this doesn't appear to be the case.
  835. *
  836. * On compilers without this annotation mechanism, this is defined to nothing.
  837. *
  838. * \since This macro is available since SDL 3.1.3.
  839. */
  840. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  841. /**
  842. * Macro that annotates function params as scanf-style format strings.
  843. *
  844. * If we were to annotate `fscanf`:
  845. *
  846. * ```c
  847. * int fscanf(FILE *f, SDL_SCANF_FORMAT_STRING const char *fmt, ...);
  848. * ```
  849. *
  850. * This notes that `fmt` should be a scanf-style format string. The compiler
  851. * or other analysis tools can warn when this doesn't appear to be the case.
  852. *
  853. * On compilers without this annotation mechanism, this is defined to nothing.
  854. *
  855. * \since This macro is available since SDL 3.1.3.
  856. */
  857. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  858. /**
  859. * Macro that annotates a vararg function that operates like printf.
  860. *
  861. * If we were to annotate `fprintf`:
  862. *
  863. * ```c
  864. * int fprintf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  865. * ```
  866. *
  867. * This notes that the second parameter should be a printf-style format
  868. * string, followed by `...`. The compiler or other analysis tools can warn
  869. * when this doesn't appear to be the case.
  870. *
  871. * On compilers without this annotation mechanism, this is defined to nothing.
  872. *
  873. * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
  874. * between them will cover at least Visual Studio, GCC, and Clang.
  875. *
  876. * \since This macro is available since SDL 3.1.3.
  877. */
  878. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  879. /**
  880. * Macro that annotates a va_list function that operates like printf.
  881. *
  882. * If we were to annotate `vfprintf`:
  883. *
  884. * ```c
  885. * int vfprintf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  886. * ```
  887. *
  888. * This notes that the second parameter should be a printf-style format
  889. * string, followed by a va_list. The compiler or other analysis tools can
  890. * warn when this doesn't appear to be the case.
  891. *
  892. * On compilers without this annotation mechanism, this is defined to nothing.
  893. *
  894. * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
  895. * between them will cover at least Visual Studio, GCC, and Clang.
  896. *
  897. * \since This macro is available since SDL 3.1.3.
  898. */
  899. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
  900. /**
  901. * Macro that annotates a vararg function that operates like scanf.
  902. *
  903. * If we were to annotate `fscanf`:
  904. *
  905. * ```c
  906. * int fscanf(FILE *f, const char *fmt, ...) SDL_PRINTF_VARARG_FUNCV(2);
  907. * ```
  908. *
  909. * This notes that the second parameter should be a scanf-style format string,
  910. * followed by `...`. The compiler or other analysis tools can warn when this
  911. * doesn't appear to be the case.
  912. *
  913. * On compilers without this annotation mechanism, this is defined to nothing.
  914. *
  915. * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
  916. * between them will cover at least Visual Studio, GCC, and Clang.
  917. *
  918. * \since This macro is available since SDL 3.1.3.
  919. */
  920. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  921. /**
  922. * Macro that annotates a va_list function that operates like scanf.
  923. *
  924. * If we were to annotate `vfscanf`:
  925. *
  926. * ```c
  927. * int vfscanf(FILE *f, const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  928. * ```
  929. *
  930. * This notes that the second parameter should be a scanf-style format string,
  931. * followed by a va_list. The compiler or other analysis tools can warn when
  932. * this doesn't appear to be the case.
  933. *
  934. * On compilers without this annotation mechanism, this is defined to nothing.
  935. *
  936. * This can (and should) be used with SDL_SCANF_FORMAT_STRING as well, which
  937. * between them will cover at least Visual Studio, GCC, and Clang.
  938. *
  939. * \since This macro is available since SDL 3.1.3.
  940. */
  941. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
  942. /**
  943. * Macro that annotates a vararg function that operates like wprintf.
  944. *
  945. * If we were to annotate `fwprintf`:
  946. *
  947. * ```c
  948. * int fwprintf(FILE *f, const wchar_t *fmt, ...) SDL_WPRINTF_VARARG_FUNC(2);
  949. * ```
  950. *
  951. * This notes that the second parameter should be a wprintf-style format wide
  952. * string, followed by `...`. The compiler or other analysis tools can warn
  953. * when this doesn't appear to be the case.
  954. *
  955. * On compilers without this annotation mechanism, this is defined to nothing.
  956. *
  957. * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
  958. * between them will cover at least Visual Studio, GCC, and Clang.
  959. *
  960. * \since This macro is available since SDL 3.1.3.
  961. */
  962. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
  963. /**
  964. * Macro that annotates a va_list function that operates like wprintf.
  965. *
  966. * If we were to annotate `vfwprintf`:
  967. *
  968. * ```c
  969. * int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNC(2);
  970. * ```
  971. *
  972. * This notes that the second parameter should be a wprintf-style format wide
  973. * string, followed by a va_list. The compiler or other analysis tools can
  974. * warn when this doesn't appear to be the case.
  975. *
  976. * On compilers without this annotation mechanism, this is defined to nothing.
  977. *
  978. * This can (and should) be used with SDL_PRINTF_FORMAT_STRING as well, which
  979. * between them will cover at least Visual Studio, GCC, and Clang.
  980. *
  981. * \since This macro is available since SDL 3.1.3.
  982. */
  983. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
  984. #elif defined(SDL_DISABLE_ANALYZE_MACROS)
  985. #define SDL_IN_BYTECAP(x)
  986. #define SDL_INOUT_Z_CAP(x)
  987. #define SDL_OUT_Z_CAP(x)
  988. #define SDL_OUT_CAP(x)
  989. #define SDL_OUT_BYTECAP(x)
  990. #define SDL_OUT_Z_BYTECAP(x)
  991. #define SDL_PRINTF_FORMAT_STRING
  992. #define SDL_SCANF_FORMAT_STRING
  993. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  994. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  995. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  996. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  997. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  998. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
  999. #else
  1000. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  1001. #include <sal.h>
  1002. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  1003. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  1004. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  1005. #define SDL_OUT_CAP(x) _Out_cap_(x)
  1006. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  1007. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  1008. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  1009. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  1010. #else
  1011. #define SDL_IN_BYTECAP(x)
  1012. #define SDL_INOUT_Z_CAP(x)
  1013. #define SDL_OUT_Z_CAP(x)
  1014. #define SDL_OUT_CAP(x)
  1015. #define SDL_OUT_BYTECAP(x)
  1016. #define SDL_OUT_Z_BYTECAP(x)
  1017. #define SDL_PRINTF_FORMAT_STRING
  1018. #define SDL_SCANF_FORMAT_STRING
  1019. #endif
  1020. #if defined(__GNUC__) || defined(__clang__)
  1021. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  1022. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
  1023. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  1024. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
  1025. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
  1026. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
  1027. #else
  1028. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  1029. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  1030. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  1031. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  1032. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  1033. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
  1034. #endif
  1035. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  1036. /** \cond */
  1037. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  1038. SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);
  1039. SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1);
  1040. SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1);
  1041. SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2);
  1042. SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2);
  1043. SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
  1044. SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4);
  1045. SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8);
  1046. SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8);
  1047. SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long));
  1048. SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long));
  1049. typedef struct SDL_alignment_test
  1050. {
  1051. Uint8 a;
  1052. void *b;
  1053. } SDL_alignment_test;
  1054. SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
  1055. SDL_COMPILE_TIME_ASSERT(two_s_complement, (int)~(int)0 == (int)(-1));
  1056. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  1057. /** \endcond */
  1058. /* Check to make sure enums are the size of ints, for structure packing.
  1059. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  1060. enums having the size of an int must be enabled.
  1061. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  1062. */
  1063. /** \cond */
  1064. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  1065. #if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
  1066. /* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
  1067. typedef enum SDL_DUMMY_ENUM
  1068. {
  1069. DUMMY_ENUM_VALUE
  1070. } SDL_DUMMY_ENUM;
  1071. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  1072. #endif
  1073. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  1074. /** \endcond */
  1075. #include <SDL3/SDL_begin_code.h>
  1076. /* Set up for C function definitions, even when using C++ */
  1077. #ifdef __cplusplus
  1078. extern "C" {
  1079. #endif
  1080. /**
  1081. * A macro to initialize an SDL interface.
  1082. *
  1083. * This macro will initialize an SDL interface structure and should be called
  1084. * before you fill out the fields with your implementation.
  1085. *
  1086. * You can use it like this:
  1087. *
  1088. * ```c
  1089. * SDL_IOStreamInterface iface;
  1090. *
  1091. * SDL_INIT_INTERFACE(&iface);
  1092. *
  1093. * // Fill in the interface function pointers with your implementation
  1094. * iface.seek = ...
  1095. *
  1096. * stream = SDL_OpenIO(&iface, NULL);
  1097. * ```
  1098. *
  1099. * If you are using designated initializers, you can use the size of the
  1100. * interface as the version, e.g.
  1101. *
  1102. * ```c
  1103. * SDL_IOStreamInterface iface = {
  1104. * .version = sizeof(iface),
  1105. * .seek = ...
  1106. * };
  1107. * stream = SDL_OpenIO(&iface, NULL);
  1108. * ```
  1109. *
  1110. * \threadsafety It is safe to call this macro from any thread.
  1111. *
  1112. * \since This macro is available since SDL 3.1.3.
  1113. *
  1114. * \sa SDL_IOStreamInterface
  1115. * \sa SDL_StorageInterface
  1116. * \sa SDL_VirtualJoystickDesc
  1117. */
  1118. #define SDL_INIT_INTERFACE(iface) \
  1119. do { \
  1120. SDL_zerop(iface); \
  1121. (iface)->version = sizeof(*(iface)); \
  1122. } while (0)
  1123. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  1124. /**
  1125. * Allocate memory on the stack (maybe).
  1126. *
  1127. * If SDL knows how to access alloca() on the current platform, it will use it
  1128. * to stack-allocate memory here. If it doesn't, it will use SDL_malloc() to
  1129. * heap-allocate memory.
  1130. *
  1131. * Since this might not be stack memory at all, it's important that you check
  1132. * the returned pointer for NULL, and that you call SDL_stack_free on the
  1133. * memory when done with it. Since this might be stack memory, it's important
  1134. * that you don't allocate large amounts of it, or allocate in a loop without
  1135. * returning from the function, so the stack doesn't overflow.
  1136. *
  1137. * \param type the datatype of the memory to allocate.
  1138. * \param count the number of `type` objects to allocate.
  1139. * \returns newly-allocated memory, or NULL on failure.
  1140. *
  1141. * \threadsafety It is safe to call this macro from any thread.
  1142. *
  1143. * \since This macro is available since SDL 3.1.3.
  1144. *
  1145. * \sa SDL_stack_free
  1146. */
  1147. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  1148. /**
  1149. * Free memory previously allocated with SDL_stack_alloc.
  1150. *
  1151. * If SDL used alloca() to allocate this memory, this macro does nothing and
  1152. * the allocated memory will be automatically released when the function that
  1153. * called SDL_stack_alloc() returns. If SDL used SDL_malloc(), it will
  1154. * SDL_free the memory immediately.
  1155. *
  1156. * \param data the pointer, from SDL_stack_alloc(), to free.
  1157. *
  1158. * \threadsafety It is safe to call this macro from any thread.
  1159. *
  1160. * \since This macro is available since SDL 3.1.3.
  1161. *
  1162. * \sa SDL_stack_alloc
  1163. */
  1164. #define SDL_stack_free(data)
  1165. #elif !defined(SDL_DISABLE_ALLOCA)
  1166. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  1167. #define SDL_stack_free(data)
  1168. #else
  1169. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  1170. #define SDL_stack_free(data) SDL_free(data)
  1171. #endif
  1172. /**
  1173. * Allocate uninitialized memory.
  1174. *
  1175. * The allocated memory returned by this function must be freed with
  1176. * SDL_free().
  1177. *
  1178. * If `size` is 0, it will be set to 1.
  1179. *
  1180. * If you want to allocate memory aligned to a specific alignment, consider
  1181. * using SDL_aligned_alloc().
  1182. *
  1183. * \param size the size to allocate.
  1184. * \returns a pointer to the allocated memory, or NULL if allocation failed.
  1185. *
  1186. * \threadsafety It is safe to call this function from any thread.
  1187. *
  1188. * \since This function is available since SDL 3.1.3.
  1189. *
  1190. * \sa SDL_free
  1191. * \sa SDL_calloc
  1192. * \sa SDL_realloc
  1193. * \sa SDL_aligned_alloc
  1194. */
  1195. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
  1196. /**
  1197. * Allocate a zero-initialized array.
  1198. *
  1199. * The memory returned by this function must be freed with SDL_free().
  1200. *
  1201. * If either of `nmemb` or `size` is 0, they will both be set to 1.
  1202. *
  1203. * \param nmemb the number of elements in the array.
  1204. * \param size the size of each element of the array.
  1205. * \returns a pointer to the allocated array, or NULL if allocation failed.
  1206. *
  1207. * \threadsafety It is safe to call this function from any thread.
  1208. *
  1209. * \since This function is available since SDL 3.1.3.
  1210. *
  1211. * \sa SDL_free
  1212. * \sa SDL_malloc
  1213. * \sa SDL_realloc
  1214. */
  1215. extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
  1216. /**
  1217. * Change the size of allocated memory.
  1218. *
  1219. * The memory returned by this function must be freed with SDL_free().
  1220. *
  1221. * If `size` is 0, it will be set to 1. Note that this is unlike some other C
  1222. * runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
  1223. * same way as `free(mem)`.
  1224. *
  1225. * If `mem` is NULL, the behavior of this function is equivalent to
  1226. * SDL_malloc(). Otherwise, the function can have one of three possible
  1227. * outcomes:
  1228. *
  1229. * - If it returns the same pointer as `mem`, it means that `mem` was resized
  1230. * in place without freeing.
  1231. * - If it returns a different non-NULL pointer, it means that `mem` was freed
  1232. * and cannot be dereferenced anymore.
  1233. * - If it returns NULL (indicating failure), then `mem` will remain valid and
  1234. * must still be freed with SDL_free().
  1235. *
  1236. * \param mem a pointer to allocated memory to reallocate, or NULL.
  1237. * \param size the new size of the memory.
  1238. * \returns a pointer to the newly allocated memory, or NULL if allocation
  1239. * failed.
  1240. *
  1241. * \threadsafety It is safe to call this function from any thread.
  1242. *
  1243. * \since This function is available since SDL 3.1.3.
  1244. *
  1245. * \sa SDL_free
  1246. * \sa SDL_malloc
  1247. * \sa SDL_calloc
  1248. */
  1249. extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
  1250. /**
  1251. * Free allocated memory.
  1252. *
  1253. * The pointer is no longer valid after this call and cannot be dereferenced
  1254. * anymore.
  1255. *
  1256. * If `mem` is NULL, this function does nothing.
  1257. *
  1258. * \param mem a pointer to allocated memory, or NULL.
  1259. *
  1260. * \threadsafety It is safe to call this function from any thread.
  1261. *
  1262. * \since This function is available since SDL 3.1.3.
  1263. *
  1264. * \sa SDL_malloc
  1265. * \sa SDL_calloc
  1266. * \sa SDL_realloc
  1267. */
  1268. extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
  1269. /**
  1270. * A callback used to implement SDL_malloc().
  1271. *
  1272. * SDL will always ensure that the passed `size` is greater than 0.
  1273. *
  1274. * \param size the size to allocate.
  1275. * \returns a pointer to the allocated memory, or NULL if allocation failed.
  1276. *
  1277. * \threadsafety It should be safe to call this callback from any thread.
  1278. *
  1279. * \since This datatype is available since SDL 3.1.3.
  1280. *
  1281. * \sa SDL_malloc
  1282. * \sa SDL_GetOriginalMemoryFunctions
  1283. * \sa SDL_GetMemoryFunctions
  1284. * \sa SDL_SetMemoryFunctions
  1285. */
  1286. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  1287. /**
  1288. * A callback used to implement SDL_calloc().
  1289. *
  1290. * SDL will always ensure that the passed `nmemb` and `size` are both greater
  1291. * than 0.
  1292. *
  1293. * \param nmemb the number of elements in the array.
  1294. * \param size the size of each element of the array.
  1295. * \returns a pointer to the allocated array, or NULL if allocation failed.
  1296. *
  1297. * \threadsafety It should be safe to call this callback from any thread.
  1298. *
  1299. * \since This datatype is available since SDL 3.1.3.
  1300. *
  1301. * \sa SDL_calloc
  1302. * \sa SDL_GetOriginalMemoryFunctions
  1303. * \sa SDL_GetMemoryFunctions
  1304. * \sa SDL_SetMemoryFunctions
  1305. */
  1306. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  1307. /**
  1308. * A callback used to implement SDL_realloc().
  1309. *
  1310. * SDL will always ensure that the passed `size` is greater than 0.
  1311. *
  1312. * \param mem a pointer to allocated memory to reallocate, or NULL.
  1313. * \param size the new size of the memory.
  1314. * \returns a pointer to the newly allocated memory, or NULL if allocation
  1315. * failed.
  1316. *
  1317. * \threadsafety It should be safe to call this callback from any thread.
  1318. *
  1319. * \since This datatype is available since SDL 3.1.3.
  1320. *
  1321. * \sa SDL_realloc
  1322. * \sa SDL_GetOriginalMemoryFunctions
  1323. * \sa SDL_GetMemoryFunctions
  1324. * \sa SDL_SetMemoryFunctions
  1325. */
  1326. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  1327. /**
  1328. * A callback used to implement SDL_free().
  1329. *
  1330. * SDL will always ensure that the passed `mem` is a non-NULL pointer.
  1331. *
  1332. * \param mem a pointer to allocated memory.
  1333. *
  1334. * \threadsafety It should be safe to call this callback from any thread.
  1335. *
  1336. * \since This datatype is available since SDL 3.1.3.
  1337. *
  1338. * \sa SDL_free
  1339. * \sa SDL_GetOriginalMemoryFunctions
  1340. * \sa SDL_GetMemoryFunctions
  1341. * \sa SDL_SetMemoryFunctions
  1342. */
  1343. typedef void (SDLCALL *SDL_free_func)(void *mem);
  1344. /**
  1345. * Get the original set of SDL memory functions.
  1346. *
  1347. * This is what SDL_malloc and friends will use by default, if there has been
  1348. * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
  1349. * runtime's `malloc` functions behind the scenes! Different platforms and
  1350. * build configurations might do any number of unexpected things.
  1351. *
  1352. * \param malloc_func filled with malloc function.
  1353. * \param calloc_func filled with calloc function.
  1354. * \param realloc_func filled with realloc function.
  1355. * \param free_func filled with free function.
  1356. *
  1357. * \threadsafety It is safe to call this function from any thread.
  1358. *
  1359. * \since This function is available since SDL 3.1.3.
  1360. */
  1361. extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
  1362. SDL_calloc_func *calloc_func,
  1363. SDL_realloc_func *realloc_func,
  1364. SDL_free_func *free_func);
  1365. /**
  1366. * Get the current set of SDL memory functions.
  1367. *
  1368. * \param malloc_func filled with malloc function.
  1369. * \param calloc_func filled with calloc function.
  1370. * \param realloc_func filled with realloc function.
  1371. * \param free_func filled with free function.
  1372. *
  1373. * \threadsafety This does not hold a lock, so do not call this in the
  1374. * unlikely event of a background thread calling
  1375. * SDL_SetMemoryFunctions simultaneously.
  1376. *
  1377. * \since This function is available since SDL 3.1.3.
  1378. *
  1379. * \sa SDL_SetMemoryFunctions
  1380. * \sa SDL_GetOriginalMemoryFunctions
  1381. */
  1382. extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  1383. SDL_calloc_func *calloc_func,
  1384. SDL_realloc_func *realloc_func,
  1385. SDL_free_func *free_func);
  1386. /**
  1387. * Replace SDL's memory allocation functions with a custom set.
  1388. *
  1389. * It is not safe to call this function once any allocations have been made,
  1390. * as future calls to SDL_free will use the new allocator, even if they came
  1391. * from an SDL_malloc made with the old one!
  1392. *
  1393. * If used, usually this needs to be the first call made into the SDL library,
  1394. * if not the very first thing done at program startup time.
  1395. *
  1396. * \param malloc_func custom malloc function.
  1397. * \param calloc_func custom calloc function.
  1398. * \param realloc_func custom realloc function.
  1399. * \param free_func custom free function.
  1400. * \returns true on success or false on failure; call SDL_GetError() for more
  1401. * information.
  1402. *
  1403. * \threadsafety It is safe to call this function from any thread, but one
  1404. * should not replace the memory functions once any allocations
  1405. * are made!
  1406. *
  1407. * \since This function is available since SDL 3.1.3.
  1408. *
  1409. * \sa SDL_GetMemoryFunctions
  1410. * \sa SDL_GetOriginalMemoryFunctions
  1411. */
  1412. extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  1413. SDL_calloc_func calloc_func,
  1414. SDL_realloc_func realloc_func,
  1415. SDL_free_func free_func);
  1416. /**
  1417. * Allocate memory aligned to a specific alignment.
  1418. *
  1419. * The memory returned by this function must be freed with SDL_aligned_free(),
  1420. * _not_ SDL_free().
  1421. *
  1422. * If `alignment` is less than the size of `void *`, it will be increased to
  1423. * match that.
  1424. *
  1425. * The returned memory address will be a multiple of the alignment value, and
  1426. * the size of the memory allocated will be a multiple of the alignment value.
  1427. *
  1428. * \param alignment the alignment of the memory.
  1429. * \param size the size to allocate.
  1430. * \returns a pointer to the aligned memory, or NULL if allocation failed.
  1431. *
  1432. * \threadsafety It is safe to call this function from any thread.
  1433. *
  1434. * \since This function is available since SDL 3.1.3.
  1435. *
  1436. * \sa SDL_aligned_free
  1437. */
  1438. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  1439. /**
  1440. * Free memory allocated by SDL_aligned_alloc().
  1441. *
  1442. * The pointer is no longer valid after this call and cannot be dereferenced
  1443. * anymore.
  1444. *
  1445. * If `mem` is NULL, this function does nothing.
  1446. *
  1447. * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
  1448. *
  1449. * \threadsafety It is safe to call this function from any thread.
  1450. *
  1451. * \since This function is available since SDL 3.1.3.
  1452. *
  1453. * \sa SDL_aligned_alloc
  1454. */
  1455. extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  1456. /**
  1457. * Get the number of outstanding (unfreed) allocations.
  1458. *
  1459. * \returns the number of allocations or -1 if allocation counting is
  1460. * disabled.
  1461. *
  1462. * \threadsafety It is safe to call this function from any thread.
  1463. *
  1464. * \since This function is available since SDL 3.1.3.
  1465. */
  1466. extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  1467. /**
  1468. * A thread-safe set of environment variables
  1469. *
  1470. * \since This struct is available since SDL 3.1.3.
  1471. *
  1472. * \sa SDL_GetEnvironment
  1473. * \sa SDL_CreateEnvironment
  1474. * \sa SDL_GetEnvironmentVariable
  1475. * \sa SDL_GetEnvironmentVariables
  1476. * \sa SDL_SetEnvironmentVariable
  1477. * \sa SDL_UnsetEnvironmentVariable
  1478. * \sa SDL_DestroyEnvironment
  1479. */
  1480. typedef struct SDL_Environment SDL_Environment;
  1481. /**
  1482. * Get the process environment.
  1483. *
  1484. * This is initialized at application start and is not affected by setenv()
  1485. * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
  1486. * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
  1487. * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
  1488. * in the C runtime environment after SDL_Quit().
  1489. *
  1490. * \returns a pointer to the environment for the process or NULL on failure;
  1491. * call SDL_GetError() for more information.
  1492. *
  1493. * \threadsafety It is safe to call this function from any thread.
  1494. *
  1495. * \since This function is available since SDL 3.1.3.
  1496. *
  1497. * \sa SDL_GetEnvironmentVariable
  1498. * \sa SDL_GetEnvironmentVariables
  1499. * \sa SDL_SetEnvironmentVariable
  1500. * \sa SDL_UnsetEnvironmentVariable
  1501. */
  1502. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
  1503. /**
  1504. * Create a set of environment variables
  1505. *
  1506. * \param populated true to initialize it from the C runtime environment,
  1507. * false to create an empty environment.
  1508. * \returns a pointer to the new environment or NULL on failure; call
  1509. * SDL_GetError() for more information.
  1510. *
  1511. * \threadsafety If `populated` is false, it is safe to call this function
  1512. * from any thread, otherwise it is safe if no other threads are
  1513. * calling setenv() or unsetenv()
  1514. *
  1515. * \since This function is available since SDL 3.1.3.
  1516. *
  1517. * \sa SDL_GetEnvironmentVariable
  1518. * \sa SDL_GetEnvironmentVariables
  1519. * \sa SDL_SetEnvironmentVariable
  1520. * \sa SDL_UnsetEnvironmentVariable
  1521. * \sa SDL_DestroyEnvironment
  1522. */
  1523. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
  1524. /**
  1525. * Get the value of a variable in the environment.
  1526. *
  1527. * \param env the environment to query.
  1528. * \param name the name of the variable to get.
  1529. * \returns a pointer to the value of the variable or NULL if it can't be
  1530. * found.
  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. * \sa SDL_GetEnvironment
  1537. * \sa SDL_CreateEnvironment
  1538. * \sa SDL_GetEnvironmentVariables
  1539. * \sa SDL_SetEnvironmentVariable
  1540. * \sa SDL_UnsetEnvironmentVariable
  1541. */
  1542. extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
  1543. /**
  1544. * Get all variables in the environment.
  1545. *
  1546. * \param env the environment to query.
  1547. * \returns a NULL terminated array of pointers to environment variables in
  1548. * the form "variable=value" or NULL on failure; call SDL_GetError()
  1549. * for more information. This is a single allocation that should be
  1550. * freed with SDL_free() when it is no longer needed.
  1551. *
  1552. * \threadsafety It is safe to call this function from any thread.
  1553. *
  1554. * \since This function is available since SDL 3.1.3.
  1555. *
  1556. * \sa SDL_GetEnvironment
  1557. * \sa SDL_CreateEnvironment
  1558. * \sa SDL_GetEnvironmentVariables
  1559. * \sa SDL_SetEnvironmentVariable
  1560. * \sa SDL_UnsetEnvironmentVariable
  1561. */
  1562. extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
  1563. /**
  1564. * Set the value of a variable in the environment.
  1565. *
  1566. * \param env the environment to modify.
  1567. * \param name the name of the variable to set.
  1568. * \param value the value of the variable to set.
  1569. * \param overwrite true to overwrite the variable if it exists, false to
  1570. * return success without setting the variable if it already
  1571. * exists.
  1572. * \returns true on success or false on failure; call SDL_GetError() for more
  1573. * information.
  1574. *
  1575. * \threadsafety It is safe to call this function from any thread.
  1576. *
  1577. * \since This function is available since SDL 3.1.3.
  1578. *
  1579. * \sa SDL_GetEnvironment
  1580. * \sa SDL_CreateEnvironment
  1581. * \sa SDL_GetEnvironmentVariable
  1582. * \sa SDL_GetEnvironmentVariables
  1583. * \sa SDL_UnsetEnvironmentVariable
  1584. */
  1585. extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
  1586. /**
  1587. * Clear a variable from the environment.
  1588. *
  1589. * \param env the environment to modify.
  1590. * \param name the name of the variable to unset.
  1591. * \returns true on success or false on failure; call SDL_GetError() for more
  1592. * information.
  1593. *
  1594. * \threadsafety It is safe to call this function from any thread.
  1595. *
  1596. * \since This function is available since SDL 3.1.3.
  1597. *
  1598. * \sa SDL_GetEnvironment
  1599. * \sa SDL_CreateEnvironment
  1600. * \sa SDL_GetEnvironmentVariable
  1601. * \sa SDL_GetEnvironmentVariables
  1602. * \sa SDL_SetEnvironmentVariable
  1603. * \sa SDL_UnsetEnvironmentVariable
  1604. */
  1605. extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
  1606. /**
  1607. * Destroy a set of environment variables.
  1608. *
  1609. * \param env the environment to destroy.
  1610. *
  1611. * \threadsafety It is safe to call this function from any thread, as long as
  1612. * the environment is no longer in use.
  1613. *
  1614. * \since This function is available since SDL 3.1.3.
  1615. *
  1616. * \sa SDL_CreateEnvironment
  1617. */
  1618. extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
  1619. /**
  1620. * Get the value of a variable in the environment.
  1621. *
  1622. * This function uses SDL's cached copy of the environment and is thread-safe.
  1623. *
  1624. * \param name the name of the variable to get.
  1625. * \returns a pointer to the value of the variable or NULL if it can't be
  1626. * found.
  1627. *
  1628. * \threadsafety It is safe to call this function from any thread.
  1629. *
  1630. * \since This function is available since SDL 3.1.3.
  1631. */
  1632. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
  1633. /**
  1634. * Get the value of a variable in the environment.
  1635. *
  1636. * This function bypasses SDL's cached copy of the environment and is not
  1637. * thread-safe.
  1638. *
  1639. * \param name the name of the variable to get.
  1640. * \returns a pointer to the value of the variable or NULL if it can't be
  1641. * found.
  1642. *
  1643. * \threadsafety This function is not thread safe, consider using SDL_getenv()
  1644. * instead.
  1645. *
  1646. * \since This function is available since SDL 3.1.3.
  1647. *
  1648. * \sa SDL_getenv
  1649. */
  1650. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
  1651. /**
  1652. * Set the value of a variable in the environment.
  1653. *
  1654. * \param name the name of the variable to set.
  1655. * \param value the value of the variable to set.
  1656. * \param overwrite 1 to overwrite the variable if it exists, 0 to return
  1657. * success without setting the variable if it already exists.
  1658. * \returns 0 on success, -1 on error.
  1659. *
  1660. * \threadsafety This function is not thread safe, consider using
  1661. * SDL_SetEnvironmentVariable() instead.
  1662. *
  1663. * \since This function is available since SDL 3.1.3.
  1664. *
  1665. * \sa SDL_SetEnvironmentVariable
  1666. */
  1667. extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
  1668. /**
  1669. * Clear a variable from the environment.
  1670. *
  1671. * \param name the name of the variable to unset.
  1672. * \returns 0 on success, -1 on error.
  1673. *
  1674. * \threadsafety This function is not thread safe, consider using
  1675. * SDL_UnsetEnvironmentVariable() instead.
  1676. *
  1677. * \since This function is available since SDL 3.1.3.
  1678. *
  1679. * \sa SDL_UnsetEnvironmentVariable
  1680. */
  1681. extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
  1682. /**
  1683. * A callback used with SDL sorting and binary search functions.
  1684. *
  1685. * \param a a pointer to the first element being compared.
  1686. * \param b a pointer to the second element being compared.
  1687. * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
  1688. * before `a`, 0 if they are equal. If two elements are equal, their
  1689. * order in the sorted array is undefined.
  1690. *
  1691. * \since This callback is available since SDL 3.1.3.
  1692. *
  1693. * \sa SDL_bsearch
  1694. * \sa SDL_qsort
  1695. */
  1696. typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
  1697. /**
  1698. * Sort an array.
  1699. *
  1700. * For example:
  1701. *
  1702. * ```c
  1703. * typedef struct {
  1704. * int key;
  1705. * const char *string;
  1706. * } data;
  1707. *
  1708. * int SDLCALL compare(const void *a, const void *b)
  1709. * {
  1710. * const data *A = (const data *)a;
  1711. * const data *B = (const data *)b;
  1712. *
  1713. * if (A->n < B->n) {
  1714. * return -1;
  1715. * } else if (B->n < A->n) {
  1716. * return 1;
  1717. * } else {
  1718. * return 0;
  1719. * }
  1720. * }
  1721. *
  1722. * data values[] = {
  1723. * { 3, "third" }, { 1, "first" }, { 2, "second" }
  1724. * };
  1725. *
  1726. * SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
  1727. * ```
  1728. *
  1729. * \param base a pointer to the start of the array.
  1730. * \param nmemb the number of elements in the array.
  1731. * \param size the size of the elements in the array.
  1732. * \param compare a function used to compare elements in the array.
  1733. *
  1734. * \threadsafety It is safe to call this function from any thread.
  1735. *
  1736. * \since This function is available since SDL 3.1.3.
  1737. *
  1738. * \sa SDL_bsearch
  1739. * \sa SDL_qsort_r
  1740. */
  1741. extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1742. /**
  1743. * Perform a binary search on a previously sorted array.
  1744. *
  1745. * For example:
  1746. *
  1747. * ```c
  1748. * typedef struct {
  1749. * int key;
  1750. * const char *string;
  1751. * } data;
  1752. *
  1753. * int SDLCALL compare(const void *a, const void *b)
  1754. * {
  1755. * const data *A = (const data *)a;
  1756. * const data *B = (const data *)b;
  1757. *
  1758. * if (A->n < B->n) {
  1759. * return -1;
  1760. * } else if (B->n < A->n) {
  1761. * return 1;
  1762. * } else {
  1763. * return 0;
  1764. * }
  1765. * }
  1766. *
  1767. * data values[] = {
  1768. * { 1, "first" }, { 2, "second" }, { 3, "third" }
  1769. * };
  1770. * data key = { 2, NULL };
  1771. *
  1772. * data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
  1773. * ```
  1774. *
  1775. * \param key a pointer to a key equal to the element being searched for.
  1776. * \param base a pointer to the start of the array.
  1777. * \param nmemb the number of elements in the array.
  1778. * \param size the size of the elements in the array.
  1779. * \param compare a function used to compare elements in the array.
  1780. * \returns a pointer to the matching element in the array, or NULL if not
  1781. * found.
  1782. *
  1783. * \threadsafety It is safe to call this function from any thread.
  1784. *
  1785. * \since This function is available since SDL 3.1.3.
  1786. *
  1787. * \sa SDL_bsearch_r
  1788. * \sa SDL_qsort
  1789. */
  1790. extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1791. /**
  1792. * A callback used with SDL sorting and binary search functions.
  1793. *
  1794. * \param userdata the `userdata` pointer passed to the sort function.
  1795. * \param a a pointer to the first element being compared.
  1796. * \param b a pointer to the second element being compared.
  1797. * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
  1798. * before `a`, 0 if they are equal. If two elements are equal, their
  1799. * order in the sorted array is undefined.
  1800. *
  1801. * \since This callback is available since SDL 3.1.3.
  1802. *
  1803. * \sa SDL_qsort_r
  1804. * \sa SDL_bsearch_r
  1805. */
  1806. typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
  1807. /**
  1808. * Sort an array, passing a userdata pointer to the compare function.
  1809. *
  1810. * For example:
  1811. *
  1812. * ```c
  1813. * typedef enum {
  1814. * sort_increasing,
  1815. * sort_decreasing,
  1816. * } sort_method;
  1817. *
  1818. * typedef struct {
  1819. * int key;
  1820. * const char *string;
  1821. * } data;
  1822. *
  1823. * int SDLCALL compare(const void *userdata, const void *a, const void *b)
  1824. * {
  1825. * sort_method method = (sort_method)(uintptr_t)userdata;
  1826. * const data *A = (const data *)a;
  1827. * const data *B = (const data *)b;
  1828. *
  1829. * if (A->key < B->key) {
  1830. * return (method == sort_increasing) ? -1 : 1;
  1831. * } else if (B->key < A->key) {
  1832. * return (method == sort_increasing) ? 1 : -1;
  1833. * } else {
  1834. * return 0;
  1835. * }
  1836. * }
  1837. *
  1838. * data values[] = {
  1839. * { 3, "third" }, { 1, "first" }, { 2, "second" }
  1840. * };
  1841. *
  1842. * SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
  1843. * ```
  1844. *
  1845. * \param base a pointer to the start of the array.
  1846. * \param nmemb the number of elements in the array.
  1847. * \param size the size of the elements in the array.
  1848. * \param compare a function used to compare elements in the array.
  1849. * \param userdata a pointer to pass to the compare function.
  1850. *
  1851. * \threadsafety It is safe to call this function from any thread.
  1852. *
  1853. * \since This function is available since SDL 3.1.3.
  1854. *
  1855. * \sa SDL_bsearch_r
  1856. * \sa SDL_qsort
  1857. */
  1858. extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
  1859. /**
  1860. * Perform a binary search on a previously sorted array, passing a userdata
  1861. * pointer to the compare function.
  1862. *
  1863. * For example:
  1864. *
  1865. * ```c
  1866. * typedef enum {
  1867. * sort_increasing,
  1868. * sort_decreasing,
  1869. * } sort_method;
  1870. *
  1871. * typedef struct {
  1872. * int key;
  1873. * const char *string;
  1874. * } data;
  1875. *
  1876. * int SDLCALL compare(const void *userdata, const void *a, const void *b)
  1877. * {
  1878. * sort_method method = (sort_method)(uintptr_t)userdata;
  1879. * const data *A = (const data *)a;
  1880. * const data *B = (const data *)b;
  1881. *
  1882. * if (A->key < B->key) {
  1883. * return (method == sort_increasing) ? -1 : 1;
  1884. * } else if (B->key < A->key) {
  1885. * return (method == sort_increasing) ? 1 : -1;
  1886. * } else {
  1887. * return 0;
  1888. * }
  1889. * }
  1890. *
  1891. * data values[] = {
  1892. * { 1, "first" }, { 2, "second" }, { 3, "third" }
  1893. * };
  1894. * data key = { 2, NULL };
  1895. *
  1896. * data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
  1897. * ```
  1898. *
  1899. * \param key a pointer to a key equal to the element being searched for.
  1900. * \param base a pointer to the start of the array.
  1901. * \param nmemb the number of elements in the array.
  1902. * \param size the size of the elements in the array.
  1903. * \param compare a function used to compare elements in the array.
  1904. * \param userdata a pointer to pass to the compare function.
  1905. * \returns a pointer to the matching element in the array, or NULL if not
  1906. * found.
  1907. *
  1908. * \threadsafety It is safe to call this function from any thread.
  1909. *
  1910. * \since This function is available since SDL 3.1.3.
  1911. *
  1912. * \sa SDL_bsearch
  1913. * \sa SDL_qsort_r
  1914. */
  1915. 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);
  1916. /**
  1917. * Compute the absolute value of `x`.
  1918. *
  1919. * \param x an integer value.
  1920. * \returns the absolute value of x.
  1921. *
  1922. * \threadsafety It is safe to call this function from any thread.
  1923. *
  1924. * \since This function is available since SDL 3.1.3.
  1925. */
  1926. extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
  1927. /**
  1928. * Return the lesser of two values.
  1929. *
  1930. * This is a helper macro that might be more clear than writing out the
  1931. * comparisons directly, and works with any type that can be compared with the
  1932. * `<` operator. However, it double-evaluates both its parameters, so do not
  1933. * use expressions with side-effects here.
  1934. *
  1935. * \param x the first value to compare.
  1936. * \param y the second value to compare.
  1937. * \returns the lesser of `x` and `y`.
  1938. *
  1939. * \threadsafety It is safe to call this macro from any thread.
  1940. *
  1941. * \since This macro is available since SDL 3.1.3.
  1942. */
  1943. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  1944. /**
  1945. * Return the greater of two values.
  1946. *
  1947. * This is a helper macro that might be more clear than writing out the
  1948. * comparisons directly, and works with any type that can be compared with the
  1949. * `>` operator. However, it double-evaluates both its parameters, so do not
  1950. * use expressions with side-effects here.
  1951. *
  1952. * \param x the first value to compare.
  1953. * \param y the second value to compare.
  1954. * \returns the lesser of `x` and `y`.
  1955. *
  1956. * \threadsafety It is safe to call this macro from any thread.
  1957. *
  1958. * \since This macro is available since SDL 3.1.3.
  1959. */
  1960. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  1961. /**
  1962. * Return a value clamped to a range.
  1963. *
  1964. * If `x` is outside the range a values between `a` and `b`, the returned
  1965. * value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
  1966. *
  1967. * This macro will produce incorrect results if `b` is less than `a`.
  1968. *
  1969. * This is a helper macro that might be more clear than writing out the
  1970. * comparisons directly, and works with any type that can be compared with the
  1971. * `<` and `>` operators. However, it double-evaluates all its parameters, so
  1972. * do not use expressions with side-effects here.
  1973. *
  1974. * \param x the value to compare.
  1975. * \param a the low end value.
  1976. * \param b the high end value.
  1977. * \returns x, clamped between a and b.
  1978. *
  1979. * \threadsafety It is safe to call this macro from any thread.
  1980. *
  1981. * \since This macro is available since SDL 3.1.3.
  1982. */
  1983. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  1984. /**
  1985. * Query if a character is alphabetic (a letter).
  1986. *
  1987. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1988. * for English 'a-z' and 'A-Z' as true.
  1989. *
  1990. * \param x character value to check.
  1991. * \returns non-zero if x falls within the character class, zero otherwise.
  1992. *
  1993. * \threadsafety It is safe to call this function from any thread.
  1994. *
  1995. * \since This function is available since SDL 3.1.3.
  1996. */
  1997. extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
  1998. /**
  1999. * Query if a character is alphabetic (a letter) or a number.
  2000. *
  2001. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2002. * for English 'a-z', 'A-Z', and '0-9' as true.
  2003. *
  2004. * \param x character value to check.
  2005. * \returns non-zero if x falls within the character class, zero otherwise.
  2006. *
  2007. * \threadsafety It is safe to call this function from any thread.
  2008. *
  2009. * \since This function is available since SDL 3.1.3.
  2010. */
  2011. extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
  2012. /**
  2013. * Report if a character is blank (a space or tab).
  2014. *
  2015. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2016. * 0x20 (space) or 0x9 (tab) as true.
  2017. *
  2018. * \param x character value to check.
  2019. * \returns non-zero if x falls within the character class, zero otherwise.
  2020. *
  2021. * \threadsafety It is safe to call this function from any thread.
  2022. *
  2023. * \since This function is available since SDL 3.1.3.
  2024. */
  2025. extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
  2026. /**
  2027. * Report if a character is a control character.
  2028. *
  2029. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2030. * 0 through 0x1F, and 0x7F, as true.
  2031. *
  2032. * \param x character value to check.
  2033. * \returns non-zero if x falls within the character class, zero otherwise.
  2034. *
  2035. * \threadsafety It is safe to call this function from any thread.
  2036. *
  2037. * \since This function is available since SDL 3.1.3.
  2038. */
  2039. extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
  2040. /**
  2041. * Report if a character is a numeric digit.
  2042. *
  2043. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2044. * '0' (0x30) through '9' (0x39), as true.
  2045. *
  2046. * \param x character value to check.
  2047. * \returns non-zero if x falls within the character class, zero otherwise.
  2048. *
  2049. * \threadsafety It is safe to call this function from any thread.
  2050. *
  2051. * \since This function is available since SDL 3.1.3.
  2052. */
  2053. extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
  2054. /**
  2055. * Report if a character is a hexadecimal digit.
  2056. *
  2057. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2058. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  2059. *
  2060. * \param x character value to check.
  2061. * \returns non-zero if x falls within the character class, zero otherwise.
  2062. *
  2063. * \threadsafety It is safe to call this function from any thread.
  2064. *
  2065. * \since This function is available since SDL 3.1.3.
  2066. */
  2067. extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
  2068. /**
  2069. * Report if a character is a punctuation mark.
  2070. *
  2071. * **WARNING**: Regardless of system locale, this is equivalent to
  2072. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  2073. *
  2074. * \param x character value to check.
  2075. * \returns non-zero if x falls within the character class, zero otherwise.
  2076. *
  2077. * \threadsafety It is safe to call this function from any thread.
  2078. *
  2079. * \since This function is available since SDL 3.1.3.
  2080. *
  2081. * \sa SDL_isgraph
  2082. * \sa SDL_isalnum
  2083. */
  2084. extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
  2085. /**
  2086. * Report if a character is whitespace.
  2087. *
  2088. * **WARNING**: Regardless of system locale, this will only treat the
  2089. * following ASCII values as true:
  2090. *
  2091. * - space (0x20)
  2092. * - tab (0x09)
  2093. * - newline (0x0A)
  2094. * - vertical tab (0x0B)
  2095. * - form feed (0x0C)
  2096. * - return (0x0D)
  2097. *
  2098. * \param x character value to check.
  2099. * \returns non-zero if x falls within the character class, zero otherwise.
  2100. *
  2101. * \threadsafety It is safe to call this function from any thread.
  2102. *
  2103. * \since This function is available since SDL 3.1.3.
  2104. */
  2105. extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
  2106. /**
  2107. * Report if a character is upper case.
  2108. *
  2109. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2110. * 'A' through 'Z' as true.
  2111. *
  2112. * \param x character value to check.
  2113. * \returns non-zero if x falls within the character class, zero otherwise.
  2114. *
  2115. * \threadsafety It is safe to call this function from any thread.
  2116. *
  2117. * \since This function is available since SDL 3.1.3.
  2118. */
  2119. extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
  2120. /**
  2121. * Report if a character is lower case.
  2122. *
  2123. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2124. * 'a' through 'z' as true.
  2125. *
  2126. * \param x character value to check.
  2127. * \returns non-zero if x falls within the character class, zero otherwise.
  2128. *
  2129. * \threadsafety It is safe to call this function from any thread.
  2130. *
  2131. * \since This function is available since SDL 3.1.3.
  2132. */
  2133. extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
  2134. /**
  2135. * Report if a character is "printable".
  2136. *
  2137. * Be advised that "printable" has a definition that goes back to text
  2138. * terminals from the dawn of computing, making this a sort of special case
  2139. * function that is not suitable for Unicode (or most any) text management.
  2140. *
  2141. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2142. * ' ' (0x20) through '~' (0x7E) as true.
  2143. *
  2144. * \param x character value to check.
  2145. * \returns non-zero if x falls within the character class, zero otherwise.
  2146. *
  2147. * \threadsafety It is safe to call this function from any thread.
  2148. *
  2149. * \since This function is available since SDL 3.1.3.
  2150. */
  2151. extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
  2152. /**
  2153. * Report if a character is any "printable" except space.
  2154. *
  2155. * Be advised that "printable" has a definition that goes back to text
  2156. * terminals from the dawn of computing, making this a sort of special case
  2157. * function that is not suitable for Unicode (or most any) text management.
  2158. *
  2159. * **WARNING**: Regardless of system locale, this is equivalent to
  2160. * `(SDL_isprint(x)) && ((x) != ' ')`.
  2161. *
  2162. * \param x character value to check.
  2163. * \returns non-zero if x falls within the character class, zero otherwise.
  2164. *
  2165. * \threadsafety It is safe to call this function from any thread.
  2166. *
  2167. * \since This function is available since SDL 3.1.3.
  2168. *
  2169. * \sa SDL_isprint
  2170. */
  2171. extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
  2172. /**
  2173. * Convert low-ASCII English letters to uppercase.
  2174. *
  2175. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2176. * values 'a' through 'z' to uppercase.
  2177. *
  2178. * This function returns the uppercase equivalent of `x`. If a character
  2179. * cannot be converted, or is already uppercase, this function returns `x`.
  2180. *
  2181. * \param x character value to check.
  2182. * \returns capitalized version of x, or x if no conversion available.
  2183. *
  2184. * \threadsafety It is safe to call this function from any thread.
  2185. *
  2186. * \since This function is available since SDL 3.1.3.
  2187. */
  2188. extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
  2189. /**
  2190. * Convert low-ASCII English letters to lowercase.
  2191. *
  2192. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2193. * values 'A' through 'Z' to lowercase.
  2194. *
  2195. * This function returns the lowercase equivalent of `x`. If a character
  2196. * cannot be converted, or is already lowercase, this function returns `x`.
  2197. *
  2198. * \param x character value to check.
  2199. * \returns lowercase version of x, or x if no conversion available.
  2200. *
  2201. * \threadsafety It is safe to call this function from any thread.
  2202. *
  2203. * \since This function is available since SDL 3.1.3.
  2204. */
  2205. extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
  2206. /**
  2207. * Calculate a CRC-16 value.
  2208. *
  2209. * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
  2210. *
  2211. * This function can be called multiple times, to stream data to be
  2212. * checksummed in blocks. Each call must provide the previous CRC-16 return
  2213. * value to be updated with the next block. The first call to this function
  2214. * for a set of blocks should pass in a zero CRC value.
  2215. *
  2216. * \param crc the current checksum for this data set, or 0 for a new data set.
  2217. * \param data a new block of data to add to the checksum.
  2218. * \param len the size, in bytes, of the new block of data.
  2219. * \returns a CRC-16 checksum value of all blocks in the data set.
  2220. *
  2221. * \threadsafety It is safe to call this function from any thread.
  2222. *
  2223. * \since This function is available since SDL 3.1.3.
  2224. */
  2225. extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  2226. /**
  2227. * Calculate a CRC-32 value.
  2228. *
  2229. * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
  2230. *
  2231. * This function can be called multiple times, to stream data to be
  2232. * checksummed in blocks. Each call must provide the previous CRC-32 return
  2233. * value to be updated with the next block. The first call to this function
  2234. * for a set of blocks should pass in a zero CRC value.
  2235. *
  2236. * \param crc the current checksum for this data set, or 0 for a new data set.
  2237. * \param data a new block of data to add to the checksum.
  2238. * \param len the size, in bytes, of the new block of data.
  2239. * \returns a CRC-32 checksum value of all blocks in the data set.
  2240. *
  2241. * \threadsafety It is safe to call this function from any thread.
  2242. *
  2243. * \since This function is available since SDL 3.1.3.
  2244. */
  2245. extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  2246. /**
  2247. * Calculate a 32-bit MurmurHash3 value for a block of data.
  2248. *
  2249. * https://en.wikipedia.org/wiki/MurmurHash
  2250. *
  2251. * A seed may be specified, which changes the final results consistently, but
  2252. * this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
  2253. * result from this function back into itself as the next seed value to
  2254. * calculate a hash in chunks; it won't produce the same hash as it would if
  2255. * the same data was provided in a single call.
  2256. *
  2257. * If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
  2258. * cryptographically secure, so it shouldn't be used for hashing top-secret
  2259. * data.
  2260. *
  2261. * \param data the data to be hashed.
  2262. * \param len the size of data, in bytes.
  2263. * \param seed a value that alters the final hash value.
  2264. * \returns a Murmur3 32-bit hash value.
  2265. *
  2266. * \threadsafety It is safe to call this function from any thread.
  2267. *
  2268. * \since This function is available since SDL 3.1.3.
  2269. */
  2270. extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
  2271. /**
  2272. * Copy non-overlapping memory.
  2273. *
  2274. * The memory regions must not overlap. If they do, use SDL_memmove() instead.
  2275. *
  2276. * \param dst The destination memory region. Must not be NULL, and must not
  2277. * overlap with `src`.
  2278. * \param src The source memory region. Must not be NULL, and must not overlap
  2279. * with `dst`.
  2280. * \param len The length in bytes of both `dst` and `src`.
  2281. * \returns `dst`.
  2282. *
  2283. * \threadsafety It is safe to call this function from any thread.
  2284. *
  2285. * \since This function is available since SDL 3.1.3.
  2286. *
  2287. * \sa SDL_memmove
  2288. */
  2289. extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  2290. /* Take advantage of compiler optimizations for memcpy */
  2291. #ifndef SDL_SLOW_MEMCPY
  2292. #ifdef SDL_memcpy
  2293. #undef SDL_memcpy
  2294. #endif
  2295. #define SDL_memcpy memcpy
  2296. #endif
  2297. /**
  2298. * A macro to copy memory between objects, with basic type checking.
  2299. *
  2300. * SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
  2301. * which can lead to bugs. This macro aims to avoid most of those bugs by
  2302. * making sure that the source and destination are both pointers to objects
  2303. * that are the same size. It does not check that the objects are the same
  2304. * _type_, just that the copy will not overflow either object.
  2305. *
  2306. * The size check happens at compile time, and the compiler will throw an
  2307. * error if the objects are different sizes.
  2308. *
  2309. * Generally this is intended to copy a single object, not an array.
  2310. *
  2311. * This macro looks like it double-evaluates its parameters, but the extras
  2312. * them are in `sizeof` sections, which generate no code nor side-effects.
  2313. *
  2314. * \param dst a pointer to the destination object. Must not be NULL.
  2315. * \param src a pointer to the source object. Must not be NULL.
  2316. *
  2317. * \threadsafety It is safe to call this function from any thread.
  2318. *
  2319. * \since This function is available since SDL 3.1.3.
  2320. */
  2321. #define SDL_copyp(dst, src) \
  2322. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  2323. SDL_memcpy((dst), (src), sizeof(*(src)))
  2324. /**
  2325. * Copy memory ranges that might overlap.
  2326. *
  2327. * It is okay for the memory regions to overlap. If you are confident that the
  2328. * regions never overlap, using SDL_memcpy() may improve performance.
  2329. *
  2330. * \param dst The destination memory region. Must not be NULL.
  2331. * \param src The source memory region. Must not be NULL.
  2332. * \param len The length in bytes of both `dst` and `src`.
  2333. * \returns `dst`.
  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. * \sa SDL_memcpy
  2340. */
  2341. extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  2342. /* Take advantage of compiler optimizations for memmove */
  2343. #ifndef SDL_SLOW_MEMMOVE
  2344. #ifdef SDL_memmove
  2345. #undef SDL_memmove
  2346. #endif
  2347. #define SDL_memmove memmove
  2348. #endif
  2349. /**
  2350. * Initialize all bytes of buffer of memory to a specific value.
  2351. *
  2352. * This function will set `len` bytes, pointed to by `dst`, to the value
  2353. * specified in `c`.
  2354. *
  2355. * Despite `c` being an `int` instead of a `char`, this only operates on
  2356. * bytes; `c` must be a value between 0 and 255, inclusive.
  2357. *
  2358. * \param dst the destination memory region. Must not be NULL.
  2359. * \param c the byte value to set.
  2360. * \param len the length, in bytes, to set in `dst`.
  2361. * \returns `dst`.
  2362. *
  2363. * \threadsafety It is safe to call this function from any thread.
  2364. *
  2365. * \since This function is available since SDL 3.1.3.
  2366. */
  2367. extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  2368. /**
  2369. * Initialize all 32-bit words of buffer of memory to a specific value.
  2370. *
  2371. * This function will set a buffer of `dwords` Uint32 values, pointed to by
  2372. * `dst`, to the value specified in `val`.
  2373. *
  2374. * Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
  2375. * to a range of 0-255.
  2376. *
  2377. * \param dst the destination memory region. Must not be NULL.
  2378. * \param val the Uint32 value to set.
  2379. * \param dwords the number of Uint32 values to set in `dst`.
  2380. * \returns `dst`.
  2381. *
  2382. * \threadsafety It is safe to call this function from any thread.
  2383. *
  2384. * \since This function is available since SDL 3.1.3.
  2385. */
  2386. extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  2387. /* Take advantage of compiler optimizations for memset */
  2388. #ifndef SDL_SLOW_MEMSET
  2389. #ifdef SDL_memset
  2390. #undef SDL_memset
  2391. #endif
  2392. #define SDL_memset memset
  2393. #endif
  2394. /**
  2395. * Clear an object's memory to zero.
  2396. *
  2397. * This is wrapper over SDL_memset that handles calculating the object size,
  2398. * so there's no chance of copy/paste errors, and the code is cleaner.
  2399. *
  2400. * This requires an object, not a pointer to an object, nor an array.
  2401. *
  2402. * \param x the object to clear.
  2403. *
  2404. * \threadsafety It is safe to call this macro from any thread.
  2405. *
  2406. * \since This macro is available since SDL 3.1.3.
  2407. *
  2408. * \sa SDL_zerop
  2409. * \sa SDL_zeroa
  2410. */
  2411. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  2412. /**
  2413. * Clear an object's memory to zero, using a pointer.
  2414. *
  2415. * This is wrapper over SDL_memset that handles calculating the object size,
  2416. * so there's no chance of copy/paste errors, and the code is cleaner.
  2417. *
  2418. * This requires a pointer to an object, not an object itself, nor an array.
  2419. *
  2420. * \param x a pointer to the object to clear.
  2421. *
  2422. * \threadsafety It is safe to call this macro from any thread.
  2423. *
  2424. * \since This macro is available since SDL 3.1.3.
  2425. *
  2426. * \sa SDL_zero
  2427. * \sa SDL_zeroa
  2428. */
  2429. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  2430. /**
  2431. * Clear an array's memory to zero.
  2432. *
  2433. * This is wrapper over SDL_memset that handles calculating the array size, so
  2434. * there's no chance of copy/paste errors, and the code is cleaner.
  2435. *
  2436. * This requires an array, not an object, nor a pointer to an object.
  2437. *
  2438. * \param x an array to clear.
  2439. *
  2440. * \threadsafety It is safe to call this macro from any thread.
  2441. *
  2442. * \since This macro is available since SDL 3.1.3.
  2443. *
  2444. * \sa SDL_zero
  2445. * \sa SDL_zeroa
  2446. */
  2447. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  2448. /**
  2449. * Compare two buffers of memory.
  2450. *
  2451. * \param s1 the first buffer to compare. NULL is not permitted!
  2452. * \param s2 the second buffer to compare. NULL is not permitted!
  2453. * \param len the number of bytes to compare between the buffers.
  2454. * \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
  2455. * "greater than" s2, and zero if the buffers match exactly for `len`
  2456. * bytes.
  2457. *
  2458. * \threadsafety It is safe to call this function from any thread.
  2459. *
  2460. * \since This function is available since SDL 3.1.3.
  2461. */
  2462. extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  2463. /**
  2464. * This works exactly like wcslen() but doesn't require access to a C runtime.
  2465. *
  2466. * Counts the number of wchar_t values in `wstr`, excluding the null
  2467. * terminator.
  2468. *
  2469. * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
  2470. * this counts wchar_t values in a string, even if the string's encoding is of
  2471. * variable width, like UTF-16.
  2472. *
  2473. * Also be aware that wchar_t is different sizes on different platforms (4
  2474. * bytes on Linux, 2 on Windows, etc).
  2475. *
  2476. * \param wstr The null-terminated wide string to read. Must not be NULL.
  2477. * \returns the length (in wchar_t values, excluding the null terminator) of
  2478. * `wstr`.
  2479. *
  2480. * \threadsafety It is safe to call this function from any thread.
  2481. *
  2482. * \since This function is available since SDL 3.1.3.
  2483. *
  2484. * \sa SDL_wcsnlen
  2485. * \sa SDL_utf8strlen
  2486. * \sa SDL_utf8strnlen
  2487. */
  2488. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  2489. /**
  2490. * This works exactly like wcsnlen() but doesn't require access to a C
  2491. * runtime.
  2492. *
  2493. * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
  2494. * null terminator.
  2495. *
  2496. * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
  2497. * this counts wchar_t values in a string, even if the string's encoding is of
  2498. * variable width, like UTF-16.
  2499. *
  2500. * Also be aware that wchar_t is different sizes on different platforms (4
  2501. * bytes on Linux, 2 on Windows, etc).
  2502. *
  2503. * Also, `maxlen` is a count of wide characters, not bytes!
  2504. *
  2505. * \param wstr The null-terminated wide string to read. Must not be NULL.
  2506. * \param maxlen The maximum amount of wide characters to count.
  2507. * \returns the length (in wide characters, excluding the null terminator) of
  2508. * `wstr` but never more than `maxlen`.
  2509. *
  2510. * \threadsafety It is safe to call this function from any thread.
  2511. *
  2512. * \since This function is available since SDL 3.1.3.
  2513. *
  2514. * \sa SDL_wcslen
  2515. * \sa SDL_utf8strlen
  2516. * \sa SDL_utf8strnlen
  2517. */
  2518. extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  2519. /**
  2520. * Copy a wide string.
  2521. *
  2522. * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
  2523. * appends a null terminator.
  2524. *
  2525. * `src` and `dst` must not overlap.
  2526. *
  2527. * If `maxlen` is 0, no wide characters are copied and no null terminator is
  2528. * written.
  2529. *
  2530. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2531. * with `src`.
  2532. * \param src The null-terminated wide string to copy. Must not be NULL, and
  2533. * must not overlap with `dst`.
  2534. * \param maxlen The length (in wide characters) of the destination buffer.
  2535. * \returns the length (in wide characters, excluding the null terminator) of
  2536. * `src`.
  2537. *
  2538. * \threadsafety It is safe to call this function from any thread.
  2539. *
  2540. * \since This function is available since SDL 3.1.3.
  2541. *
  2542. * \sa SDL_wcslcat
  2543. */
  2544. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  2545. /**
  2546. * Concatenate wide strings.
  2547. *
  2548. * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
  2549. * from `src` to the end of the wide string in `dst`, then appends a null
  2550. * terminator.
  2551. *
  2552. * `src` and `dst` must not overlap.
  2553. *
  2554. * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
  2555. * unmodified.
  2556. *
  2557. * \param dst The destination buffer already containing the first
  2558. * null-terminated wide string. Must not be NULL and must not
  2559. * overlap with `src`.
  2560. * \param src The second null-terminated wide string. Must not be NULL, and
  2561. * must not overlap with `dst`.
  2562. * \param maxlen The length (in wide characters) of the destination buffer.
  2563. * \returns the length (in wide characters, excluding the null terminator) of
  2564. * the string in `dst` plus the length of `src`.
  2565. *
  2566. * \threadsafety It is safe to call this function from any thread.
  2567. *
  2568. * \since This function is available since SDL 3.1.3.
  2569. *
  2570. * \sa SDL_wcslcpy
  2571. */
  2572. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  2573. /**
  2574. * Allocate a copy of a wide string.
  2575. *
  2576. * This allocates enough space for a null-terminated copy of `wstr`, using
  2577. * SDL_malloc, and then makes a copy of the string into this space.
  2578. *
  2579. * The returned string is owned by the caller, and should be passed to
  2580. * SDL_free when no longer needed.
  2581. *
  2582. * \param wstr the string to copy.
  2583. * \returns a pointer to the newly-allocated wide string.
  2584. *
  2585. * \threadsafety It is safe to call this function from any thread.
  2586. *
  2587. * \since This function is available since SDL 3.1.3.
  2588. */
  2589. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
  2590. /**
  2591. * Search a wide string for the first instance of a specific substring.
  2592. *
  2593. * The search ends once it finds the requested substring, or a null terminator
  2594. * byte to end the string.
  2595. *
  2596. * Note that this looks for strings of _wide characters_, not _codepoints_, so
  2597. * it's legal to search for malformed and incomplete UTF-16 sequences.
  2598. *
  2599. * \param haystack the wide string to search. Must not be NULL.
  2600. * \param needle the wide string to search for. Must not be NULL.
  2601. * \returns a pointer to the first instance of `needle` in the string, or NULL
  2602. * if not found.
  2603. *
  2604. * \threadsafety It is safe to call this function from any thread.
  2605. *
  2606. * \since This function is available since SDL 3.1.3.
  2607. */
  2608. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  2609. /**
  2610. * Search a wide string, up to n wide chars, for the first instance of a
  2611. * specific substring.
  2612. *
  2613. * The search ends once it finds the requested substring, or a null terminator
  2614. * value to end the string, or `maxlen` wide character have been examined. It
  2615. * is possible to use this function on a wide string without a null
  2616. * terminator.
  2617. *
  2618. * Note that this looks for strings of _wide characters_, not _codepoints_, so
  2619. * it's legal to search for malformed and incomplete UTF-16 sequences.
  2620. *
  2621. * \param haystack the wide string to search. Must not be NULL.
  2622. * \param needle the wide string to search for. Must not be NULL.
  2623. * \param maxlen the maximum number of wide characters to search in
  2624. * `haystack`.
  2625. * \returns a pointer to the first instance of `needle` in the string, or NULL
  2626. * if not found.
  2627. *
  2628. * \threadsafety It is safe to call this function from any thread.
  2629. *
  2630. * \since This function is available since SDL 3.1.3.
  2631. */
  2632. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  2633. /**
  2634. * Compare two null-terminated wide strings.
  2635. *
  2636. * This only compares wchar_t values until it hits a null-terminating
  2637. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  2638. * depending on your platform's wchar_t size), or uses valid Unicode values.
  2639. *
  2640. * \param str1 the first string to compare. NULL is not permitted!
  2641. * \param str2 the second string to compare. NULL is not permitted!
  2642. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2643. * str1 is "greater than" str2, and zero if the strings match
  2644. * exactly.
  2645. *
  2646. * \threadsafety It is safe to call this function from any thread.
  2647. *
  2648. * \since This function is available since SDL 3.1.3.
  2649. */
  2650. extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  2651. /**
  2652. * Compare two wide strings up to a number of wchar_t values.
  2653. *
  2654. * This only compares wchar_t values; it does not care if the string is
  2655. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  2656. * or uses valid Unicode values.
  2657. *
  2658. * Note that while this function is intended to be used with UTF-16 (or
  2659. * UTF-32, depending on your platform's definition of wchar_t), it is
  2660. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  2661. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  2662. * sequence, it will only compare a portion of the final character.
  2663. *
  2664. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  2665. * match to this number of wide chars (or both have matched to a
  2666. * null-terminator character before this count), they will be considered
  2667. * equal.
  2668. *
  2669. * \param str1 the first string to compare. NULL is not permitted!
  2670. * \param str2 the second string to compare. NULL is not permitted!
  2671. * \param maxlen the maximum number of wchar_t to compare.
  2672. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2673. * str1 is "greater than" str2, and zero if the strings match
  2674. * exactly.
  2675. *
  2676. * \threadsafety It is safe to call this function from any thread.
  2677. *
  2678. * \since This function is available since SDL 3.1.3.
  2679. */
  2680. extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  2681. /**
  2682. * Compare two null-terminated wide strings, case-insensitively.
  2683. *
  2684. * This will work with Unicode strings, using a technique called
  2685. * "case-folding" to handle the vast majority of case-sensitive human
  2686. * languages regardless of system locale. It can deal with expanding values: a
  2687. * German Eszett character can compare against two ASCII 's' chars and be
  2688. * considered a match, for example. A notable exception: it does not handle
  2689. * the Turkish 'i' character; human language is complicated!
  2690. *
  2691. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  2692. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  2693. * handles Unicode, it expects the string to be well-formed and not a
  2694. * null-terminated string of arbitrary bytes. Characters that are not valid
  2695. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  2696. * CHARACTER), which is to say two strings of random bits may turn out to
  2697. * match if they convert to the same amount of replacement characters.
  2698. *
  2699. * \param str1 the first string to compare. NULL is not permitted!
  2700. * \param str2 the second string to compare. NULL is not permitted!
  2701. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2702. * str1 is "greater than" str2, and zero if the strings match
  2703. * exactly.
  2704. *
  2705. * \threadsafety It is safe to call this function from any thread.
  2706. *
  2707. * \since This function is available since SDL 3.1.3.
  2708. */
  2709. extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  2710. /**
  2711. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  2712. *
  2713. * This will work with Unicode strings, using a technique called
  2714. * "case-folding" to handle the vast majority of case-sensitive human
  2715. * languages regardless of system locale. It can deal with expanding values: a
  2716. * German Eszett character can compare against two ASCII 's' chars and be
  2717. * considered a match, for example. A notable exception: it does not handle
  2718. * the Turkish 'i' character; human language is complicated!
  2719. *
  2720. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  2721. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  2722. * handles Unicode, it expects the string to be well-formed and not a
  2723. * null-terminated string of arbitrary bytes. Characters that are not valid
  2724. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  2725. * CHARACTER), which is to say two strings of random bits may turn out to
  2726. * match if they convert to the same amount of replacement characters.
  2727. *
  2728. * Note that while this function might deal with variable-sized characters,
  2729. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  2730. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  2731. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  2732. * to overflow a buffer.
  2733. *
  2734. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  2735. * strings match to this number of wchar_t (or both have matched to a
  2736. * null-terminator character before this number of bytes), they will be
  2737. * considered equal.
  2738. *
  2739. * \param str1 the first string to compare. NULL is not permitted!
  2740. * \param str2 the second string to compare. NULL is not permitted!
  2741. * \param maxlen the maximum number of wchar_t values to compare.
  2742. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2743. * str1 is "greater than" str2, and zero if the strings match
  2744. * exactly.
  2745. *
  2746. * \threadsafety It is safe to call this function from any thread.
  2747. *
  2748. * \since This function is available since SDL 3.1.3.
  2749. */
  2750. extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  2751. /**
  2752. * Parse a `long` from a wide string.
  2753. *
  2754. * If `str` starts with whitespace, then those whitespace characters are
  2755. * skipped before attempting to parse the number.
  2756. *
  2757. * If the parsed number does not fit inside a `long`, the result is clamped to
  2758. * the minimum and maximum representable `long` values.
  2759. *
  2760. * \param str The null-terminated wide string to read. Must not be NULL.
  2761. * \param endp If not NULL, the address of the first invalid wide character
  2762. * (i.e. the next character after the parsed number) will be
  2763. * written to this pointer.
  2764. * \param base The base of the integer to read. Supported values are 0 and 2
  2765. * to 36 inclusive. If 0, the base will be inferred from the
  2766. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  2767. * otherwise).
  2768. * \returns the parsed `long`, or 0 if no number could be parsed.
  2769. *
  2770. * \threadsafety It is safe to call this function from any thread.
  2771. *
  2772. * \since This function is available since SDL 3.1.3.
  2773. *
  2774. * \sa SDL_strtol
  2775. */
  2776. extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  2777. /**
  2778. * This works exactly like strlen() but doesn't require access to a C runtime.
  2779. *
  2780. * Counts the bytes in `str`, excluding the null terminator.
  2781. *
  2782. * If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
  2783. *
  2784. * \param str The null-terminated string to read. Must not be NULL.
  2785. * \returns the length (in bytes, excluding the null terminator) of `src`.
  2786. *
  2787. * \threadsafety It is safe to call this function from any thread.
  2788. *
  2789. * \since This function is available since SDL 3.1.3.
  2790. *
  2791. * \sa SDL_strnlen
  2792. * \sa SDL_utf8strlen
  2793. * \sa SDL_utf8strnlen
  2794. */
  2795. extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  2796. /**
  2797. * This works exactly like strnlen() but doesn't require access to a C
  2798. * runtime.
  2799. *
  2800. * Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
  2801. * terminator.
  2802. *
  2803. * If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
  2804. *
  2805. * \param str The null-terminated string to read. Must not be NULL.
  2806. * \param maxlen The maximum amount of bytes to count.
  2807. * \returns the length (in bytes, excluding the null terminator) of `src` but
  2808. * never more than `maxlen`.
  2809. *
  2810. * \threadsafety It is safe to call this function from any thread.
  2811. *
  2812. * \since This function is available since SDL 3.1.3.
  2813. *
  2814. * \sa SDL_strlen
  2815. * \sa SDL_utf8strlen
  2816. * \sa SDL_utf8strnlen
  2817. */
  2818. extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  2819. /**
  2820. * Copy a string.
  2821. *
  2822. * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
  2823. * then appends a null terminator.
  2824. *
  2825. * If `maxlen` is 0, no characters are copied and no null terminator is
  2826. * written.
  2827. *
  2828. * If you want to copy an UTF-8 string but need to ensure that multi-byte
  2829. * sequences are not truncated, consider using SDL_utf8strlcpy().
  2830. *
  2831. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2832. * with `src`.
  2833. * \param src The null-terminated string to copy. Must not be NULL, and must
  2834. * not overlap with `dst`.
  2835. * \param maxlen The length (in characters) of the destination buffer.
  2836. * \returns the length (in characters, excluding the null terminator) of
  2837. * `src`.
  2838. *
  2839. * \threadsafety It is safe to call this function from any thread.
  2840. *
  2841. * \since This function is available since SDL 3.1.3.
  2842. *
  2843. * \sa SDL_strlcat
  2844. * \sa SDL_utf8strlcpy
  2845. */
  2846. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  2847. /**
  2848. * Copy an UTF-8 string.
  2849. *
  2850. * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
  2851. * also ensuring that the string written to `dst` does not end in a truncated
  2852. * multi-byte sequence. Finally, it appends a null terminator.
  2853. *
  2854. * `src` and `dst` must not overlap.
  2855. *
  2856. * Note that unlike SDL_strlcpy(), this function returns the number of bytes
  2857. * written, not the length of `src`.
  2858. *
  2859. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2860. * with `src`.
  2861. * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
  2862. * must not overlap with `dst`.
  2863. * \param dst_bytes The length (in bytes) of the destination buffer. Must not
  2864. * be 0.
  2865. * \returns the number of bytes written, excluding the null terminator.
  2866. *
  2867. * \threadsafety It is safe to call this function from any thread.
  2868. *
  2869. * \since This function is available since SDL 3.1.3.
  2870. *
  2871. * \sa SDL_strlcpy
  2872. */
  2873. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  2874. /**
  2875. * Concatenate strings.
  2876. *
  2877. * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
  2878. * `src` to the end of the string in `dst`, then appends a null terminator.
  2879. *
  2880. * `src` and `dst` must not overlap.
  2881. *
  2882. * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
  2883. * unmodified.
  2884. *
  2885. * \param dst The destination buffer already containing the first
  2886. * null-terminated string. Must not be NULL and must not overlap
  2887. * with `src`.
  2888. * \param src The second null-terminated string. Must not be NULL, and must
  2889. * not overlap with `dst`.
  2890. * \param maxlen The length (in characters) of the destination buffer.
  2891. * \returns the length (in characters, excluding the null terminator) of the
  2892. * string in `dst` plus the length of `src`.
  2893. *
  2894. * \threadsafety It is safe to call this function from any thread.
  2895. *
  2896. * \since This function is available since SDL 3.1.3.
  2897. *
  2898. * \sa SDL_strlcpy
  2899. */
  2900. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  2901. /**
  2902. * Allocate a copy of a string.
  2903. *
  2904. * This allocates enough space for a null-terminated copy of `str`, using
  2905. * SDL_malloc, and then makes a copy of the string into this space.
  2906. *
  2907. * The returned string is owned by the caller, and should be passed to
  2908. * SDL_free when no longer needed.
  2909. *
  2910. * \param str the string to copy.
  2911. * \returns a pointer to the newly-allocated string.
  2912. *
  2913. * \threadsafety It is safe to call this function from any thread.
  2914. *
  2915. * \since This function is available since SDL 3.1.3.
  2916. */
  2917. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
  2918. /**
  2919. * Allocate a copy of a string, up to n characters.
  2920. *
  2921. * This allocates enough space for a null-terminated copy of `str`, up to
  2922. * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
  2923. * this space.
  2924. *
  2925. * If the string is longer than `maxlen` bytes, the returned string will be
  2926. * `maxlen` bytes long, plus a null-terminator character that isn't included
  2927. * in the count.
  2928. *
  2929. * The returned string is owned by the caller, and should be passed to
  2930. * SDL_free when no longer needed.
  2931. *
  2932. * \param str the string to copy.
  2933. * \param maxlen the maximum length of the copied string, not counting the
  2934. * null-terminator character.
  2935. * \returns a pointer to the newly-allocated string.
  2936. *
  2937. * \threadsafety It is safe to call this function from any thread.
  2938. *
  2939. * \since This function is available since SDL 3.1.3.
  2940. */
  2941. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
  2942. /**
  2943. * Reverse a string's contents.
  2944. *
  2945. * This reverses a null-terminated string in-place. Only the content of the
  2946. * string is reversed; the null-terminator character remains at the end of the
  2947. * reversed string.
  2948. *
  2949. * **WARNING**: This function reverses the _bytes_ of the string, not the
  2950. * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
  2951. * will ruin the string data. You should only use this function on strings
  2952. * that are completely comprised of low ASCII characters.
  2953. *
  2954. * \param str the string to reverse.
  2955. * \returns `str`.
  2956. *
  2957. * \threadsafety It is safe to call this function from any thread.
  2958. *
  2959. * \since This function is available since SDL 3.1.3.
  2960. */
  2961. extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
  2962. /**
  2963. * Convert a string to uppercase.
  2964. *
  2965. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2966. * values 'A' through 'Z' to uppercase.
  2967. *
  2968. * This function operates on a null-terminated string of bytes--even if it is
  2969. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  2970. * uppercase equivalents in-place, returning the original `str` pointer.
  2971. *
  2972. * \param str the string to convert in-place. Can not be NULL.
  2973. * \returns the `str` pointer passed into this function.
  2974. *
  2975. * \threadsafety It is safe to call this function from any thread.
  2976. *
  2977. * \since This function is available since SDL 3.1.3.
  2978. *
  2979. * \sa SDL_strlwr
  2980. */
  2981. extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
  2982. /**
  2983. * Convert a string to lowercase.
  2984. *
  2985. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2986. * values 'A' through 'Z' to lowercase.
  2987. *
  2988. * This function operates on a null-terminated string of bytes--even if it is
  2989. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  2990. * lowercase equivalents in-place, returning the original `str` pointer.
  2991. *
  2992. * \param str the string to convert in-place. Can not be NULL.
  2993. * \returns the `str` pointer passed into this function.
  2994. *
  2995. * \threadsafety It is safe to call this function from any thread.
  2996. *
  2997. * \since This function is available since SDL 3.1.3.
  2998. *
  2999. * \sa SDL_strupr
  3000. */
  3001. extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
  3002. /**
  3003. * Search a string for the first instance of a specific byte.
  3004. *
  3005. * The search ends once it finds the requested byte value, or a null
  3006. * terminator byte to end the string.
  3007. *
  3008. * Note that this looks for _bytes_, not _characters_, so you cannot match
  3009. * against a Unicode codepoint > 255, regardless of character encoding.
  3010. *
  3011. * \param str the string to search. Must not be NULL.
  3012. * \param c the byte value to search for.
  3013. * \returns a pointer to the first instance of `c` in the string, or NULL if
  3014. * not found.
  3015. *
  3016. * \threadsafety It is safe to call this function from any thread.
  3017. *
  3018. * \since This function is available since SDL 3.1.3.
  3019. */
  3020. extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
  3021. /**
  3022. * Search a string for the last instance of a specific byte.
  3023. *
  3024. * The search must go until it finds a null terminator byte to end the string.
  3025. *
  3026. * Note that this looks for _bytes_, not _characters_, so you cannot match
  3027. * against a Unicode codepoint > 255, regardless of character encoding.
  3028. *
  3029. * \param str the string to search. Must not be NULL.
  3030. * \param c the byte value to search for.
  3031. * \returns a pointer to the last instance of `c` in the string, or NULL if
  3032. * not found.
  3033. *
  3034. * \threadsafety It is safe to call this function from any thread.
  3035. *
  3036. * \since This function is available since SDL 3.1.3.
  3037. */
  3038. extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
  3039. /**
  3040. * Search a string for the first instance of a specific substring.
  3041. *
  3042. * The search ends once it finds the requested substring, or a null terminator
  3043. * byte to end the string.
  3044. *
  3045. * Note that this looks for strings of _bytes_, not _characters_, so it's
  3046. * legal to search for malformed and incomplete UTF-8 sequences.
  3047. *
  3048. * \param haystack the string to search. Must not be NULL.
  3049. * \param needle the string to search for. Must not be NULL.
  3050. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3051. * if not found.
  3052. *
  3053. * \threadsafety It is safe to call this function from any thread.
  3054. *
  3055. * \since This function is available since SDL 3.1.3.
  3056. */
  3057. extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
  3058. /**
  3059. * Search a string, up to n bytes, for the first instance of a specific
  3060. * substring.
  3061. *
  3062. * The search ends once it finds the requested substring, or a null terminator
  3063. * byte to end the string, or `maxlen` bytes have been examined. It is
  3064. * possible to use this function on a string without a null terminator.
  3065. *
  3066. * Note that this looks for strings of _bytes_, not _characters_, so it's
  3067. * legal to search for malformed and incomplete UTF-8 sequences.
  3068. *
  3069. * \param haystack the string to search. Must not be NULL.
  3070. * \param needle the string to search for. Must not be NULL.
  3071. * \param maxlen the maximum number of bytes to search in `haystack`.
  3072. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3073. * if not found.
  3074. *
  3075. * \threadsafety It is safe to call this function from any thread.
  3076. *
  3077. * \since This function is available since SDL 3.1.3.
  3078. */
  3079. extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  3080. /**
  3081. * Search a UTF-8 string for the first instance of a specific substring,
  3082. * case-insensitively.
  3083. *
  3084. * This will work with Unicode strings, using a technique called
  3085. * "case-folding" to handle the vast majority of case-sensitive human
  3086. * languages regardless of system locale. It can deal with expanding values: a
  3087. * German Eszett character can compare against two ASCII 's' chars and be
  3088. * considered a match, for example. A notable exception: it does not handle
  3089. * the Turkish 'i' character; human language is complicated!
  3090. *
  3091. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3092. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3093. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3094. * CHARACTER), which is to say two strings of random bits may turn out to
  3095. * match if they convert to the same amount of replacement characters.
  3096. *
  3097. * \param haystack the string to search. Must not be NULL.
  3098. * \param needle the string to search for. Must not be NULL.
  3099. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3100. * if not found.
  3101. *
  3102. * \threadsafety It is safe to call this function from any thread.
  3103. *
  3104. * \since This function is available since SDL 3.1.3.
  3105. */
  3106. extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  3107. /**
  3108. * This works exactly like strtok_r() but doesn't require access to a C
  3109. * runtime.
  3110. *
  3111. * Break a string up into a series of tokens.
  3112. *
  3113. * To start tokenizing a new string, `str` should be the non-NULL address of
  3114. * the string to start tokenizing. Future calls to get the next token from the
  3115. * same string should specify a NULL.
  3116. *
  3117. * Note that this function will overwrite pieces of `str` with null chars to
  3118. * split it into tokens. This function cannot be used with const/read-only
  3119. * strings!
  3120. *
  3121. * `saveptr` just needs to point to a `char *` that can be overwritten; SDL
  3122. * will use this to save tokenizing state between calls. It is initialized if
  3123. * `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
  3124. *
  3125. * \param str the string to tokenize, or NULL to continue tokenizing.
  3126. * \param delim the delimiter string that separates tokens.
  3127. * \param saveptr pointer to a char *, used for ongoing state.
  3128. * \returns A pointer to the next token, or NULL if no tokens remain.
  3129. *
  3130. * \threadsafety It is safe to call this function from any thread.
  3131. *
  3132. * \since This function is available since SDL 3.1.3.
  3133. */
  3134. extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
  3135. /**
  3136. * Count the number of codepoints in a UTF-8 string.
  3137. *
  3138. * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
  3139. * terminator.
  3140. *
  3141. * If you need to count the bytes in a string instead, consider using
  3142. * SDL_strlen().
  3143. *
  3144. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3145. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3146. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3147. * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
  3148. * count by several replacement characters.
  3149. *
  3150. * \param str The null-terminated UTF-8 string to read. Must not be NULL.
  3151. * \returns The length (in codepoints, excluding the null terminator) of
  3152. * `src`.
  3153. *
  3154. * \threadsafety It is safe to call this function from any thread.
  3155. *
  3156. * \since This function is available since SDL 3.1.3.
  3157. *
  3158. * \sa SDL_utf8strnlen
  3159. * \sa SDL_strlen
  3160. */
  3161. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  3162. /**
  3163. * Count the number of codepoints in a UTF-8 string, up to n bytes.
  3164. *
  3165. * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
  3166. * terminator.
  3167. *
  3168. * If you need to count the bytes in a string instead, consider using
  3169. * SDL_strnlen().
  3170. *
  3171. * The counting stops at `bytes` bytes (not codepoints!). This seems
  3172. * counterintuitive, but makes it easy to express the total size of the
  3173. * string's buffer.
  3174. *
  3175. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3176. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3177. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3178. * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
  3179. * count by several replacement characters.
  3180. *
  3181. * \param str The null-terminated UTF-8 string to read. Must not be NULL.
  3182. * \param bytes The maximum amount of bytes to count.
  3183. * \returns The length (in codepoints, excluding the null terminator) of `src`
  3184. * but never more than `maxlen`.
  3185. *
  3186. * \threadsafety It is safe to call this function from any thread.
  3187. *
  3188. * \since This function is available since SDL 3.1.3.
  3189. *
  3190. * \sa SDL_utf8strlen
  3191. * \sa SDL_strnlen
  3192. */
  3193. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  3194. /**
  3195. * Convert an integer into a string.
  3196. *
  3197. * This requires a radix to specified for string format. Specifying 10
  3198. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3199. * to 36.
  3200. *
  3201. * Note that this function will overflow a buffer if `str` is not large enough
  3202. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3203. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3204. * much more space than you expect to use (and don't forget possible negative
  3205. * signs, null terminator bytes, etc).
  3206. *
  3207. * \param value the integer to convert.
  3208. * \param str the buffer to write the string into.
  3209. * \param radix the radix to use for string generation.
  3210. * \returns `str`.
  3211. *
  3212. * \threadsafety It is safe to call this function from any thread.
  3213. *
  3214. * \since This function is available since SDL 3.1.3.
  3215. *
  3216. * \sa SDL_uitoa
  3217. * \sa SDL_ltoa
  3218. * \sa SDL_lltoa
  3219. */
  3220. extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
  3221. /**
  3222. * Convert an unsigned integer into a string.
  3223. *
  3224. * This requires a radix to specified for string format. Specifying 10
  3225. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3226. * to 36.
  3227. *
  3228. * Note that this function will overflow a buffer if `str` is not large enough
  3229. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3230. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3231. * much more space than you expect to use (and don't forget null terminator
  3232. * bytes, etc).
  3233. *
  3234. * \param value the unsigned integer to convert.
  3235. * \param str the buffer to write the string into.
  3236. * \param radix the radix to use for string generation.
  3237. * \returns `str`.
  3238. *
  3239. * \threadsafety It is safe to call this function from any thread.
  3240. *
  3241. * \since This function is available since SDL 3.1.3.
  3242. *
  3243. * \sa SDL_itoa
  3244. * \sa SDL_ultoa
  3245. * \sa SDL_ulltoa
  3246. */
  3247. extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  3248. /**
  3249. * Convert a long integer into a string.
  3250. *
  3251. * This requires a radix to specified for string format. Specifying 10
  3252. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3253. * to 36.
  3254. *
  3255. * Note that this function will overflow a buffer if `str` is not large enough
  3256. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3257. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3258. * much more space than you expect to use (and don't forget possible negative
  3259. * signs, null terminator bytes, etc).
  3260. *
  3261. * \param value the long integer to convert.
  3262. * \param str the buffer to write the string into.
  3263. * \param radix the radix to use for string generation.
  3264. * \returns `str`.
  3265. *
  3266. * \threadsafety It is safe to call this function from any thread.
  3267. *
  3268. * \since This function is available since SDL 3.1.3.
  3269. *
  3270. * \sa SDL_ultoa
  3271. * \sa SDL_itoa
  3272. * \sa SDL_lltoa
  3273. */
  3274. extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
  3275. /**
  3276. * Convert an unsigned long integer into a string.
  3277. *
  3278. * This requires a radix to specified for string format. Specifying 10
  3279. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3280. * to 36.
  3281. *
  3282. * Note that this function will overflow a buffer if `str` is not large enough
  3283. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3284. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3285. * much more space than you expect to use (and don't forget null terminator
  3286. * bytes, etc).
  3287. *
  3288. * \param value the unsigned long integer to convert.
  3289. * \param str the buffer to write the string into.
  3290. * \param radix the radix to use for string generation.
  3291. * \returns `str`.
  3292. *
  3293. * \threadsafety It is safe to call this function from any thread.
  3294. *
  3295. * \since This function is available since SDL 3.1.3.
  3296. *
  3297. * \sa SDL_ltoa
  3298. * \sa SDL_uitoa
  3299. * \sa SDL_ulltoa
  3300. */
  3301. extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  3302. /**
  3303. * Convert a long long integer into a string.
  3304. *
  3305. * This requires a radix to specified for string format. Specifying 10
  3306. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3307. * to 36.
  3308. *
  3309. * Note that this function will overflow a buffer if `str` is not large enough
  3310. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3311. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3312. * much more space than you expect to use (and don't forget possible negative
  3313. * signs, null terminator bytes, etc).
  3314. *
  3315. * \param value the long long integer to convert.
  3316. * \param str the buffer to write the string into.
  3317. * \param radix the radix to use for string generation.
  3318. * \returns `str`.
  3319. *
  3320. * \threadsafety It is safe to call this function from any thread.
  3321. *
  3322. * \since This function is available since SDL 3.1.3.
  3323. *
  3324. * \sa SDL_ulltoa
  3325. * \sa SDL_itoa
  3326. * \sa SDL_ltoa
  3327. */
  3328. extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
  3329. /**
  3330. * Convert an unsigned long long integer into a string.
  3331. *
  3332. * This requires a radix to specified for string format. Specifying 10
  3333. * produces a decimal number, 16 hexidecimal, etc. Must be in the range of 2
  3334. * to 36.
  3335. *
  3336. * Note that this function will overflow a buffer if `str` is not large enough
  3337. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3338. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3339. * much more space than you expect to use (and don't forget null terminator
  3340. * bytes, etc).
  3341. *
  3342. * \param value the unsigned long long integer to convert.
  3343. * \param str the buffer to write the string into.
  3344. * \param radix the radix to use for string generation.
  3345. * \returns `str`.
  3346. *
  3347. * \threadsafety It is safe to call this function from any thread.
  3348. *
  3349. * \since This function is available since SDL 3.1.3.
  3350. *
  3351. * \sa SDL_lltoa
  3352. * \sa SDL_uitoa
  3353. * \sa SDL_ultoa
  3354. */
  3355. extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
  3356. /**
  3357. * Parse an `int` from a string.
  3358. *
  3359. * The result of calling `SDL_atoi(str)` is equivalent to
  3360. * `(int)SDL_strtol(str, NULL, 10)`.
  3361. *
  3362. * \param str The null-terminated string to read. Must not be NULL.
  3363. * \returns the parsed `int`.
  3364. *
  3365. * \threadsafety It is safe to call this function from any thread.
  3366. *
  3367. * \since This function is available since SDL 3.1.3.
  3368. *
  3369. * \sa SDL_atof
  3370. * \sa SDL_strtol
  3371. * \sa SDL_strtoul
  3372. * \sa SDL_strtoll
  3373. * \sa SDL_strtoull
  3374. * \sa SDL_strtod
  3375. * \sa SDL_itoa
  3376. */
  3377. extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
  3378. /**
  3379. * Parse a `double` from a string.
  3380. *
  3381. * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
  3382. * NULL)`.
  3383. *
  3384. * \param str The null-terminated string to read. Must not be NULL.
  3385. * \returns the parsed `double`.
  3386. *
  3387. * \threadsafety It is safe to call this function from any thread.
  3388. *
  3389. * \since This function is available since SDL 3.1.3.
  3390. *
  3391. * \sa SDL_atoi
  3392. * \sa SDL_strtol
  3393. * \sa SDL_strtoul
  3394. * \sa SDL_strtoll
  3395. * \sa SDL_strtoull
  3396. * \sa SDL_strtod
  3397. */
  3398. extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
  3399. /**
  3400. * Parse a `long` from a string.
  3401. *
  3402. * If `str` starts with whitespace, then those whitespace characters are
  3403. * skipped before attempting to parse the number.
  3404. *
  3405. * If the parsed number does not fit inside a `long`, the result is clamped to
  3406. * the minimum and maximum representable `long` values.
  3407. *
  3408. * \param str The null-terminated string to read. Must not be NULL.
  3409. * \param endp If not NULL, the address of the first invalid character (i.e.
  3410. * the next character after the parsed number) will be written to
  3411. * this pointer.
  3412. * \param base The base of the integer to read. Supported values are 0 and 2
  3413. * to 36 inclusive. If 0, the base will be inferred from the
  3414. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3415. * otherwise).
  3416. * \returns the parsed `long`, or 0 if no number could be parsed.
  3417. *
  3418. * \threadsafety It is safe to call this function from any thread.
  3419. *
  3420. * \since This function is available since SDL 3.1.3.
  3421. *
  3422. * \sa SDL_atoi
  3423. * \sa SDL_atof
  3424. * \sa SDL_strtoul
  3425. * \sa SDL_strtoll
  3426. * \sa SDL_strtoull
  3427. * \sa SDL_strtod
  3428. * \sa SDL_ltoa
  3429. * \sa SDL_wcstol
  3430. */
  3431. extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  3432. /**
  3433. * Parse an `unsigned long` from a string.
  3434. *
  3435. * If `str` starts with whitespace, then those whitespace characters are
  3436. * skipped before attempting to parse the number.
  3437. *
  3438. * If the parsed number does not fit inside an `unsigned long`, the result is
  3439. * clamped to the maximum representable `unsigned long` value.
  3440. *
  3441. * \param str The null-terminated string to read. Must not be NULL.
  3442. * \param endp If not NULL, the address of the first invalid character (i.e.
  3443. * the next character after the parsed number) will be written to
  3444. * this pointer.
  3445. * \param base The base of the integer to read. Supported values are 0 and 2
  3446. * to 36 inclusive. If 0, the base will be inferred from the
  3447. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3448. * otherwise).
  3449. * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
  3450. *
  3451. * \threadsafety It is safe to call this function from any thread.
  3452. *
  3453. * \since This function is available since SDL 3.1.3.
  3454. *
  3455. * \sa SDL_atoi
  3456. * \sa SDL_atof
  3457. * \sa SDL_strtol
  3458. * \sa SDL_strtoll
  3459. * \sa SDL_strtoull
  3460. * \sa SDL_strtod
  3461. * \sa SDL_ultoa
  3462. */
  3463. extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  3464. /**
  3465. * Parse a `long long` from a string.
  3466. *
  3467. * If `str` starts with whitespace, then those whitespace characters are
  3468. * skipped before attempting to parse the number.
  3469. *
  3470. * If the parsed number does not fit inside a `long long`, the result is
  3471. * clamped to the minimum and maximum representable `long long` values.
  3472. *
  3473. * \param str The null-terminated string to read. Must not be NULL.
  3474. * \param endp If not NULL, the address of the first invalid character (i.e.
  3475. * the next character after the parsed number) will be written to
  3476. * this pointer.
  3477. * \param base The base of the integer to read. Supported values are 0 and 2
  3478. * to 36 inclusive. If 0, the base will be inferred from the
  3479. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3480. * otherwise).
  3481. * \returns the parsed `long long`, or 0 if no number could be parsed.
  3482. *
  3483. * \threadsafety It is safe to call this function from any thread.
  3484. *
  3485. * \since This function is available since SDL 3.1.3.
  3486. *
  3487. * \sa SDL_atoi
  3488. * \sa SDL_atof
  3489. * \sa SDL_strtol
  3490. * \sa SDL_strtoul
  3491. * \sa SDL_strtoull
  3492. * \sa SDL_strtod
  3493. * \sa SDL_lltoa
  3494. */
  3495. extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  3496. /**
  3497. * Parse an `unsigned long long` from a string.
  3498. *
  3499. * If `str` starts with whitespace, then those whitespace characters are
  3500. * skipped before attempting to parse the number.
  3501. *
  3502. * If the parsed number does not fit inside an `unsigned long long`, the
  3503. * result is clamped to the maximum representable `unsigned long long` value.
  3504. *
  3505. * \param str The null-terminated string to read. Must not be NULL.
  3506. * \param endp If not NULL, the address of the first invalid character (i.e.
  3507. * the next character after the parsed number) will be written to
  3508. * this pointer.
  3509. * \param base The base of the integer to read. Supported values are 0 and 2
  3510. * to 36 inclusive. If 0, the base will be inferred from the
  3511. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3512. * otherwise).
  3513. * \returns the parsed `unsigned long long`, or 0 if no number could be
  3514. * parsed.
  3515. *
  3516. * \threadsafety It is safe to call this function from any thread.
  3517. *
  3518. * \since This function is available since SDL 3.1.3.
  3519. *
  3520. * \sa SDL_atoi
  3521. * \sa SDL_atof
  3522. * \sa SDL_strtol
  3523. * \sa SDL_strtoll
  3524. * \sa SDL_strtoul
  3525. * \sa SDL_strtod
  3526. * \sa SDL_ulltoa
  3527. */
  3528. extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  3529. /**
  3530. * Parse a `double` from a string.
  3531. *
  3532. * This function makes fewer guarantees than the C runtime `strtod`:
  3533. *
  3534. * - Only decimal notation is guaranteed to be supported. The handling of
  3535. * scientific and hexadecimal notation is unspecified.
  3536. * - Whether or not INF and NAN can be parsed is unspecified.
  3537. * - The precision of the result is unspecified.
  3538. *
  3539. * \param str the null-terminated string to read. Must not be NULL.
  3540. * \param endp if not NULL, the address of the first invalid character (i.e.
  3541. * the next character after the parsed number) will be written to
  3542. * this pointer.
  3543. * \returns the parsed `double`, or 0 if no number could be parsed.
  3544. *
  3545. * \threadsafety It is safe to call this function from any thread.
  3546. *
  3547. * \since This function is available since SDL 3.1.3.
  3548. *
  3549. * \sa SDL_atoi
  3550. * \sa SDL_atof
  3551. * \sa SDL_strtol
  3552. * \sa SDL_strtoll
  3553. * \sa SDL_strtoul
  3554. * \sa SDL_strtoull
  3555. */
  3556. extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  3557. /**
  3558. * Compare two null-terminated UTF-8 strings.
  3559. *
  3560. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  3561. * since effectively this function just compares bytes until it hits a
  3562. * null-terminating character. Also due to the nature of UTF-8, this can be
  3563. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  3564. *
  3565. * \param str1 the first string to compare. NULL is not permitted!
  3566. * \param str2 the second string to compare. NULL is not permitted!
  3567. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3568. * str1 is "greater than" str2, and zero if the strings match
  3569. * exactly.
  3570. *
  3571. * \threadsafety It is safe to call this function from any thread.
  3572. *
  3573. * \since This function is available since SDL 3.1.3.
  3574. */
  3575. extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  3576. /**
  3577. * Compare two UTF-8 strings up to a number of bytes.
  3578. *
  3579. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  3580. * since effectively this function just compares bytes until it hits a
  3581. * null-terminating character. Also due to the nature of UTF-8, this can be
  3582. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  3583. *
  3584. * Note that while this function is intended to be used with UTF-8, it is
  3585. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  3586. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  3587. * compare a portion of the final character.
  3588. *
  3589. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  3590. * match to this number of bytes (or both have matched to a null-terminator
  3591. * character before this number of bytes), they will be considered equal.
  3592. *
  3593. * \param str1 the first string to compare. NULL is not permitted!
  3594. * \param str2 the second string to compare. NULL is not permitted!
  3595. * \param maxlen the maximum number of _bytes_ to compare.
  3596. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3597. * str1 is "greater than" str2, and zero if the strings match
  3598. * exactly.
  3599. *
  3600. * \threadsafety It is safe to call this function from any thread.
  3601. *
  3602. * \since This function is available since SDL 3.1.3.
  3603. */
  3604. extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  3605. /**
  3606. * Compare two null-terminated UTF-8 strings, case-insensitively.
  3607. *
  3608. * This will work with Unicode strings, using a technique called
  3609. * "case-folding" to handle the vast majority of case-sensitive human
  3610. * languages regardless of system locale. It can deal with expanding values: a
  3611. * German Eszett character can compare against two ASCII 's' chars and be
  3612. * considered a match, for example. A notable exception: it does not handle
  3613. * the Turkish 'i' character; human language is complicated!
  3614. *
  3615. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  3616. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3617. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3618. * CHARACTER), which is to say two strings of random bits may turn out to
  3619. * match if they convert to the same amount of replacement characters.
  3620. *
  3621. * \param str1 the first string to compare. NULL is not permitted!
  3622. * \param str2 the second string to compare. NULL is not permitted!
  3623. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3624. * str1 is "greater than" str2, and zero if the strings match
  3625. * exactly.
  3626. *
  3627. * \threadsafety It is safe to call this function from any thread.
  3628. *
  3629. * \since This function is available since SDL 3.1.3.
  3630. */
  3631. extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  3632. /**
  3633. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  3634. *
  3635. * This will work with Unicode strings, using a technique called
  3636. * "case-folding" to handle the vast majority of case-sensitive human
  3637. * languages regardless of system locale. It can deal with expanding values: a
  3638. * German Eszett character can compare against two ASCII 's' chars and be
  3639. * considered a match, for example. A notable exception: it does not handle
  3640. * the Turkish 'i' character; human language is complicated!
  3641. *
  3642. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  3643. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3644. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3645. * CHARACTER), which is to say two strings of random bits may turn out to
  3646. * match if they convert to the same amount of replacement characters.
  3647. *
  3648. * Note that while this function is intended to be used with UTF-8, `maxlen`
  3649. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  3650. * UTF-8 sequence, it may convert a portion of the final character to one or
  3651. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  3652. * a buffer.
  3653. *
  3654. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  3655. * match to this number of bytes (or both have matched to a null-terminator
  3656. * character before this number of bytes), they will be considered equal.
  3657. *
  3658. * \param str1 the first string to compare. NULL is not permitted!
  3659. * \param str2 the second string to compare. NULL is not permitted!
  3660. * \param maxlen the maximum number of bytes to compare.
  3661. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3662. * str1 is "greater than" str2, and zero if the strings match
  3663. * exactly.
  3664. *
  3665. * \threadsafety It is safe to call this function from any thread.
  3666. *
  3667. * \since This function is available since SDL 3.1.3.
  3668. */
  3669. extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  3670. /**
  3671. * Searches a string for the first occurence of any character contained in a
  3672. * breakset, and returns a pointer from the string to that character.
  3673. *
  3674. * \param str The null-terminated string to be searched. Must not be NULL, and
  3675. * must not overlap with `breakset`.
  3676. * \param breakset A null-terminated string containing the list of characters
  3677. * to look for. Must not be NULL, and must not overlap with
  3678. * `str`.
  3679. * \returns A pointer to the location, in str, of the first occurence of a
  3680. * character present in the breakset, or NULL if none is found.
  3681. *
  3682. * \threadsafety It is safe to call this function from any thread.
  3683. *
  3684. * \since This function is available since SDL 3.1.3.
  3685. */
  3686. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
  3687. /**
  3688. * The Unicode REPLACEMENT CHARACTER codepoint.
  3689. *
  3690. * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
  3691. * encounter a UTF-8 string with encoding errors.
  3692. *
  3693. * This tends to render as something like a question mark in most places.
  3694. *
  3695. * \since This macro is available since SDL 3.1.3.
  3696. *
  3697. * \sa SDL_StepBackUTF8
  3698. * \sa SDL_StepUTF8
  3699. */
  3700. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  3701. /**
  3702. * Decode a UTF-8 string, one Unicode codepoint at a time.
  3703. *
  3704. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  3705. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  3706. *
  3707. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  3708. * be adjusted, as well, subtracting the number of bytes consumed.
  3709. *
  3710. * `pslen` is allowed to be NULL, in which case the string _must_ be
  3711. * NULL-terminated, as the function will blindly read until it sees the NULL
  3712. * char.
  3713. *
  3714. * if `*pslen` is zero, it assumes the end of string is reached and returns a
  3715. * zero codepoint regardless of the contents of the string buffer.
  3716. *
  3717. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  3718. * zero, it will not advance `*pstr` or `*pslen` at all.
  3719. *
  3720. * Generally this function is called in a loop until it returns zero,
  3721. * adjusting its parameters each iteration.
  3722. *
  3723. * If an invalid UTF-8 sequence is encountered, this function returns
  3724. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  3725. * (which is to say, a multibyte sequence might produce several
  3726. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  3727. * UTF-8 sequence).
  3728. *
  3729. * Several things can generate invalid UTF-8 sequences, including overlong
  3730. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  3731. * refer to
  3732. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  3733. * for details.
  3734. *
  3735. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  3736. * \param pslen a pointer to the number of bytes in the string, to be read and
  3737. * adjusted. NULL is allowed.
  3738. * \returns the first Unicode codepoint in the string.
  3739. *
  3740. * \threadsafety It is safe to call this function from any thread.
  3741. *
  3742. * \since This function is available since SDL 3.1.3.
  3743. */
  3744. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  3745. /**
  3746. * Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
  3747. *
  3748. * This will go to the start of the previous Unicode codepoint in the string,
  3749. * move `*pstr` to that location and return that codepoint.
  3750. *
  3751. * If `*pstr` is already at the start of the string), it will not advance
  3752. * `*pstr` at all.
  3753. *
  3754. * Generally this function is called in a loop until it returns zero,
  3755. * adjusting its parameter each iteration.
  3756. *
  3757. * If an invalid UTF-8 sequence is encountered, this function returns
  3758. * SDL_INVALID_UNICODE_CODEPOINT.
  3759. *
  3760. * Several things can generate invalid UTF-8 sequences, including overlong
  3761. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  3762. * refer to
  3763. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  3764. * for details.
  3765. *
  3766. * \param start a pointer to the beginning of the UTF-8 string.
  3767. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  3768. * \returns the previous Unicode codepoint in the string.
  3769. *
  3770. * \threadsafety It is safe to call this function from any thread.
  3771. *
  3772. * \since This function is available since SDL 3.1.6.
  3773. */
  3774. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
  3775. /**
  3776. * Convert a single Unicode codepoint to UTF-8.
  3777. *
  3778. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  3779. * function may generate between 1 and 4 bytes of output.
  3780. *
  3781. * This function returns the first byte _after_ the newly-written UTF-8
  3782. * sequence, which is useful for encoding multiple codepoints in a loop, or
  3783. * knowing where to write a NULL-terminator character to end the string (in
  3784. * either case, plan to have a buffer of _more_ than 4 bytes!).
  3785. *
  3786. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  3787. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  3788. * codepoint instead, and not set an error.
  3789. *
  3790. * If `dst` is NULL, this returns NULL immediately without writing to the
  3791. * pointer and without setting an error.
  3792. *
  3793. * \param codepoint a Unicode codepoint to convert to UTF-8.
  3794. * \param dst the location to write the encoded UTF-8. Must point to at least
  3795. * 4 bytes!
  3796. * \returns the first byte past the newly-written UTF-8 sequence.
  3797. *
  3798. * \threadsafety It is safe to call this function from any thread.
  3799. *
  3800. * \since This function is available since SDL 3.1.3.
  3801. */
  3802. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  3803. /**
  3804. * This works exactly like sscanf() but doesn't require access to a C runtime.
  3805. *
  3806. * Scan a string, matching a format string, converting each '%' item and
  3807. * storing it to pointers provided through variable arguments.
  3808. *
  3809. * \param text the string to scan. Must not be NULL.
  3810. * \param fmt a printf-style format string. Must not be NULL.
  3811. * \param ... a list of pointers to values to be filled in with scanned items.
  3812. * \returns the number of items that matched the format string.
  3813. *
  3814. * \threadsafety It is safe to call this function from any thread.
  3815. *
  3816. * \since This function is available since SDL 3.1.3.
  3817. */
  3818. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  3819. /**
  3820. * This works exactly like vsscanf() but doesn't require access to a C
  3821. * runtime.
  3822. *
  3823. * Functions identically to SDL_sscanf(), except it takes a `va_list` instead
  3824. * of using `...` variable arguments.
  3825. *
  3826. * \param text the string to scan. Must not be NULL.
  3827. * \param fmt a printf-style format string. Must not be NULL.
  3828. * \param ap a `va_list` of pointers to values to be filled in with scanned
  3829. * items.
  3830. * \returns the number of items that matched the format string.
  3831. *
  3832. * \threadsafety It is safe to call this function from any thread.
  3833. *
  3834. * \since This function is available since SDL 3.1.3.
  3835. */
  3836. 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);
  3837. /**
  3838. * This works exactly like snprintf() but doesn't require access to a C
  3839. * runtime.
  3840. *
  3841. * Format a string of up to `maxlen`-1 bytes, converting each '%' item with
  3842. * values provided through variable arguments.
  3843. *
  3844. * While some C runtimes differ on how to deal with too-large strings, this
  3845. * function null-terminates the output, by treating the null-terminator as
  3846. * part of the `maxlen` count. Note that if `maxlen` is zero, however, no
  3847. * bytes will be written at all.
  3848. *
  3849. * This function returns the number of _bytes_ (not _characters_) that should
  3850. * be written, excluding the null-terminator character. If this returns a
  3851. * number >= `maxlen`, it means the output string was truncated. A negative
  3852. * return value means an error occurred.
  3853. *
  3854. * Referencing the output string's pointer with a format item is undefined
  3855. * behavior.
  3856. *
  3857. * \param text the buffer to write the string into. Must not be NULL.
  3858. * \param maxlen the maximum bytes to write, including the null-terminator.
  3859. * \param fmt a printf-style format string. Must not be NULL.
  3860. * \param ... a list of values to be used with the format string.
  3861. * \returns the number of bytes that should be written, not counting the
  3862. * null-terminator char, or a negative value on error.
  3863. *
  3864. * \threadsafety It is safe to call this function from any thread.
  3865. *
  3866. * \since This function is available since SDL 3.1.3.
  3867. */
  3868. 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);
  3869. /**
  3870. * This works exactly like swprintf() but doesn't require access to a C
  3871. * runtime.
  3872. *
  3873. * Format a wide string of up to `maxlen`-1 wchar_t values, converting each
  3874. * '%' item with values provided through variable arguments.
  3875. *
  3876. * While some C runtimes differ on how to deal with too-large strings, this
  3877. * function null-terminates the output, by treating the null-terminator as
  3878. * part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
  3879. * characters will be written at all.
  3880. *
  3881. * This function returns the number of _wide characters_ (not _codepoints_)
  3882. * that should be written, excluding the null-terminator character. If this
  3883. * returns a number >= `maxlen`, it means the output string was truncated. A
  3884. * negative return value means an error occurred.
  3885. *
  3886. * Referencing the output string's pointer with a format item is undefined
  3887. * behavior.
  3888. *
  3889. * \param text the buffer to write the wide string into. Must not be NULL.
  3890. * \param maxlen the maximum wchar_t values to write, including the
  3891. * null-terminator.
  3892. * \param fmt a printf-style format string. Must not be NULL.
  3893. * \param ... a list of values to be used with the format string.
  3894. * \returns the number of wide characters that should be written, not counting
  3895. * the null-terminator char, or a negative value on error.
  3896. *
  3897. * \threadsafety It is safe to call this function from any thread.
  3898. *
  3899. * \since This function is available since SDL 3.1.3.
  3900. */
  3901. 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);
  3902. /**
  3903. * This works exactly like vsnprintf() but doesn't require access to a C
  3904. * runtime.
  3905. *
  3906. * Functions identically to SDL_snprintf(), except it takes a `va_list`
  3907. * instead of using `...` variable arguments.
  3908. *
  3909. * \param text the buffer to write the string into. Must not be NULL.
  3910. * \param maxlen the maximum bytes to write, including the null-terminator.
  3911. * \param fmt a printf-style format string. Must not be NULL.
  3912. * \param ap a `va_list` values to be used with the format string.
  3913. * \returns the number of bytes that should be written, not counting the
  3914. * null-terminator char, or a negative value on error.
  3915. *
  3916. * \threadsafety It is safe to call this function from any thread.
  3917. *
  3918. * \since This function is available since SDL 3.1.3.
  3919. */
  3920. 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);
  3921. /**
  3922. * This works exactly like vswprintf() but doesn't require access to a C
  3923. * runtime.
  3924. *
  3925. * Functions identically to SDL_swprintf(), except it takes a `va_list`
  3926. * instead of using `...` variable arguments.
  3927. *
  3928. * \param text the buffer to write the string into. Must not be NULL.
  3929. * \param maxlen the maximum wide characters to write, including the
  3930. * null-terminator.
  3931. * \param fmt a printf-style format wide string. Must not be NULL.
  3932. * \param ap a `va_list` values to be used with the format string.
  3933. * \returns the number of wide characters that should be written, not counting
  3934. * the null-terminator char, or a negative value on error.
  3935. *
  3936. * \threadsafety It is safe to call this function from any thread.
  3937. *
  3938. * \since This function is available since SDL 3.1.3.
  3939. */
  3940. 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);
  3941. /**
  3942. * This works exactly like asprintf() but doesn't require access to a C
  3943. * runtime.
  3944. *
  3945. * Functions identically to SDL_snprintf(), except it allocates a buffer large
  3946. * enough to hold the output string on behalf of the caller.
  3947. *
  3948. * On success, this function returns the number of bytes (not characters)
  3949. * comprising the output string, not counting the null-terminator character,
  3950. * and sets `*strp` to the newly-allocated string.
  3951. *
  3952. * On error, this function returns a negative number, and the value of `*strp`
  3953. * is undefined.
  3954. *
  3955. * The returned string is owned by the caller, and should be passed to
  3956. * SDL_free when no longer needed.
  3957. *
  3958. * \param strp on output, is set to the new string. Must not be NULL.
  3959. * \param fmt a printf-style format string. Must not be NULL.
  3960. * \param ... a list of values to be used with the format string.
  3961. * \returns the number of bytes in the newly-allocated string, not counting
  3962. * the null-terminator char, or a negative value on error.
  3963. *
  3964. * \threadsafety It is safe to call this function from any thread.
  3965. *
  3966. * \since This function is available since SDL 3.1.3.
  3967. */
  3968. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  3969. /**
  3970. * This works exactly like vasprintf() but doesn't require access to a C
  3971. * runtime.
  3972. *
  3973. * Functions identically to SDL_asprintf(), except it takes a `va_list`
  3974. * instead of using `...` variable arguments.
  3975. *
  3976. * \param strp on output, is set to the new string. Must not be NULL.
  3977. * \param fmt a printf-style format string. Must not be NULL.
  3978. * \param ap a `va_list` values to be used with the format string.
  3979. * \returns the number of bytes in the newly-allocated string, not counting
  3980. * the null-terminator char, or a negative value on error.
  3981. *
  3982. * \threadsafety It is safe to call this function from any thread.
  3983. *
  3984. * \since This function is available since SDL 3.1.3.
  3985. */
  3986. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  3987. /**
  3988. * Seeds the pseudo-random number generator.
  3989. *
  3990. * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
  3991. * of 'random' numbers.
  3992. *
  3993. * \param seed the value to use as a random number seed, or 0 to use
  3994. * SDL_GetPerformanceCounter().
  3995. *
  3996. * \threadsafety This should be called on the same thread that calls
  3997. * SDL_rand*()
  3998. *
  3999. * \since This function is available since SDL 3.1.3.
  4000. *
  4001. * \sa SDL_rand
  4002. * \sa SDL_rand_bits
  4003. * \sa SDL_randf
  4004. */
  4005. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  4006. /**
  4007. * Generate a pseudo-random number less than n for positive n
  4008. *
  4009. * The method used is faster and of better quality than `rand() % n`. Odds are
  4010. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  4011. * much worse as n gets bigger.
  4012. *
  4013. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  4014. * 1..6
  4015. *
  4016. * If you want to generate a pseudo-random number in the full range of Sint32,
  4017. * you should use: (Sint32)SDL_rand_bits()
  4018. *
  4019. * If you want reproducible output, be sure to initialize with SDL_srand()
  4020. * first.
  4021. *
  4022. * There are no guarantees as to the quality of the random sequence produced,
  4023. * and this should not be used for security (cryptography, passwords) or where
  4024. * money is on the line (loot-boxes, casinos). There are many random number
  4025. * libraries available with different characteristics and you should pick one
  4026. * of those to meet any serious needs.
  4027. *
  4028. * \param n the number of possible outcomes. n must be positive.
  4029. * \returns a random value in the range of [0 .. n-1].
  4030. *
  4031. * \threadsafety All calls should be made from a single thread
  4032. *
  4033. * \since This function is available since SDL 3.1.3.
  4034. *
  4035. * \sa SDL_srand
  4036. * \sa SDL_randf
  4037. */
  4038. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  4039. /**
  4040. * Generate a uniform pseudo-random floating point number less than 1.0
  4041. *
  4042. * If you want reproducible output, be sure to initialize with SDL_srand()
  4043. * first.
  4044. *
  4045. * There are no guarantees as to the quality of the random sequence produced,
  4046. * and this should not be used for security (cryptography, passwords) or where
  4047. * money is on the line (loot-boxes, casinos). There are many random number
  4048. * libraries available with different characteristics and you should pick one
  4049. * of those to meet any serious needs.
  4050. *
  4051. * \returns a random value in the range of [0.0, 1.0).
  4052. *
  4053. * \threadsafety All calls should be made from a single thread
  4054. *
  4055. * \since This function is available since SDL 3.1.3.
  4056. *
  4057. * \sa SDL_srand
  4058. * \sa SDL_rand
  4059. */
  4060. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  4061. /**
  4062. * Generate 32 pseudo-random bits.
  4063. *
  4064. * You likely want to use SDL_rand() to get a psuedo-random number instead.
  4065. *
  4066. * There are no guarantees as to the quality of the random sequence produced,
  4067. * and this should not be used for security (cryptography, passwords) or where
  4068. * money is on the line (loot-boxes, casinos). There are many random number
  4069. * libraries available with different characteristics and you should pick one
  4070. * of those to meet any serious needs.
  4071. *
  4072. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  4073. *
  4074. * \threadsafety All calls should be made from a single thread
  4075. *
  4076. * \since This function is available since SDL 3.1.3.
  4077. *
  4078. * \sa SDL_rand
  4079. * \sa SDL_randf
  4080. * \sa SDL_srand
  4081. */
  4082. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  4083. /**
  4084. * Generate a pseudo-random number less than n for positive n
  4085. *
  4086. * The method used is faster and of better quality than `rand() % n`. Odds are
  4087. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  4088. * much worse as n gets bigger.
  4089. *
  4090. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  4091. * 0..5 to 1..6
  4092. *
  4093. * If you want to generate a pseudo-random number in the full range of Sint32,
  4094. * you should use: (Sint32)SDL_rand_bits_r(state)
  4095. *
  4096. * There are no guarantees as to the quality of the random sequence produced,
  4097. * and this should not be used for security (cryptography, passwords) or where
  4098. * money is on the line (loot-boxes, casinos). There are many random number
  4099. * libraries available with different characteristics and you should pick one
  4100. * of those to meet any serious needs.
  4101. *
  4102. * \param state a pointer to the current random number state, this may not be
  4103. * NULL.
  4104. * \param n the number of possible outcomes. n must be positive.
  4105. * \returns a random value in the range of [0 .. n-1].
  4106. *
  4107. * \threadsafety This function is thread-safe, as long as the state pointer
  4108. * isn't shared between threads.
  4109. *
  4110. * \since This function is available since SDL 3.1.3.
  4111. *
  4112. * \sa SDL_rand
  4113. * \sa SDL_rand_bits_r
  4114. * \sa SDL_randf_r
  4115. */
  4116. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  4117. /**
  4118. * Generate a uniform pseudo-random floating point number less than 1.0
  4119. *
  4120. * If you want reproducible output, be sure to initialize with SDL_srand()
  4121. * first.
  4122. *
  4123. * There are no guarantees as to the quality of the random sequence produced,
  4124. * and this should not be used for security (cryptography, passwords) or where
  4125. * money is on the line (loot-boxes, casinos). There are many random number
  4126. * libraries available with different characteristics and you should pick one
  4127. * of those to meet any serious needs.
  4128. *
  4129. * \param state a pointer to the current random number state, this may not be
  4130. * NULL.
  4131. * \returns a random value in the range of [0.0, 1.0).
  4132. *
  4133. * \threadsafety This function is thread-safe, as long as the state pointer
  4134. * isn't shared between threads.
  4135. *
  4136. * \since This function is available since SDL 3.1.3.
  4137. *
  4138. * \sa SDL_rand_bits_r
  4139. * \sa SDL_rand_r
  4140. * \sa SDL_randf
  4141. */
  4142. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  4143. /**
  4144. * Generate 32 pseudo-random bits.
  4145. *
  4146. * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
  4147. *
  4148. * There are no guarantees as to the quality of the random sequence produced,
  4149. * and this should not be used for security (cryptography, passwords) or where
  4150. * money is on the line (loot-boxes, casinos). There are many random number
  4151. * libraries available with different characteristics and you should pick one
  4152. * of those to meet any serious needs.
  4153. *
  4154. * \param state a pointer to the current random number state, this may not be
  4155. * NULL.
  4156. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  4157. *
  4158. * \threadsafety This function is thread-safe, as long as the state pointer
  4159. * isn't shared between threads.
  4160. *
  4161. * \since This function is available since SDL 3.1.3.
  4162. *
  4163. * \sa SDL_rand_r
  4164. * \sa SDL_randf_r
  4165. */
  4166. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  4167. #ifndef SDL_PI_D
  4168. /**
  4169. * The value of Pi, as a double-precision floating point literal.
  4170. *
  4171. * \since This macro is available since SDL 3.1.3.
  4172. *
  4173. * \sa SDL_PI_F
  4174. */
  4175. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  4176. #endif
  4177. #ifndef SDL_PI_F
  4178. /**
  4179. * The value of Pi, as a single-precision floating point literal.
  4180. *
  4181. * \since This macro is available since SDL 3.1.3.
  4182. *
  4183. * \sa SDL_PI_D
  4184. */
  4185. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  4186. #endif
  4187. /**
  4188. * Compute the arc cosine of `x`.
  4189. *
  4190. * The definition of `y = acos(x)` is `x = cos(y)`.
  4191. *
  4192. * Domain: `-1 <= x <= 1`
  4193. *
  4194. * Range: `0 <= y <= Pi`
  4195. *
  4196. * This function operates on double-precision floating point values, use
  4197. * SDL_acosf for single-precision floats.
  4198. *
  4199. * This function may use a different approximation across different versions,
  4200. * platforms and configurations. i.e, it can return a different value given
  4201. * the same input on different machines or operating systems, or if SDL is
  4202. * updated.
  4203. *
  4204. * \param x floating point value.
  4205. * \returns arc cosine of `x`, in radians.
  4206. *
  4207. * \threadsafety It is safe to call this function from any thread.
  4208. *
  4209. * \since This function is available since SDL 3.1.3.
  4210. *
  4211. * \sa SDL_acosf
  4212. * \sa SDL_asin
  4213. * \sa SDL_cos
  4214. */
  4215. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  4216. /**
  4217. * Compute the arc cosine of `x`.
  4218. *
  4219. * The definition of `y = acos(x)` is `x = cos(y)`.
  4220. *
  4221. * Domain: `-1 <= x <= 1`
  4222. *
  4223. * Range: `0 <= y <= Pi`
  4224. *
  4225. * This function operates on single-precision floating point values, use
  4226. * SDL_acos for double-precision floats.
  4227. *
  4228. * This function may use a different approximation across different versions,
  4229. * platforms and configurations. i.e, it can return a different value given
  4230. * the same input on different machines or operating systems, or if SDL is
  4231. * updated.
  4232. *
  4233. * \param x floating point value.
  4234. * \returns arc cosine of `x`, in radians.
  4235. *
  4236. * \threadsafety It is safe to call this function from any thread.
  4237. *
  4238. * \since This function is available since SDL 3.1.3.
  4239. *
  4240. * \sa SDL_acos
  4241. * \sa SDL_asinf
  4242. * \sa SDL_cosf
  4243. */
  4244. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  4245. /**
  4246. * Compute the arc sine of `x`.
  4247. *
  4248. * The definition of `y = asin(x)` is `x = sin(y)`.
  4249. *
  4250. * Domain: `-1 <= x <= 1`
  4251. *
  4252. * Range: `-Pi/2 <= y <= Pi/2`
  4253. *
  4254. * This function operates on double-precision floating point values, use
  4255. * SDL_asinf for single-precision floats.
  4256. *
  4257. * This function may use a different approximation across different versions,
  4258. * platforms and configurations. i.e, it can return a different value given
  4259. * the same input on different machines or operating systems, or if SDL is
  4260. * updated.
  4261. *
  4262. * \param x floating point value.
  4263. * \returns arc sine of `x`, in radians.
  4264. *
  4265. * \threadsafety It is safe to call this function from any thread.
  4266. *
  4267. * \since This function is available since SDL 3.1.3.
  4268. *
  4269. * \sa SDL_asinf
  4270. * \sa SDL_acos
  4271. * \sa SDL_sin
  4272. */
  4273. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  4274. /**
  4275. * Compute the arc sine of `x`.
  4276. *
  4277. * The definition of `y = asin(x)` is `x = sin(y)`.
  4278. *
  4279. * Domain: `-1 <= x <= 1`
  4280. *
  4281. * Range: `-Pi/2 <= y <= Pi/2`
  4282. *
  4283. * This function operates on single-precision floating point values, use
  4284. * SDL_asin for double-precision floats.
  4285. *
  4286. * This function may use a different approximation across different versions,
  4287. * platforms and configurations. i.e, it can return a different value given
  4288. * the same input on different machines or operating systems, or if SDL is
  4289. * updated.
  4290. *
  4291. * \param x floating point value.
  4292. * \returns arc sine of `x`, in radians.
  4293. *
  4294. * \threadsafety It is safe to call this function from any thread.
  4295. *
  4296. * \since This function is available since SDL 3.1.3.
  4297. *
  4298. * \sa SDL_asin
  4299. * \sa SDL_acosf
  4300. * \sa SDL_sinf
  4301. */
  4302. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  4303. /**
  4304. * Compute the arc tangent of `x`.
  4305. *
  4306. * The definition of `y = atan(x)` is `x = tan(y)`.
  4307. *
  4308. * Domain: `-INF <= x <= INF`
  4309. *
  4310. * Range: `-Pi/2 <= y <= Pi/2`
  4311. *
  4312. * This function operates on double-precision floating point values, use
  4313. * SDL_atanf for single-precision floats.
  4314. *
  4315. * To calculate the arc tangent of y / x, use SDL_atan2.
  4316. *
  4317. * This function may use a different approximation across different versions,
  4318. * platforms and configurations. i.e, it can return a different value given
  4319. * the same input on different machines or operating systems, or if SDL is
  4320. * updated.
  4321. *
  4322. * \param x floating point value.
  4323. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  4324. *
  4325. * \threadsafety It is safe to call this function from any thread.
  4326. *
  4327. * \since This function is available since SDL 3.1.3.
  4328. *
  4329. * \sa SDL_atanf
  4330. * \sa SDL_atan2
  4331. * \sa SDL_tan
  4332. */
  4333. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  4334. /**
  4335. * Compute the arc tangent of `x`.
  4336. *
  4337. * The definition of `y = atan(x)` is `x = tan(y)`.
  4338. *
  4339. * Domain: `-INF <= x <= INF`
  4340. *
  4341. * Range: `-Pi/2 <= y <= Pi/2`
  4342. *
  4343. * This function operates on single-precision floating point values, use
  4344. * SDL_atan for dboule-precision floats.
  4345. *
  4346. * To calculate the arc tangent of y / x, use SDL_atan2f.
  4347. *
  4348. * This function may use a different approximation across different versions,
  4349. * platforms and configurations. i.e, it can return a different value given
  4350. * the same input on different machines or operating systems, or if SDL is
  4351. * updated.
  4352. *
  4353. * \param x floating point value.
  4354. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  4355. *
  4356. * \threadsafety It is safe to call this function from any thread.
  4357. *
  4358. * \since This function is available since SDL 3.1.3.
  4359. *
  4360. * \sa SDL_atan
  4361. * \sa SDL_atan2f
  4362. * \sa SDL_tanf
  4363. */
  4364. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  4365. /**
  4366. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  4367. * the result's quadrant.
  4368. *
  4369. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  4370. * of z is determined based on the signs of x and y.
  4371. *
  4372. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  4373. *
  4374. * Range: `-Pi/2 <= y <= Pi/2`
  4375. *
  4376. * This function operates on double-precision floating point values, use
  4377. * SDL_atan2f for single-precision floats.
  4378. *
  4379. * To calculate the arc tangent of a single value, use SDL_atan.
  4380. *
  4381. * This function may use a different approximation across different versions,
  4382. * platforms and configurations. i.e, it can return a different value given
  4383. * the same input on different machines or operating systems, or if SDL is
  4384. * updated.
  4385. *
  4386. * \param y floating point value of the numerator (y coordinate).
  4387. * \param x floating point value of the denominator (x coordinate).
  4388. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  4389. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  4390. *
  4391. * \threadsafety It is safe to call this function from any thread.
  4392. *
  4393. * \since This function is available since SDL 3.1.3.
  4394. *
  4395. * \sa SDL_atan2f
  4396. * \sa SDL_atan
  4397. * \sa SDL_tan
  4398. */
  4399. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  4400. /**
  4401. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  4402. * the result's quadrant.
  4403. *
  4404. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  4405. * of z is determined based on the signs of x and y.
  4406. *
  4407. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  4408. *
  4409. * Range: `-Pi/2 <= y <= Pi/2`
  4410. *
  4411. * This function operates on single-precision floating point values, use
  4412. * SDL_atan2 for double-precision floats.
  4413. *
  4414. * To calculate the arc tangent of a single value, use SDL_atanf.
  4415. *
  4416. * This function may use a different approximation across different versions,
  4417. * platforms and configurations. i.e, it can return a different value given
  4418. * the same input on different machines or operating systems, or if SDL is
  4419. * updated.
  4420. *
  4421. * \param y floating point value of the numerator (y coordinate).
  4422. * \param x floating point value of the denominator (x coordinate).
  4423. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  4424. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  4425. *
  4426. * \threadsafety It is safe to call this function from any thread.
  4427. *
  4428. * \since This function is available since SDL 3.1.3.
  4429. *
  4430. * \sa SDL_atan2f
  4431. * \sa SDL_atan
  4432. * \sa SDL_tan
  4433. */
  4434. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  4435. /**
  4436. * Compute the ceiling of `x`.
  4437. *
  4438. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  4439. * rounded up to the nearest integer.
  4440. *
  4441. * Domain: `-INF <= x <= INF`
  4442. *
  4443. * Range: `-INF <= y <= INF`, y integer
  4444. *
  4445. * This function operates on double-precision floating point values, use
  4446. * SDL_ceilf for single-precision floats.
  4447. *
  4448. * \param x floating point value.
  4449. * \returns the ceiling of `x`.
  4450. *
  4451. * \threadsafety It is safe to call this function from any thread.
  4452. *
  4453. * \since This function is available since SDL 3.1.3.
  4454. *
  4455. * \sa SDL_ceilf
  4456. * \sa SDL_floor
  4457. * \sa SDL_trunc
  4458. * \sa SDL_round
  4459. * \sa SDL_lround
  4460. */
  4461. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  4462. /**
  4463. * Compute the ceiling of `x`.
  4464. *
  4465. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  4466. * rounded up to the nearest integer.
  4467. *
  4468. * Domain: `-INF <= x <= INF`
  4469. *
  4470. * Range: `-INF <= y <= INF`, y integer
  4471. *
  4472. * This function operates on single-precision floating point values, use
  4473. * SDL_ceil for double-precision floats.
  4474. *
  4475. * \param x floating point value.
  4476. * \returns the ceiling of `x`.
  4477. *
  4478. * \threadsafety It is safe to call this function from any thread.
  4479. *
  4480. * \since This function is available since SDL 3.1.3.
  4481. *
  4482. * \sa SDL_ceil
  4483. * \sa SDL_floorf
  4484. * \sa SDL_truncf
  4485. * \sa SDL_roundf
  4486. * \sa SDL_lroundf
  4487. */
  4488. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  4489. /**
  4490. * Copy the sign of one floating-point value to another.
  4491. *
  4492. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  4493. *
  4494. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  4495. *
  4496. * Range: `-INF <= z <= INF`
  4497. *
  4498. * This function operates on double-precision floating point values, use
  4499. * SDL_copysignf for single-precision floats.
  4500. *
  4501. * \param x floating point value to use as the magnitude.
  4502. * \param y floating point value to use as the sign.
  4503. * \returns the floating point value with the sign of y and the magnitude of
  4504. * x.
  4505. *
  4506. * \threadsafety It is safe to call this function from any thread.
  4507. *
  4508. * \since This function is available since SDL 3.1.3.
  4509. *
  4510. * \sa SDL_copysignf
  4511. * \sa SDL_fabs
  4512. */
  4513. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  4514. /**
  4515. * Copy the sign of one floating-point value to another.
  4516. *
  4517. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  4518. *
  4519. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  4520. *
  4521. * Range: `-INF <= z <= INF`
  4522. *
  4523. * This function operates on single-precision floating point values, use
  4524. * SDL_copysign for double-precision floats.
  4525. *
  4526. * \param x floating point value to use as the magnitude.
  4527. * \param y floating point value to use as the sign.
  4528. * \returns the floating point value with the sign of y and the magnitude of
  4529. * x.
  4530. *
  4531. * \threadsafety It is safe to call this function from any thread.
  4532. *
  4533. * \since This function is available since SDL 3.1.3.
  4534. *
  4535. * \sa SDL_copysignf
  4536. * \sa SDL_fabsf
  4537. */
  4538. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  4539. /**
  4540. * Compute the cosine of `x`.
  4541. *
  4542. * Domain: `-INF <= x <= INF`
  4543. *
  4544. * Range: `-1 <= y <= 1`
  4545. *
  4546. * This function operates on double-precision floating point values, use
  4547. * SDL_cosf for single-precision floats.
  4548. *
  4549. * This function may use a different approximation across different versions,
  4550. * platforms and configurations. i.e, it can return a different value given
  4551. * the same input on different machines or operating systems, or if SDL is
  4552. * updated.
  4553. *
  4554. * \param x floating point value, in radians.
  4555. * \returns cosine of `x`.
  4556. *
  4557. * \threadsafety It is safe to call this function from any thread.
  4558. *
  4559. * \since This function is available since SDL 3.1.3.
  4560. *
  4561. * \sa SDL_cosf
  4562. * \sa SDL_acos
  4563. * \sa SDL_sin
  4564. */
  4565. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  4566. /**
  4567. * Compute the cosine of `x`.
  4568. *
  4569. * Domain: `-INF <= x <= INF`
  4570. *
  4571. * Range: `-1 <= y <= 1`
  4572. *
  4573. * This function operates on single-precision floating point values, use
  4574. * SDL_cos for double-precision floats.
  4575. *
  4576. * This function may use a different approximation across different versions,
  4577. * platforms and configurations. i.e, it can return a different value given
  4578. * the same input on different machines or operating systems, or if SDL is
  4579. * updated.
  4580. *
  4581. * \param x floating point value, in radians.
  4582. * \returns cosine of `x`.
  4583. *
  4584. * \threadsafety It is safe to call this function from any thread.
  4585. *
  4586. * \since This function is available since SDL 3.1.3.
  4587. *
  4588. * \sa SDL_cos
  4589. * \sa SDL_acosf
  4590. * \sa SDL_sinf
  4591. */
  4592. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  4593. /**
  4594. * Compute the exponential of `x`.
  4595. *
  4596. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  4597. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  4598. *
  4599. * Domain: `-INF <= x <= INF`
  4600. *
  4601. * Range: `0 <= y <= INF`
  4602. *
  4603. * The output will overflow if `exp(x)` is too large to be represented.
  4604. *
  4605. * This function operates on double-precision floating point values, use
  4606. * SDL_expf for single-precision floats.
  4607. *
  4608. * This function may use a different approximation across different versions,
  4609. * platforms and configurations. i.e, it can return a different value given
  4610. * the same input on different machines or operating systems, or if SDL is
  4611. * updated.
  4612. *
  4613. * \param x floating point value.
  4614. * \returns value of `e^x`.
  4615. *
  4616. * \threadsafety It is safe to call this function from any thread.
  4617. *
  4618. * \since This function is available since SDL 3.1.3.
  4619. *
  4620. * \sa SDL_expf
  4621. * \sa SDL_log
  4622. */
  4623. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  4624. /**
  4625. * Compute the exponential of `x`.
  4626. *
  4627. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  4628. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  4629. *
  4630. * Domain: `-INF <= x <= INF`
  4631. *
  4632. * Range: `0 <= y <= INF`
  4633. *
  4634. * The output will overflow if `exp(x)` is too large to be represented.
  4635. *
  4636. * This function operates on single-precision floating point values, use
  4637. * SDL_exp for double-precision floats.
  4638. *
  4639. * This function may use a different approximation across different versions,
  4640. * platforms and configurations. i.e, it can return a different value given
  4641. * the same input on different machines or operating systems, or if SDL is
  4642. * updated.
  4643. *
  4644. * \param x floating point value.
  4645. * \returns value of `e^x`.
  4646. *
  4647. * \threadsafety It is safe to call this function from any thread.
  4648. *
  4649. * \since This function is available since SDL 3.1.3.
  4650. *
  4651. * \sa SDL_exp
  4652. * \sa SDL_logf
  4653. */
  4654. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  4655. /**
  4656. * Compute the absolute value of `x`
  4657. *
  4658. * Domain: `-INF <= x <= INF`
  4659. *
  4660. * Range: `0 <= y <= INF`
  4661. *
  4662. * This function operates on double-precision floating point values, use
  4663. * SDL_copysignf for single-precision floats.
  4664. *
  4665. * \param x floating point value to use as the magnitude.
  4666. * \returns the absolute value of `x`.
  4667. *
  4668. * \threadsafety It is safe to call this function from any thread.
  4669. *
  4670. * \since This function is available since SDL 3.1.3.
  4671. *
  4672. * \sa SDL_fabsf
  4673. */
  4674. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  4675. /**
  4676. * Compute the absolute value of `x`
  4677. *
  4678. * Domain: `-INF <= x <= INF`
  4679. *
  4680. * Range: `0 <= y <= INF`
  4681. *
  4682. * This function operates on single-precision floating point values, use
  4683. * SDL_copysignf for double-precision floats.
  4684. *
  4685. * \param x floating point value to use as the magnitude.
  4686. * \returns the absolute value of `x`.
  4687. *
  4688. * \threadsafety It is safe to call this function from any thread.
  4689. *
  4690. * \since This function is available since SDL 3.1.3.
  4691. *
  4692. * \sa SDL_fabs
  4693. */
  4694. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  4695. /**
  4696. * Compute the floor of `x`.
  4697. *
  4698. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  4699. * rounded down to the nearest integer.
  4700. *
  4701. * Domain: `-INF <= x <= INF`
  4702. *
  4703. * Range: `-INF <= y <= INF`, y integer
  4704. *
  4705. * This function operates on double-precision floating point values, use
  4706. * SDL_floorf for single-precision floats.
  4707. *
  4708. * \param x floating point value.
  4709. * \returns the floor of `x`.
  4710. *
  4711. * \threadsafety It is safe to call this function from any thread.
  4712. *
  4713. * \since This function is available since SDL 3.1.3.
  4714. *
  4715. * \sa SDL_floorf
  4716. * \sa SDL_ceil
  4717. * \sa SDL_trunc
  4718. * \sa SDL_round
  4719. * \sa SDL_lround
  4720. */
  4721. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  4722. /**
  4723. * Compute the floor of `x`.
  4724. *
  4725. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  4726. * rounded down to the nearest integer.
  4727. *
  4728. * Domain: `-INF <= x <= INF`
  4729. *
  4730. * Range: `-INF <= y <= INF`, y integer
  4731. *
  4732. * This function operates on single-precision floating point values, use
  4733. * SDL_floorf for double-precision floats.
  4734. *
  4735. * \param x floating point value.
  4736. * \returns the floor of `x`.
  4737. *
  4738. * \threadsafety It is safe to call this function from any thread.
  4739. *
  4740. * \since This function is available since SDL 3.1.3.
  4741. *
  4742. * \sa SDL_floor
  4743. * \sa SDL_ceilf
  4744. * \sa SDL_truncf
  4745. * \sa SDL_roundf
  4746. * \sa SDL_lroundf
  4747. */
  4748. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  4749. /**
  4750. * Truncate `x` to an integer.
  4751. *
  4752. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  4753. * the fractional part of `x`, leaving only the integer part.
  4754. *
  4755. * Domain: `-INF <= x <= INF`
  4756. *
  4757. * Range: `-INF <= y <= INF`, y integer
  4758. *
  4759. * This function operates on double-precision floating point values, use
  4760. * SDL_truncf for single-precision floats.
  4761. *
  4762. * \param x floating point value.
  4763. * \returns `x` truncated to an integer.
  4764. *
  4765. * \threadsafety It is safe to call this function from any thread.
  4766. *
  4767. * \since This function is available since SDL 3.1.3.
  4768. *
  4769. * \sa SDL_truncf
  4770. * \sa SDL_fmod
  4771. * \sa SDL_ceil
  4772. * \sa SDL_floor
  4773. * \sa SDL_round
  4774. * \sa SDL_lround
  4775. */
  4776. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  4777. /**
  4778. * Truncate `x` to an integer.
  4779. *
  4780. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  4781. * the fractional part of `x`, leaving only the integer part.
  4782. *
  4783. * Domain: `-INF <= x <= INF`
  4784. *
  4785. * Range: `-INF <= y <= INF`, y integer
  4786. *
  4787. * This function operates on single-precision floating point values, use
  4788. * SDL_truncf for double-precision floats.
  4789. *
  4790. * \param x floating point value.
  4791. * \returns `x` truncated to an integer.
  4792. *
  4793. * \threadsafety It is safe to call this function from any thread.
  4794. *
  4795. * \since This function is available since SDL 3.1.3.
  4796. *
  4797. * \sa SDL_trunc
  4798. * \sa SDL_fmodf
  4799. * \sa SDL_ceilf
  4800. * \sa SDL_floorf
  4801. * \sa SDL_roundf
  4802. * \sa SDL_lroundf
  4803. */
  4804. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  4805. /**
  4806. * Return the floating-point remainder of `x / y`
  4807. *
  4808. * Divides `x` by `y`, and returns the remainder.
  4809. *
  4810. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  4811. *
  4812. * Range: `-y <= z <= y`
  4813. *
  4814. * This function operates on double-precision floating point values, use
  4815. * SDL_fmodf for single-precision floats.
  4816. *
  4817. * \param x the numerator.
  4818. * \param y the denominator. Must not be 0.
  4819. * \returns the remainder of `x / y`.
  4820. *
  4821. * \threadsafety It is safe to call this function from any thread.
  4822. *
  4823. * \since This function is available since SDL 3.1.3.
  4824. *
  4825. * \sa SDL_fmodf
  4826. * \sa SDL_modf
  4827. * \sa SDL_trunc
  4828. * \sa SDL_ceil
  4829. * \sa SDL_floor
  4830. * \sa SDL_round
  4831. * \sa SDL_lround
  4832. */
  4833. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  4834. /**
  4835. * Return the floating-point remainder of `x / y`
  4836. *
  4837. * Divides `x` by `y`, and returns the remainder.
  4838. *
  4839. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  4840. *
  4841. * Range: `-y <= z <= y`
  4842. *
  4843. * This function operates on single-precision floating point values, use
  4844. * SDL_fmod for single-precision floats.
  4845. *
  4846. * \param x the numerator.
  4847. * \param y the denominator. Must not be 0.
  4848. * \returns the remainder of `x / y`.
  4849. *
  4850. * \threadsafety It is safe to call this function from any thread.
  4851. *
  4852. * \since This function is available since SDL 3.1.3.
  4853. *
  4854. * \sa SDL_fmod
  4855. * \sa SDL_truncf
  4856. * \sa SDL_modff
  4857. * \sa SDL_ceilf
  4858. * \sa SDL_floorf
  4859. * \sa SDL_roundf
  4860. * \sa SDL_lroundf
  4861. */
  4862. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  4863. /**
  4864. * Return whether the value is infinity.
  4865. *
  4866. * \param x double-precision floating point value.
  4867. * \returns non-zero if the value is infinity, 0 otherwise.
  4868. *
  4869. * \threadsafety It is safe to call this function from any thread.
  4870. *
  4871. * \since This function is available since SDL 3.1.3.
  4872. *
  4873. * \sa SDL_isinff
  4874. */
  4875. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  4876. /**
  4877. * Return whether the value is infinity.
  4878. *
  4879. * \param x floating point value.
  4880. * \returns non-zero if the value is infinity, 0 otherwise.
  4881. *
  4882. * \threadsafety It is safe to call this function from any thread.
  4883. *
  4884. * \since This function is available since SDL 3.1.3.
  4885. *
  4886. * \sa SDL_isinf
  4887. */
  4888. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  4889. /**
  4890. * Return whether the value is NaN.
  4891. *
  4892. * \param x double-precision floating point value.
  4893. * \returns non-zero if the value is NaN, 0 otherwise.
  4894. *
  4895. * \threadsafety It is safe to call this function from any thread.
  4896. *
  4897. * \since This function is available since SDL 3.1.3.
  4898. *
  4899. * \sa SDL_isnanf
  4900. */
  4901. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  4902. /**
  4903. * Return whether the value is NaN.
  4904. *
  4905. * \param x floating point value.
  4906. * \returns non-zero if the value is NaN, 0 otherwise.
  4907. *
  4908. * \threadsafety It is safe to call this function from any thread.
  4909. *
  4910. * \since This function is available since SDL 3.1.3.
  4911. *
  4912. * \sa SDL_isnan
  4913. */
  4914. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  4915. /**
  4916. * Compute the natural logarithm of `x`.
  4917. *
  4918. * Domain: `0 < x <= INF`
  4919. *
  4920. * Range: `-INF <= y <= INF`
  4921. *
  4922. * It is an error for `x` to be less than or equal to 0.
  4923. *
  4924. * This function operates on double-precision floating point values, use
  4925. * SDL_logf for single-precision floats.
  4926. *
  4927. * This function may use a different approximation across different versions,
  4928. * platforms and configurations. i.e, it can return a different value given
  4929. * the same input on different machines or operating systems, or if SDL is
  4930. * updated.
  4931. *
  4932. * \param x floating point value. Must be greater than 0.
  4933. * \returns the natural logarithm of `x`.
  4934. *
  4935. * \threadsafety It is safe to call this function from any thread.
  4936. *
  4937. * \since This function is available since SDL 3.1.3.
  4938. *
  4939. * \sa SDL_logf
  4940. * \sa SDL_log10
  4941. * \sa SDL_exp
  4942. */
  4943. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  4944. /**
  4945. * Compute the natural logarithm of `x`.
  4946. *
  4947. * Domain: `0 < x <= INF`
  4948. *
  4949. * Range: `-INF <= y <= INF`
  4950. *
  4951. * It is an error for `x` to be less than or equal to 0.
  4952. *
  4953. * This function operates on single-precision floating point values, use
  4954. * SDL_log for double-precision floats.
  4955. *
  4956. * This function may use a different approximation across different versions,
  4957. * platforms and configurations. i.e, it can return a different value given
  4958. * the same input on different machines or operating systems, or if SDL is
  4959. * updated.
  4960. *
  4961. * \param x floating point value. Must be greater than 0.
  4962. * \returns the natural logarithm of `x`.
  4963. *
  4964. * \threadsafety It is safe to call this function from any thread.
  4965. *
  4966. * \since This function is available since SDL 3.1.3.
  4967. *
  4968. * \sa SDL_log
  4969. * \sa SDL_expf
  4970. */
  4971. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  4972. /**
  4973. * Compute the base-10 logarithm of `x`.
  4974. *
  4975. * Domain: `0 < x <= INF`
  4976. *
  4977. * Range: `-INF <= y <= INF`
  4978. *
  4979. * It is an error for `x` to be less than or equal to 0.
  4980. *
  4981. * This function operates on double-precision floating point values, use
  4982. * SDL_log10f for single-precision floats.
  4983. *
  4984. * This function may use a different approximation across different versions,
  4985. * platforms and configurations. i.e, it can return a different value given
  4986. * the same input on different machines or operating systems, or if SDL is
  4987. * updated.
  4988. *
  4989. * \param x floating point value. Must be greater than 0.
  4990. * \returns the logarithm of `x`.
  4991. *
  4992. * \threadsafety It is safe to call this function from any thread.
  4993. *
  4994. * \since This function is available since SDL 3.1.3.
  4995. *
  4996. * \sa SDL_log10f
  4997. * \sa SDL_log
  4998. * \sa SDL_pow
  4999. */
  5000. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  5001. /**
  5002. * Compute the base-10 logarithm of `x`.
  5003. *
  5004. * Domain: `0 < x <= INF`
  5005. *
  5006. * Range: `-INF <= y <= INF`
  5007. *
  5008. * It is an error for `x` to be less than or equal to 0.
  5009. *
  5010. * This function operates on single-precision floating point values, use
  5011. * SDL_log10 for double-precision floats.
  5012. *
  5013. * This function may use a different approximation across different versions,
  5014. * platforms and configurations. i.e, it can return a different value given
  5015. * the same input on different machines or operating systems, or if SDL is
  5016. * updated.
  5017. *
  5018. * \param x floating point value. Must be greater than 0.
  5019. * \returns the logarithm of `x`.
  5020. *
  5021. * \threadsafety It is safe to call this function from any thread.
  5022. *
  5023. * \since This function is available since SDL 3.1.3.
  5024. *
  5025. * \sa SDL_log10
  5026. * \sa SDL_logf
  5027. * \sa SDL_powf
  5028. */
  5029. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  5030. /**
  5031. * Split `x` into integer and fractional parts
  5032. *
  5033. * This function operates on double-precision floating point values, use
  5034. * SDL_modff for single-precision floats.
  5035. *
  5036. * \param x floating point value.
  5037. * \param y output pointer to store the integer part of `x`.
  5038. * \returns the fractional part of `x`.
  5039. *
  5040. * \threadsafety It is safe to call this function from any thread.
  5041. *
  5042. * \since This function is available since SDL 3.1.3.
  5043. *
  5044. * \sa SDL_modff
  5045. * \sa SDL_trunc
  5046. * \sa SDL_fmod
  5047. */
  5048. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  5049. /**
  5050. * Split `x` into integer and fractional parts
  5051. *
  5052. * This function operates on single-precision floating point values, use
  5053. * SDL_modf for double-precision floats.
  5054. *
  5055. * \param x floating point value.
  5056. * \param y output pointer to store the integer part of `x`.
  5057. * \returns the fractional part of `x`.
  5058. *
  5059. * \threadsafety It is safe to call this function from any thread.
  5060. *
  5061. * \since This function is available since SDL 3.1.3.
  5062. *
  5063. * \sa SDL_modf
  5064. * \sa SDL_truncf
  5065. * \sa SDL_fmodf
  5066. */
  5067. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  5068. /**
  5069. * Raise `x` to the power `y`
  5070. *
  5071. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  5072. *
  5073. * Range: `-INF <= z <= INF`
  5074. *
  5075. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  5076. * instead.
  5077. *
  5078. * This function operates on double-precision floating point values, use
  5079. * SDL_powf for single-precision floats.
  5080. *
  5081. * This function may use a different approximation across different versions,
  5082. * platforms and configurations. i.e, it can return a different value given
  5083. * the same input on different machines or operating systems, or if SDL is
  5084. * updated.
  5085. *
  5086. * \param x the base.
  5087. * \param y the exponent.
  5088. * \returns `x` raised to the power `y`.
  5089. *
  5090. * \threadsafety It is safe to call this function from any thread.
  5091. *
  5092. * \since This function is available since SDL 3.1.3.
  5093. *
  5094. * \sa SDL_powf
  5095. * \sa SDL_exp
  5096. * \sa SDL_log
  5097. */
  5098. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  5099. /**
  5100. * Raise `x` to the power `y`
  5101. *
  5102. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  5103. *
  5104. * Range: `-INF <= z <= INF`
  5105. *
  5106. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  5107. * instead.
  5108. *
  5109. * This function operates on single-precision floating point values, use
  5110. * SDL_powf for double-precision floats.
  5111. *
  5112. * This function may use a different approximation across different versions,
  5113. * platforms and configurations. i.e, it can return a different value given
  5114. * the same input on different machines or operating systems, or if SDL is
  5115. * updated.
  5116. *
  5117. * \param x the base.
  5118. * \param y the exponent.
  5119. * \returns `x` raised to the power `y`.
  5120. *
  5121. * \threadsafety It is safe to call this function from any thread.
  5122. *
  5123. * \since This function is available since SDL 3.1.3.
  5124. *
  5125. * \sa SDL_pow
  5126. * \sa SDL_expf
  5127. * \sa SDL_logf
  5128. */
  5129. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  5130. /**
  5131. * Round `x` to the nearest integer.
  5132. *
  5133. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5134. * rounded away from zero.
  5135. *
  5136. * Domain: `-INF <= x <= INF`
  5137. *
  5138. * Range: `-INF <= y <= INF`, y integer
  5139. *
  5140. * This function operates on double-precision floating point values, use
  5141. * SDL_roundf for single-precision floats. To get the result as an integer
  5142. * type, use SDL_lround.
  5143. *
  5144. * \param x floating point value.
  5145. * \returns the nearest integer to `x`.
  5146. *
  5147. * \threadsafety It is safe to call this function from any thread.
  5148. *
  5149. * \since This function is available since SDL 3.1.3.
  5150. *
  5151. * \sa SDL_roundf
  5152. * \sa SDL_lround
  5153. * \sa SDL_floor
  5154. * \sa SDL_ceil
  5155. * \sa SDL_trunc
  5156. */
  5157. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  5158. /**
  5159. * Round `x` to the nearest integer.
  5160. *
  5161. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5162. * rounded away from zero.
  5163. *
  5164. * Domain: `-INF <= x <= INF`
  5165. *
  5166. * Range: `-INF <= y <= INF`, y integer
  5167. *
  5168. * This function operates on double-precision floating point values, use
  5169. * SDL_roundf for single-precision floats. To get the result as an integer
  5170. * type, use SDL_lroundf.
  5171. *
  5172. * \param x floating point value.
  5173. * \returns the nearest integer to `x`.
  5174. *
  5175. * \threadsafety It is safe to call this function from any thread.
  5176. *
  5177. * \since This function is available since SDL 3.1.3.
  5178. *
  5179. * \sa SDL_round
  5180. * \sa SDL_lroundf
  5181. * \sa SDL_floorf
  5182. * \sa SDL_ceilf
  5183. * \sa SDL_truncf
  5184. */
  5185. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  5186. /**
  5187. * Round `x` to the nearest integer representable as a long
  5188. *
  5189. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5190. * rounded away from zero.
  5191. *
  5192. * Domain: `-INF <= x <= INF`
  5193. *
  5194. * Range: `MIN_LONG <= y <= MAX_LONG`
  5195. *
  5196. * This function operates on double-precision floating point values, use
  5197. * SDL_lround for single-precision floats. To get the result as a
  5198. * floating-point type, use SDL_round.
  5199. *
  5200. * \param x floating point value.
  5201. * \returns the nearest integer to `x`.
  5202. *
  5203. * \threadsafety It is safe to call this function from any thread.
  5204. *
  5205. * \since This function is available since SDL 3.1.3.
  5206. *
  5207. * \sa SDL_lroundf
  5208. * \sa SDL_round
  5209. * \sa SDL_floor
  5210. * \sa SDL_ceil
  5211. * \sa SDL_trunc
  5212. */
  5213. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  5214. /**
  5215. * Round `x` to the nearest integer representable as a long
  5216. *
  5217. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5218. * rounded away from zero.
  5219. *
  5220. * Domain: `-INF <= x <= INF`
  5221. *
  5222. * Range: `MIN_LONG <= y <= MAX_LONG`
  5223. *
  5224. * This function operates on single-precision floating point values, use
  5225. * SDL_lroundf for double-precision floats. To get the result as a
  5226. * floating-point type, use SDL_roundf,
  5227. *
  5228. * \param x floating point value.
  5229. * \returns the nearest integer to `x`.
  5230. *
  5231. * \threadsafety It is safe to call this function from any thread.
  5232. *
  5233. * \since This function is available since SDL 3.1.3.
  5234. *
  5235. * \sa SDL_lround
  5236. * \sa SDL_roundf
  5237. * \sa SDL_floorf
  5238. * \sa SDL_ceilf
  5239. * \sa SDL_truncf
  5240. */
  5241. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  5242. /**
  5243. * Scale `x` by an integer power of two.
  5244. *
  5245. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  5246. *
  5247. * Domain: `-INF <= x <= INF`, `n` integer
  5248. *
  5249. * Range: `-INF <= y <= INF`
  5250. *
  5251. * This function operates on double-precision floating point values, use
  5252. * SDL_scalbnf for single-precision floats.
  5253. *
  5254. * \param x floating point value to be scaled.
  5255. * \param n integer exponent.
  5256. * \returns `x * 2^n`.
  5257. *
  5258. * \threadsafety It is safe to call this function from any thread.
  5259. *
  5260. * \since This function is available since SDL 3.1.3.
  5261. *
  5262. * \sa SDL_scalbnf
  5263. * \sa SDL_pow
  5264. */
  5265. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  5266. /**
  5267. * Scale `x` by an integer power of two.
  5268. *
  5269. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  5270. *
  5271. * Domain: `-INF <= x <= INF`, `n` integer
  5272. *
  5273. * Range: `-INF <= y <= INF`
  5274. *
  5275. * This function operates on single-precision floating point values, use
  5276. * SDL_scalbn for double-precision floats.
  5277. *
  5278. * \param x floating point value to be scaled.
  5279. * \param n integer exponent.
  5280. * \returns `x * 2^n`.
  5281. *
  5282. * \threadsafety It is safe to call this function from any thread.
  5283. *
  5284. * \since This function is available since SDL 3.1.3.
  5285. *
  5286. * \sa SDL_scalbn
  5287. * \sa SDL_powf
  5288. */
  5289. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  5290. /**
  5291. * Compute the sine of `x`.
  5292. *
  5293. * Domain: `-INF <= x <= INF`
  5294. *
  5295. * Range: `-1 <= y <= 1`
  5296. *
  5297. * This function operates on double-precision floating point values, use
  5298. * SDL_sinf for single-precision floats.
  5299. *
  5300. * This function may use a different approximation across different versions,
  5301. * platforms and configurations. i.e, it can return a different value given
  5302. * the same input on different machines or operating systems, or if SDL is
  5303. * updated.
  5304. *
  5305. * \param x floating point value, in radians.
  5306. * \returns sine of `x`.
  5307. *
  5308. * \threadsafety It is safe to call this function from any thread.
  5309. *
  5310. * \since This function is available since SDL 3.1.3.
  5311. *
  5312. * \sa SDL_sinf
  5313. * \sa SDL_asin
  5314. * \sa SDL_cos
  5315. */
  5316. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  5317. /**
  5318. * Compute the sine of `x`.
  5319. *
  5320. * Domain: `-INF <= x <= INF`
  5321. *
  5322. * Range: `-1 <= y <= 1`
  5323. *
  5324. * This function operates on single-precision floating point values, use
  5325. * SDL_sin for double-precision floats.
  5326. *
  5327. * This function may use a different approximation across different versions,
  5328. * platforms and configurations. i.e, it can return a different value given
  5329. * the same input on different machines or operating systems, or if SDL is
  5330. * updated.
  5331. *
  5332. * \param x floating point value, in radians.
  5333. * \returns sine of `x`.
  5334. *
  5335. * \threadsafety It is safe to call this function from any thread.
  5336. *
  5337. * \since This function is available since SDL 3.1.3.
  5338. *
  5339. * \sa SDL_sin
  5340. * \sa SDL_asinf
  5341. * \sa SDL_cosf
  5342. */
  5343. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  5344. /**
  5345. * Compute the square root of `x`.
  5346. *
  5347. * Domain: `0 <= x <= INF`
  5348. *
  5349. * Range: `0 <= y <= INF`
  5350. *
  5351. * This function operates on double-precision floating point values, use
  5352. * SDL_sqrtf for single-precision floats.
  5353. *
  5354. * This function may use a different approximation across different versions,
  5355. * platforms and configurations. i.e, it can return a different value given
  5356. * the same input on different machines or operating systems, or if SDL is
  5357. * updated.
  5358. *
  5359. * \param x floating point value. Must be greater than or equal to 0.
  5360. * \returns square root of `x`.
  5361. *
  5362. * \threadsafety It is safe to call this function from any thread.
  5363. *
  5364. * \since This function is available since SDL 3.1.3.
  5365. *
  5366. * \sa SDL_sqrtf
  5367. */
  5368. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  5369. /**
  5370. * Compute the square root of `x`.
  5371. *
  5372. * Domain: `0 <= x <= INF`
  5373. *
  5374. * Range: `0 <= y <= INF`
  5375. *
  5376. * This function operates on single-precision floating point values, use
  5377. * SDL_sqrt for double-precision floats.
  5378. *
  5379. * This function may use a different approximation across different versions,
  5380. * platforms and configurations. i.e, it can return a different value given
  5381. * the same input on different machines or operating systems, or if SDL is
  5382. * updated.
  5383. *
  5384. * \param x floating point value. Must be greater than or equal to 0.
  5385. * \returns square root of `x`.
  5386. *
  5387. * \threadsafety It is safe to call this function from any thread.
  5388. *
  5389. * \since This function is available since SDL 3.1.3.
  5390. *
  5391. * \sa SDL_sqrt
  5392. */
  5393. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  5394. /**
  5395. * Compute the tangent of `x`.
  5396. *
  5397. * Domain: `-INF <= x <= INF`
  5398. *
  5399. * Range: `-INF <= y <= INF`
  5400. *
  5401. * This function operates on double-precision floating point values, use
  5402. * SDL_tanf for single-precision floats.
  5403. *
  5404. * This function may use a different approximation across different versions,
  5405. * platforms and configurations. i.e, it can return a different value given
  5406. * the same input on different machines or operating systems, or if SDL is
  5407. * updated.
  5408. *
  5409. * \param x floating point value, in radians.
  5410. * \returns tangent of `x`.
  5411. *
  5412. * \threadsafety It is safe to call this function from any thread.
  5413. *
  5414. * \since This function is available since SDL 3.1.3.
  5415. *
  5416. * \sa SDL_tanf
  5417. * \sa SDL_sin
  5418. * \sa SDL_cos
  5419. * \sa SDL_atan
  5420. * \sa SDL_atan2
  5421. */
  5422. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  5423. /**
  5424. * Compute the tangent of `x`.
  5425. *
  5426. * Domain: `-INF <= x <= INF`
  5427. *
  5428. * Range: `-INF <= y <= INF`
  5429. *
  5430. * This function operates on single-precision floating point values, use
  5431. * SDL_tanf for double-precision floats.
  5432. *
  5433. * This function may use a different approximation across different versions,
  5434. * platforms and configurations. i.e, it can return a different value given
  5435. * the same input on different machines or operating systems, or if SDL is
  5436. * updated.
  5437. *
  5438. * \param x floating point value, in radians.
  5439. * \returns tangent of `x`.
  5440. *
  5441. * \threadsafety It is safe to call this function from any thread.
  5442. *
  5443. * \since This function is available since SDL 3.1.3.
  5444. *
  5445. * \sa SDL_tan
  5446. * \sa SDL_sinf
  5447. * \sa SDL_cosf
  5448. * \sa SDL_atanf
  5449. * \sa SDL_atan2f
  5450. */
  5451. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  5452. /**
  5453. * An opaque handle representing string encoding conversion state.
  5454. *
  5455. * \since This datatype is available since SDL 3.1.3.
  5456. *
  5457. * \sa SDL_iconv_open
  5458. */
  5459. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  5460. /**
  5461. * This function allocates a context for the specified character set
  5462. * conversion.
  5463. *
  5464. * \param tocode The target character encoding, must not be NULL.
  5465. * \param fromcode The source character encoding, must not be NULL.
  5466. * \returns a handle that must be freed with SDL_iconv_close, or
  5467. * SDL_ICONV_ERROR on failure.
  5468. *
  5469. * \since This function is available since SDL 3.1.3.
  5470. *
  5471. * \sa SDL_iconv
  5472. * \sa SDL_iconv_close
  5473. * \sa SDL_iconv_string
  5474. */
  5475. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  5476. const char *fromcode);
  5477. /**
  5478. * This function frees a context used for character set conversion.
  5479. *
  5480. * \param cd The character set conversion handle.
  5481. * \returns 0 on success, or -1 on failure.
  5482. *
  5483. * \since This function is available since SDL 3.1.3.
  5484. *
  5485. * \sa SDL_iconv
  5486. * \sa SDL_iconv_open
  5487. * \sa SDL_iconv_string
  5488. */
  5489. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  5490. /**
  5491. * This function converts text between encodings, reading from and writing to
  5492. * a buffer.
  5493. *
  5494. * It returns the number of succesful conversions on success. On error,
  5495. * SDL_ICONV_E2BIG is returned when the output buffer is too small, or
  5496. * SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
  5497. * or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  5498. * encountered.
  5499. *
  5500. * On exit:
  5501. *
  5502. * - inbuf will point to the beginning of the next multibyte sequence. On
  5503. * error, this is the location of the problematic input sequence. On
  5504. * success, this is the end of the input sequence.
  5505. * - inbytesleft will be set to the number of bytes left to convert, which
  5506. * will be 0 on success.
  5507. * - outbuf will point to the location where to store the next output byte.
  5508. * - outbytesleft will be set to the number of bytes left in the output
  5509. * buffer.
  5510. *
  5511. * \param cd The character set conversion context, created in
  5512. * SDL_iconv_open().
  5513. * \param inbuf Address of variable that points to the first character of the
  5514. * input sequence.
  5515. * \param inbytesleft The number of bytes in the input buffer.
  5516. * \param outbuf Address of variable that points to the output buffer.
  5517. * \param outbytesleft The number of bytes in the output buffer.
  5518. * \returns the number of conversions on success, or a negative error code.
  5519. *
  5520. * \since This function is available since SDL 3.1.3.
  5521. *
  5522. * \sa SDL_iconv_open
  5523. * \sa SDL_iconv_close
  5524. * \sa SDL_iconv_string
  5525. */
  5526. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  5527. size_t *inbytesleft, char **outbuf,
  5528. size_t *outbytesleft);
  5529. #define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
  5530. #define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
  5531. #define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
  5532. #define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
  5533. /**
  5534. * Helper function to convert a string's encoding in one call.
  5535. *
  5536. * This function converts a buffer or string between encodings in one pass.
  5537. *
  5538. * The string does not need to be NULL-terminated; this function operates on
  5539. * the number of bytes specified in `inbytesleft` whether there is a NULL
  5540. * character anywhere in the buffer.
  5541. *
  5542. * The returned string is owned by the caller, and should be passed to
  5543. * SDL_free when no longer needed.
  5544. *
  5545. * \param tocode the character encoding of the output string. Examples are
  5546. * "UTF-8", "UCS-4", etc.
  5547. * \param fromcode the character encoding of data in `inbuf`.
  5548. * \param inbuf the string to convert to a different encoding.
  5549. * \param inbytesleft the size of the input string _in bytes_.
  5550. * \returns a new string, converted to the new encoding, or NULL on error.
  5551. *
  5552. * \since This function is available since SDL 3.1.3.
  5553. *
  5554. * \sa SDL_iconv_open
  5555. * \sa SDL_iconv_close
  5556. * \sa SDL_iconv
  5557. */
  5558. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  5559. const char *fromcode,
  5560. const char *inbuf,
  5561. size_t inbytesleft);
  5562. /* Some helper macros for common SDL_iconv_string cases... */
  5563. /**
  5564. * Convert a UTF-8 string to the current locale's character encoding.
  5565. *
  5566. * This is a helper macro that might be more clear than calling
  5567. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5568. * do not use an expression with side-effects here.
  5569. *
  5570. * \param S the string to convert.
  5571. * \returns a new string, converted to the new encoding, or NULL on error.
  5572. *
  5573. * \since This macro is available since SDL 3.1.3.
  5574. */
  5575. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  5576. /**
  5577. * Convert a UTF-8 string to UCS-2.
  5578. *
  5579. * This is a helper macro that might be more clear than calling
  5580. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5581. * do not use an expression with side-effects here.
  5582. *
  5583. * \param S the string to convert.
  5584. * \returns a new string, converted to the new encoding, or NULL on error.
  5585. *
  5586. * \since This macro is available since SDL 3.1.3.
  5587. */
  5588. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  5589. /**
  5590. * Convert a UTF-8 string to UCS-4.
  5591. *
  5592. * This is a helper macro that might be more clear than calling
  5593. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5594. * do not use an expression with side-effects here.
  5595. *
  5596. * \param S the string to convert.
  5597. * \returns a new string, converted to the new encoding, or NULL on error.
  5598. *
  5599. * \since This macro is available since SDL 3.1.3.
  5600. */
  5601. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  5602. /**
  5603. * Convert a wchar_t string to UTF-8.
  5604. *
  5605. * This is a helper macro that might be more clear than calling
  5606. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5607. * do not use an expression with side-effects here.
  5608. *
  5609. * \param S the string to convert.
  5610. * \returns a new string, converted to the new encoding, or NULL on error.
  5611. *
  5612. * \since This macro is available since SDL 3.1.3.
  5613. */
  5614. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  5615. /* force builds using Clang's static analysis tools to use literal C runtime
  5616. here, since there are possibly tests that are ineffective otherwise. */
  5617. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  5618. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  5619. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  5620. size_t strlcpy(char *dst, const char *src, size_t size);
  5621. #endif
  5622. /* The analyzer knows about strlcat even when the system doesn't provide it */
  5623. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  5624. size_t strlcat(char *dst, const char *src, size_t size);
  5625. #endif
  5626. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  5627. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  5628. #endif
  5629. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  5630. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  5631. #endif
  5632. /* strdup is not ANSI but POSIX, and its prototype might be hidden... */
  5633. char *strdup(const char *str);
  5634. /* Starting LLVM 16, the analyser errors out if these functions do not have
  5635. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  5636. #include <stdio.h>
  5637. #include <stdlib.h>
  5638. #include <strings.h>
  5639. #define SDL_malloc malloc
  5640. #define SDL_calloc calloc
  5641. #define SDL_realloc realloc
  5642. #define SDL_free free
  5643. #ifndef SDL_memcpy
  5644. #define SDL_memcpy memcpy
  5645. #endif
  5646. #ifndef SDL_memmove
  5647. #define SDL_memmove memmove
  5648. #endif
  5649. #ifndef SDL_memset
  5650. #define SDL_memset memset
  5651. #endif
  5652. #define SDL_memcmp memcmp
  5653. #define SDL_strlcpy strlcpy
  5654. #define SDL_strlcat strlcat
  5655. #define SDL_strlen strlen
  5656. #define SDL_wcslen wcslen
  5657. #define SDL_wcslcpy wcslcpy
  5658. #define SDL_wcslcat wcslcat
  5659. #define SDL_strdup strdup
  5660. #define SDL_wcsdup wcsdup
  5661. #define SDL_strchr strchr
  5662. #define SDL_strrchr strrchr
  5663. #define SDL_strstr strstr
  5664. #define SDL_wcsstr wcsstr
  5665. #define SDL_strtok_r strtok_r
  5666. #define SDL_strcmp strcmp
  5667. #define SDL_wcscmp wcscmp
  5668. #define SDL_strncmp strncmp
  5669. #define SDL_wcsncmp wcsncmp
  5670. #define SDL_strcasecmp strcasecmp
  5671. #define SDL_strncasecmp strncasecmp
  5672. #define SDL_strpbrk strpbrk
  5673. #define SDL_sscanf sscanf
  5674. #define SDL_vsscanf vsscanf
  5675. #define SDL_snprintf snprintf
  5676. #define SDL_vsnprintf vsnprintf
  5677. #endif
  5678. /**
  5679. * Multiply two integers, checking for overflow.
  5680. *
  5681. * If `a * b` would overflow, return false.
  5682. *
  5683. * Otherwise store `a * b` via ret and return true.
  5684. *
  5685. * \param a the multiplicand.
  5686. * \param b the multiplier.
  5687. * \param ret on non-overflow output, stores the multiplication result, may
  5688. * not be NULL.
  5689. * \returns false on overflow, true if result is multiplied without overflow.
  5690. *
  5691. * \threadsafety It is safe to call this function from any thread.
  5692. *
  5693. * \since This function is available since SDL 3.1.3.
  5694. */
  5695. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  5696. {
  5697. if (a != 0 && b > SDL_SIZE_MAX / a) {
  5698. return false;
  5699. }
  5700. *ret = a * b;
  5701. return true;
  5702. }
  5703. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  5704. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  5705. /* This needs to be wrapped in an inline rather than being a direct #define,
  5706. * because __builtin_mul_overflow() is type-generic, but we want to be
  5707. * consistent about interpreting a and b as size_t. */
  5708. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  5709. {
  5710. return (__builtin_mul_overflow(a, b, ret) == 0);
  5711. }
  5712. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  5713. #endif
  5714. #endif
  5715. /**
  5716. * Add two integers, checking for overflow.
  5717. *
  5718. * If `a + b` would overflow, return false.
  5719. *
  5720. * Otherwise store `a + b` via ret and return true.
  5721. *
  5722. * \param a the first addend.
  5723. * \param b the second addend.
  5724. * \param ret on non-overflow output, stores the addition result, may not be
  5725. * NULL.
  5726. * \returns false on overflow, true if result is added without overflow.
  5727. *
  5728. * \threadsafety It is safe to call this function from any thread.
  5729. *
  5730. * \since This function is available since SDL 3.1.3.
  5731. */
  5732. SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  5733. {
  5734. if (b > SDL_SIZE_MAX - a) {
  5735. return false;
  5736. }
  5737. *ret = a + b;
  5738. return true;
  5739. }
  5740. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  5741. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  5742. /* This needs to be wrapped in an inline rather than being a direct #define,
  5743. * the same as the call to __builtin_mul_overflow() above. */
  5744. SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  5745. {
  5746. return (__builtin_add_overflow(a, b, ret) == 0);
  5747. }
  5748. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  5749. #endif
  5750. #endif
  5751. /* This is a generic function pointer which should be cast to the type you expect */
  5752. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  5753. /**
  5754. * A generic function pointer.
  5755. *
  5756. * In theory, generic function pointers should use this, instead of `void *`,
  5757. * since some platforms could treat code addresses differently than data
  5758. * addresses. Although in current times no popular platforms make this
  5759. * distinction, it is more correct and portable to use the correct type for a
  5760. * generic pointer.
  5761. *
  5762. * If for some reason you need to force this typedef to be an actual `void *`,
  5763. * perhaps to work around a compiler or existing code, you can define
  5764. * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
  5765. *
  5766. * \since This datatype is available since SDL 3.1.3.
  5767. */
  5768. typedef void (*SDL_FunctionPointer)(void);
  5769. #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
  5770. typedef void *SDL_FunctionPointer;
  5771. #else
  5772. typedef void (*SDL_FunctionPointer)(void);
  5773. #endif
  5774. /* Ends C function definitions when using C++ */
  5775. #ifdef __cplusplus
  5776. }
  5777. #endif
  5778. #include <SDL3/SDL_close_code.h>
  5779. #endif /* SDL_stdinc_h_ */