SDL_stdinc.h 206 KB

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