SDL_stdinc.h 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221
  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. * \param malloc_func custom malloc function.
  1466. * \param calloc_func custom calloc function.
  1467. * \param realloc_func custom realloc function.
  1468. * \param free_func custom free function.
  1469. * \returns true on success or false on failure; call SDL_GetError() for more
  1470. * information.
  1471. *
  1472. * \threadsafety It is safe to call this function from any thread, but one
  1473. * should not replace the memory functions once any allocations
  1474. * are made!
  1475. *
  1476. * \since This function is available since SDL 3.2.0.
  1477. *
  1478. * \sa SDL_GetMemoryFunctions
  1479. * \sa SDL_GetOriginalMemoryFunctions
  1480. */
  1481. extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  1482. SDL_calloc_func calloc_func,
  1483. SDL_realloc_func realloc_func,
  1484. SDL_free_func free_func);
  1485. /**
  1486. * Allocate memory aligned to a specific alignment.
  1487. *
  1488. * The memory returned by this function must be freed with SDL_aligned_free(),
  1489. * _not_ SDL_free().
  1490. *
  1491. * If `alignment` is less than the size of `void *`, it will be increased to
  1492. * match that.
  1493. *
  1494. * The returned memory address will be a multiple of the alignment value, and
  1495. * the size of the memory allocated will be a multiple of the alignment value.
  1496. *
  1497. * \param alignment the alignment of the memory.
  1498. * \param size the size to allocate.
  1499. * \returns a pointer to the aligned memory, or NULL if allocation failed.
  1500. *
  1501. * \threadsafety It is safe to call this function from any thread.
  1502. *
  1503. * \since This function is available since SDL 3.2.0.
  1504. *
  1505. * \sa SDL_aligned_free
  1506. */
  1507. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  1508. /**
  1509. * Allocate zero-initialized memory aligned to a specific alignment.
  1510. *
  1511. * The memory returned by this function must be freed with SDL_aligned_free(),
  1512. * _not_ SDL_free().
  1513. *
  1514. * If `alignment` is less than the size of `void *`, it will be increased to
  1515. * match that.
  1516. *
  1517. * The returned memory address will be a multiple of the alignment value, and
  1518. * the size of the memory allocated will be a multiple of the alignment value.
  1519. *
  1520. * \param alignment the alignment of the memory.
  1521. * \param size the size to allocate.
  1522. * \returns a pointer to the aligned memory, or NULL if allocation failed.
  1523. *
  1524. * \threadsafety It is safe to call this function from any thread.
  1525. *
  1526. * \since This function is available since SDL 3.6.0.
  1527. *
  1528. * \sa SDL_aligned_free
  1529. */
  1530. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc_zero(size_t alignment, size_t size);
  1531. /**
  1532. * Free memory allocated by SDL_aligned_alloc().
  1533. *
  1534. * The pointer is no longer valid after this call and cannot be dereferenced
  1535. * anymore.
  1536. *
  1537. * If `mem` is NULL, this function does nothing.
  1538. *
  1539. * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
  1540. *
  1541. * \threadsafety It is safe to call this function from any thread.
  1542. *
  1543. * \since This function is available since SDL 3.2.0.
  1544. *
  1545. * \sa SDL_aligned_alloc
  1546. */
  1547. extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  1548. /**
  1549. * Get the number of outstanding (unfreed) allocations.
  1550. *
  1551. * \returns the number of allocations or -1 if allocation counting is
  1552. * disabled.
  1553. *
  1554. * \threadsafety It is safe to call this function from any thread.
  1555. *
  1556. * \since This function is available since SDL 3.2.0.
  1557. */
  1558. extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  1559. /**
  1560. * A thread-safe set of environment variables
  1561. *
  1562. * \since This struct is available since SDL 3.2.0.
  1563. *
  1564. * \sa SDL_GetEnvironment
  1565. * \sa SDL_CreateEnvironment
  1566. * \sa SDL_GetEnvironmentVariable
  1567. * \sa SDL_GetEnvironmentVariables
  1568. * \sa SDL_SetEnvironmentVariable
  1569. * \sa SDL_UnsetEnvironmentVariable
  1570. * \sa SDL_DestroyEnvironment
  1571. */
  1572. typedef struct SDL_Environment SDL_Environment;
  1573. /**
  1574. * Get the process environment.
  1575. *
  1576. * This is initialized at application start and is not affected by setenv()
  1577. * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
  1578. * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
  1579. * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
  1580. * in the C runtime environment after SDL_Quit().
  1581. *
  1582. * \returns a pointer to the environment for the process or NULL on failure;
  1583. * call SDL_GetError() for more information.
  1584. *
  1585. * \threadsafety It is safe to call this function from any thread.
  1586. *
  1587. * \since This function is available since SDL 3.2.0.
  1588. *
  1589. * \sa SDL_GetEnvironmentVariable
  1590. * \sa SDL_GetEnvironmentVariables
  1591. * \sa SDL_SetEnvironmentVariable
  1592. * \sa SDL_UnsetEnvironmentVariable
  1593. */
  1594. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
  1595. /**
  1596. * Create a set of environment variables
  1597. *
  1598. * \param populated true to initialize it from the C runtime environment,
  1599. * false to create an empty environment.
  1600. * \returns a pointer to the new environment or NULL on failure; call
  1601. * SDL_GetError() for more information.
  1602. *
  1603. * \threadsafety If `populated` is false, it is safe to call this function
  1604. * from any thread, otherwise it is safe if no other threads are
  1605. * calling setenv() or unsetenv()
  1606. *
  1607. * \since This function is available since SDL 3.2.0.
  1608. *
  1609. * \sa SDL_GetEnvironmentVariable
  1610. * \sa SDL_GetEnvironmentVariables
  1611. * \sa SDL_SetEnvironmentVariable
  1612. * \sa SDL_UnsetEnvironmentVariable
  1613. * \sa SDL_DestroyEnvironment
  1614. */
  1615. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
  1616. /**
  1617. * Get the value of a variable in the environment.
  1618. *
  1619. * \param env the environment to query.
  1620. * \param name the name of the variable to get.
  1621. * \returns a pointer to the value of the variable or NULL if it can't be
  1622. * found.
  1623. *
  1624. * \threadsafety It is safe to call this function from any thread.
  1625. *
  1626. * \since This function is available since SDL 3.2.0.
  1627. *
  1628. * \sa SDL_GetEnvironment
  1629. * \sa SDL_CreateEnvironment
  1630. * \sa SDL_GetEnvironmentVariables
  1631. * \sa SDL_SetEnvironmentVariable
  1632. * \sa SDL_UnsetEnvironmentVariable
  1633. */
  1634. extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
  1635. /**
  1636. * Get all variables in the environment.
  1637. *
  1638. * \param env the environment to query.
  1639. * \returns a NULL terminated array of pointers to environment variables in
  1640. * the form "variable=value" or NULL on failure; call SDL_GetError()
  1641. * for more information. This is a single allocation that should be
  1642. * freed with SDL_free() when it is no longer needed.
  1643. *
  1644. * \threadsafety It is safe to call this function from any thread.
  1645. *
  1646. * \since This function is available since SDL 3.2.0.
  1647. *
  1648. * \sa SDL_GetEnvironment
  1649. * \sa SDL_CreateEnvironment
  1650. * \sa SDL_GetEnvironmentVariable
  1651. * \sa SDL_SetEnvironmentVariable
  1652. * \sa SDL_UnsetEnvironmentVariable
  1653. */
  1654. extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
  1655. /**
  1656. * Set the value of a variable in the environment.
  1657. *
  1658. * \param env the environment to modify.
  1659. * \param name the name of the variable to set.
  1660. * \param value the value of the variable to set.
  1661. * \param overwrite true to overwrite the variable if it exists, false to
  1662. * return success without setting the variable if it already
  1663. * exists.
  1664. * \returns true on success or false on failure; call SDL_GetError() for more
  1665. * information.
  1666. *
  1667. * \threadsafety It is safe to call this function from any thread.
  1668. *
  1669. * \since This function is available since SDL 3.2.0.
  1670. *
  1671. * \sa SDL_GetEnvironment
  1672. * \sa SDL_CreateEnvironment
  1673. * \sa SDL_GetEnvironmentVariable
  1674. * \sa SDL_GetEnvironmentVariables
  1675. * \sa SDL_UnsetEnvironmentVariable
  1676. */
  1677. extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
  1678. /**
  1679. * Clear a variable from the environment.
  1680. *
  1681. * \param env the environment to modify.
  1682. * \param name the name of the variable to unset.
  1683. * \returns true on success or false on failure; call SDL_GetError() for more
  1684. * information.
  1685. *
  1686. * \threadsafety It is safe to call this function from any thread.
  1687. *
  1688. * \since This function is available since SDL 3.2.0.
  1689. *
  1690. * \sa SDL_GetEnvironment
  1691. * \sa SDL_CreateEnvironment
  1692. * \sa SDL_GetEnvironmentVariable
  1693. * \sa SDL_GetEnvironmentVariables
  1694. * \sa SDL_SetEnvironmentVariable
  1695. * \sa SDL_UnsetEnvironmentVariable
  1696. */
  1697. extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
  1698. /**
  1699. * Destroy a set of environment variables.
  1700. *
  1701. * \param env the environment to destroy.
  1702. *
  1703. * \threadsafety It is safe to call this function from any thread, as long as
  1704. * the environment is no longer in use.
  1705. *
  1706. * \since This function is available since SDL 3.2.0.
  1707. *
  1708. * \sa SDL_CreateEnvironment
  1709. */
  1710. extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
  1711. /**
  1712. * Get the value of a variable in the environment.
  1713. *
  1714. * The name of the variable is case sensitive on all platforms.
  1715. *
  1716. * This function uses SDL's cached copy of the environment and is thread-safe.
  1717. *
  1718. * \param name the name of the variable to get.
  1719. * \returns a pointer to the value of the variable or NULL if it can't be
  1720. * found.
  1721. *
  1722. * \threadsafety It is safe to call this function from any thread.
  1723. *
  1724. * \since This function is available since SDL 3.2.0.
  1725. */
  1726. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
  1727. /**
  1728. * Get the value of a variable in the environment.
  1729. *
  1730. * This function bypasses SDL's cached copy of the environment and is not
  1731. * thread-safe.
  1732. *
  1733. * On some platforms, this may make case-insensitive matches, while other
  1734. * platforms are case-sensitive. It is best to be precise with strings used
  1735. * for queries through this interface. SDL_getenv is always case-sensitive,
  1736. * however.
  1737. *
  1738. * \param name the name of the variable to get.
  1739. * \returns a pointer to the value of the variable or NULL if it can't be
  1740. * found.
  1741. *
  1742. * \threadsafety This function is not thread safe, consider using SDL_getenv()
  1743. * instead.
  1744. *
  1745. * \since This function is available since SDL 3.2.0.
  1746. *
  1747. * \sa SDL_getenv
  1748. */
  1749. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
  1750. /**
  1751. * Set the value of a variable in the environment.
  1752. *
  1753. * \param name the name of the variable to set.
  1754. * \param value the value of the variable to set.
  1755. * \param overwrite 1 to overwrite the variable if it exists, 0 to return
  1756. * success without setting the variable if it already exists.
  1757. * \returns 0 on success, -1 on error.
  1758. *
  1759. * \threadsafety This function is not thread safe, consider using
  1760. * SDL_SetEnvironmentVariable() instead.
  1761. *
  1762. * \since This function is available since SDL 3.2.0.
  1763. *
  1764. * \sa SDL_SetEnvironmentVariable
  1765. */
  1766. extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
  1767. /**
  1768. * Clear a variable from the environment.
  1769. *
  1770. * \param name the name of the variable to unset.
  1771. * \returns 0 on success, -1 on error.
  1772. *
  1773. * \threadsafety This function is not thread safe, consider using
  1774. * SDL_UnsetEnvironmentVariable() instead.
  1775. *
  1776. * \since This function is available since SDL 3.2.0.
  1777. *
  1778. * \sa SDL_UnsetEnvironmentVariable
  1779. */
  1780. extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
  1781. /**
  1782. * A callback used with SDL sorting and binary search functions.
  1783. *
  1784. * \param a a pointer to the first element being compared.
  1785. * \param b a pointer to the second element being compared.
  1786. * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
  1787. * before `a`, 0 if they are equal. If two elements are equal, their
  1788. * order in the sorted array is undefined.
  1789. *
  1790. * \since This callback is available since SDL 3.2.0.
  1791. *
  1792. * \sa SDL_bsearch
  1793. * \sa SDL_qsort
  1794. */
  1795. typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
  1796. /**
  1797. * Sort an array.
  1798. *
  1799. * For example:
  1800. *
  1801. * ```c
  1802. * typedef struct {
  1803. * int key;
  1804. * const char *string;
  1805. * } data;
  1806. *
  1807. * int SDLCALL compare(const void *a, const void *b)
  1808. * {
  1809. * const data *A = (const data *)a;
  1810. * const data *B = (const data *)b;
  1811. *
  1812. * if (A->n < B->n) {
  1813. * return -1;
  1814. * } else if (B->n < A->n) {
  1815. * return 1;
  1816. * } else {
  1817. * return 0;
  1818. * }
  1819. * }
  1820. *
  1821. * data values[] = {
  1822. * { 3, "third" }, { 1, "first" }, { 2, "second" }
  1823. * };
  1824. *
  1825. * SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
  1826. * ```
  1827. *
  1828. * \param base a pointer to the start of the array.
  1829. * \param nmemb the number of elements in the array.
  1830. * \param size the size of the elements in the array.
  1831. * \param compare a function used to compare elements in the array.
  1832. *
  1833. * \threadsafety It is safe to call this function from any thread.
  1834. *
  1835. * \since This function is available since SDL 3.2.0.
  1836. *
  1837. * \sa SDL_bsearch
  1838. * \sa SDL_qsort_r
  1839. */
  1840. extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1841. /**
  1842. * Perform a binary search on a previously sorted array.
  1843. *
  1844. * For example:
  1845. *
  1846. * ```c
  1847. * typedef struct {
  1848. * int key;
  1849. * const char *string;
  1850. * } data;
  1851. *
  1852. * int SDLCALL compare(const void *a, const void *b)
  1853. * {
  1854. * const data *A = (const data *)a;
  1855. * const data *B = (const data *)b;
  1856. *
  1857. * if (A->n < B->n) {
  1858. * return -1;
  1859. * } else if (B->n < A->n) {
  1860. * return 1;
  1861. * } else {
  1862. * return 0;
  1863. * }
  1864. * }
  1865. *
  1866. * data values[] = {
  1867. * { 1, "first" }, { 2, "second" }, { 3, "third" }
  1868. * };
  1869. * data key = { 2, NULL };
  1870. *
  1871. * data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
  1872. * ```
  1873. *
  1874. * \param key a pointer to a key equal to the element being searched for.
  1875. * \param base a pointer to the start of the array.
  1876. * \param nmemb the number of elements in the array.
  1877. * \param size the size of the elements in the array.
  1878. * \param compare a function used to compare elements in the array.
  1879. * \returns a pointer to the matching element in the array, or NULL if not
  1880. * found.
  1881. *
  1882. * \threadsafety It is safe to call this function from any thread.
  1883. *
  1884. * \since This function is available since SDL 3.2.0.
  1885. *
  1886. * \sa SDL_bsearch_r
  1887. * \sa SDL_qsort
  1888. */
  1889. extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1890. /**
  1891. * A callback used with SDL sorting and binary search functions.
  1892. *
  1893. * \param userdata the `userdata` pointer passed to the sort function.
  1894. * \param a a pointer to the first element being compared.
  1895. * \param b a pointer to the second element being compared.
  1896. * \returns -1 if `a` should be sorted before `b`, 1 if `b` should be sorted
  1897. * before `a`, 0 if they are equal. If two elements are equal, their
  1898. * order in the sorted array is undefined.
  1899. *
  1900. * \since This callback is available since SDL 3.2.0.
  1901. *
  1902. * \sa SDL_qsort_r
  1903. * \sa SDL_bsearch_r
  1904. */
  1905. typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
  1906. /**
  1907. * Sort an array, passing a userdata pointer to the compare function.
  1908. *
  1909. * For example:
  1910. *
  1911. * ```c
  1912. * typedef enum {
  1913. * sort_increasing,
  1914. * sort_decreasing,
  1915. * } sort_method;
  1916. *
  1917. * typedef struct {
  1918. * int key;
  1919. * const char *string;
  1920. * } data;
  1921. *
  1922. * int SDLCALL compare(const void *userdata, const void *a, const void *b)
  1923. * {
  1924. * sort_method method = (sort_method)(uintptr_t)userdata;
  1925. * const data *A = (const data *)a;
  1926. * const data *B = (const data *)b;
  1927. *
  1928. * if (A->key < B->key) {
  1929. * return (method == sort_increasing) ? -1 : 1;
  1930. * } else if (B->key < A->key) {
  1931. * return (method == sort_increasing) ? 1 : -1;
  1932. * } else {
  1933. * return 0;
  1934. * }
  1935. * }
  1936. *
  1937. * data values[] = {
  1938. * { 3, "third" }, { 1, "first" }, { 2, "second" }
  1939. * };
  1940. *
  1941. * SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
  1942. * ```
  1943. *
  1944. * \param base a pointer to the start of the array.
  1945. * \param nmemb the number of elements in the array.
  1946. * \param size the size of the elements in the array.
  1947. * \param compare a function used to compare elements in the array.
  1948. * \param userdata a pointer to pass to the compare function.
  1949. *
  1950. * \threadsafety It is safe to call this function from any thread.
  1951. *
  1952. * \since This function is available since SDL 3.2.0.
  1953. *
  1954. * \sa SDL_bsearch_r
  1955. * \sa SDL_qsort
  1956. */
  1957. extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
  1958. /**
  1959. * Perform a binary search on a previously sorted array, passing a userdata
  1960. * pointer to the compare function.
  1961. *
  1962. * For example:
  1963. *
  1964. * ```c
  1965. * typedef enum {
  1966. * sort_increasing,
  1967. * sort_decreasing,
  1968. * } sort_method;
  1969. *
  1970. * typedef struct {
  1971. * int key;
  1972. * const char *string;
  1973. * } data;
  1974. *
  1975. * int SDLCALL compare(const void *userdata, const void *a, const void *b)
  1976. * {
  1977. * sort_method method = (sort_method)(uintptr_t)userdata;
  1978. * const data *A = (const data *)a;
  1979. * const data *B = (const data *)b;
  1980. *
  1981. * if (A->key < B->key) {
  1982. * return (method == sort_increasing) ? -1 : 1;
  1983. * } else if (B->key < A->key) {
  1984. * return (method == sort_increasing) ? 1 : -1;
  1985. * } else {
  1986. * return 0;
  1987. * }
  1988. * }
  1989. *
  1990. * data values[] = {
  1991. * { 1, "first" }, { 2, "second" }, { 3, "third" }
  1992. * };
  1993. * data key = { 2, NULL };
  1994. *
  1995. * data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
  1996. * ```
  1997. *
  1998. * \param key a pointer to a key equal to the element being searched for.
  1999. * \param base a pointer to the start of the array.
  2000. * \param nmemb the number of elements in the array.
  2001. * \param size the size of the elements in the array.
  2002. * \param compare a function used to compare elements in the array.
  2003. * \param userdata a pointer to pass to the compare function.
  2004. * \returns a pointer to the matching element in the array, or NULL if not
  2005. * found.
  2006. *
  2007. * \threadsafety It is safe to call this function from any thread.
  2008. *
  2009. * \since This function is available since SDL 3.2.0.
  2010. *
  2011. * \sa SDL_bsearch
  2012. * \sa SDL_qsort_r
  2013. */
  2014. 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);
  2015. /**
  2016. * Compute the absolute value of `x`.
  2017. *
  2018. * \param x an integer value.
  2019. * \returns the absolute value of x.
  2020. *
  2021. * \threadsafety It is safe to call this function from any thread.
  2022. *
  2023. * \since This function is available since SDL 3.2.0.
  2024. */
  2025. extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
  2026. /**
  2027. * Return the lesser of two values.
  2028. *
  2029. * This is a helper macro that might be more clear than writing out the
  2030. * comparisons directly, and works with any type that can be compared with the
  2031. * `<` operator. However, it double-evaluates both its parameters, so do not
  2032. * use expressions with side-effects here.
  2033. *
  2034. * \param x the first value to compare.
  2035. * \param y the second value to compare.
  2036. * \returns the lesser of `x` and `y`.
  2037. *
  2038. * \threadsafety It is safe to call this macro from any thread.
  2039. *
  2040. * \since This macro is available since SDL 3.2.0.
  2041. */
  2042. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  2043. /**
  2044. * Return the greater of two values.
  2045. *
  2046. * This is a helper macro that might be more clear than writing out the
  2047. * comparisons directly, and works with any type that can be compared with the
  2048. * `>` operator. However, it double-evaluates both its parameters, so do not
  2049. * use expressions with side-effects here.
  2050. *
  2051. * \param x the first value to compare.
  2052. * \param y the second value to compare.
  2053. * \returns the greater of `x` and `y`.
  2054. *
  2055. * \threadsafety It is safe to call this macro from any thread.
  2056. *
  2057. * \since This macro is available since SDL 3.2.0.
  2058. */
  2059. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  2060. /**
  2061. * Return a value clamped to a range.
  2062. *
  2063. * If `x` is outside the range a values between `a` and `b`, the returned
  2064. * value will be `a` or `b` as appropriate. Otherwise, `x` is returned.
  2065. *
  2066. * This macro will produce incorrect results if `b` is less than `a`.
  2067. *
  2068. * This is a helper macro that might be more clear than writing out the
  2069. * comparisons directly, and works with any type that can be compared with the
  2070. * `<` and `>` operators. However, it double-evaluates all its parameters, so
  2071. * do not use expressions with side-effects here.
  2072. *
  2073. * \param x the value to compare.
  2074. * \param a the low end value.
  2075. * \param b the high end value.
  2076. * \returns x, clamped between a and b.
  2077. *
  2078. * \threadsafety It is safe to call this macro from any thread.
  2079. *
  2080. * \since This macro is available since SDL 3.2.0.
  2081. */
  2082. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  2083. /**
  2084. * Query if a character is alphabetic (a letter).
  2085. *
  2086. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2087. * for English 'a-z' and 'A-Z' as true.
  2088. *
  2089. * \param x character value to check.
  2090. * \returns non-zero if x falls within the character class, zero otherwise.
  2091. *
  2092. * \threadsafety It is safe to call this function from any thread.
  2093. *
  2094. * \since This function is available since SDL 3.2.0.
  2095. */
  2096. extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
  2097. /**
  2098. * Query if a character is alphabetic (a letter) or a number.
  2099. *
  2100. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2101. * for English 'a-z', 'A-Z', and '0-9' as true.
  2102. *
  2103. * \param x character value to check.
  2104. * \returns non-zero if x falls within the character class, zero otherwise.
  2105. *
  2106. * \threadsafety It is safe to call this function from any thread.
  2107. *
  2108. * \since This function is available since SDL 3.2.0.
  2109. */
  2110. extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
  2111. /**
  2112. * Report if a character is blank (a space or tab).
  2113. *
  2114. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2115. * 0x20 (space) or 0x9 (tab) as true.
  2116. *
  2117. * \param x character value to check.
  2118. * \returns non-zero if x falls within the character class, zero otherwise.
  2119. *
  2120. * \threadsafety It is safe to call this function from any thread.
  2121. *
  2122. * \since This function is available since SDL 3.2.0.
  2123. */
  2124. extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
  2125. /**
  2126. * Report if a character is a control character.
  2127. *
  2128. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2129. * 0 through 0x1F, and 0x7F, as true.
  2130. *
  2131. * \param x character value to check.
  2132. * \returns non-zero if x falls within the character class, zero otherwise.
  2133. *
  2134. * \threadsafety It is safe to call this function from any thread.
  2135. *
  2136. * \since This function is available since SDL 3.2.0.
  2137. */
  2138. extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
  2139. /**
  2140. * Report if a character is a numeric digit.
  2141. *
  2142. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2143. * '0' (0x30) through '9' (0x39), as true.
  2144. *
  2145. * \param x character value to check.
  2146. * \returns non-zero if x falls within the character class, zero otherwise.
  2147. *
  2148. * \threadsafety It is safe to call this function from any thread.
  2149. *
  2150. * \since This function is available since SDL 3.2.0.
  2151. */
  2152. extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
  2153. /**
  2154. * Report if a character is a hexadecimal digit.
  2155. *
  2156. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2157. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  2158. *
  2159. * \param x character value to check.
  2160. * \returns non-zero if x falls within the character class, zero otherwise.
  2161. *
  2162. * \threadsafety It is safe to call this function from any thread.
  2163. *
  2164. * \since This function is available since SDL 3.2.0.
  2165. */
  2166. extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
  2167. /**
  2168. * Report if a character is a punctuation mark.
  2169. *
  2170. * **WARNING**: Regardless of system locale, this is equivalent to
  2171. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  2172. *
  2173. * \param x character value to check.
  2174. * \returns non-zero if x falls within the character class, zero otherwise.
  2175. *
  2176. * \threadsafety It is safe to call this function from any thread.
  2177. *
  2178. * \since This function is available since SDL 3.2.0.
  2179. *
  2180. * \sa SDL_isgraph
  2181. * \sa SDL_isalnum
  2182. */
  2183. extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
  2184. /**
  2185. * Report if a character is whitespace.
  2186. *
  2187. * **WARNING**: Regardless of system locale, this will only treat the
  2188. * following ASCII values as true:
  2189. *
  2190. * - space (0x20)
  2191. * - tab (0x09)
  2192. * - newline (0x0A)
  2193. * - vertical tab (0x0B)
  2194. * - form feed (0x0C)
  2195. * - return (0x0D)
  2196. *
  2197. * \param x character value to check.
  2198. * \returns non-zero if x falls within the character class, zero otherwise.
  2199. *
  2200. * \threadsafety It is safe to call this function from any thread.
  2201. *
  2202. * \since This function is available since SDL 3.2.0.
  2203. */
  2204. extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
  2205. /**
  2206. * Report if a character is upper case.
  2207. *
  2208. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2209. * 'A' through 'Z' as true.
  2210. *
  2211. * \param x character value to check.
  2212. * \returns non-zero if x falls within the character class, zero otherwise.
  2213. *
  2214. * \threadsafety It is safe to call this function from any thread.
  2215. *
  2216. * \since This function is available since SDL 3.2.0.
  2217. */
  2218. extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
  2219. /**
  2220. * Report if a character is lower case.
  2221. *
  2222. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2223. * 'a' through 'z' as true.
  2224. *
  2225. * \param x character value to check.
  2226. * \returns non-zero if x falls within the character class, zero otherwise.
  2227. *
  2228. * \threadsafety It is safe to call this function from any thread.
  2229. *
  2230. * \since This function is available since SDL 3.2.0.
  2231. */
  2232. extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
  2233. /**
  2234. * Report if a character is "printable".
  2235. *
  2236. * Be advised that "printable" has a definition that goes back to text
  2237. * terminals from the dawn of computing, making this a sort of special case
  2238. * function that is not suitable for Unicode (or most any) text management.
  2239. *
  2240. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  2241. * ' ' (0x20) through '~' (0x7E) as true.
  2242. *
  2243. * \param x character value to check.
  2244. * \returns non-zero if x falls within the character class, zero otherwise.
  2245. *
  2246. * \threadsafety It is safe to call this function from any thread.
  2247. *
  2248. * \since This function is available since SDL 3.2.0.
  2249. */
  2250. extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
  2251. /**
  2252. * Report if a character is any "printable" except space.
  2253. *
  2254. * Be advised that "printable" has a definition that goes back to text
  2255. * terminals from the dawn of computing, making this a sort of special case
  2256. * function that is not suitable for Unicode (or most any) text management.
  2257. *
  2258. * **WARNING**: Regardless of system locale, this is equivalent to
  2259. * `(SDL_isprint(x)) && ((x) != ' ')`.
  2260. *
  2261. * \param x character value to check.
  2262. * \returns non-zero if x falls within the character class, zero otherwise.
  2263. *
  2264. * \threadsafety It is safe to call this function from any thread.
  2265. *
  2266. * \since This function is available since SDL 3.2.0.
  2267. *
  2268. * \sa SDL_isprint
  2269. */
  2270. extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
  2271. /**
  2272. * Convert low-ASCII English letters to uppercase.
  2273. *
  2274. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2275. * values 'a' through 'z' to uppercase.
  2276. *
  2277. * This function returns the uppercase equivalent of `x`. If a character
  2278. * cannot be converted, or is already uppercase, this function returns `x`.
  2279. *
  2280. * \param x character value to check.
  2281. * \returns capitalized version of x, or x if no conversion available.
  2282. *
  2283. * \threadsafety It is safe to call this function from any thread.
  2284. *
  2285. * \since This function is available since SDL 3.2.0.
  2286. */
  2287. extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
  2288. /**
  2289. * Convert low-ASCII English letters to lowercase.
  2290. *
  2291. * **WARNING**: Regardless of system locale, this will only convert ASCII
  2292. * values 'A' through 'Z' to lowercase.
  2293. *
  2294. * This function returns the lowercase equivalent of `x`. If a character
  2295. * cannot be converted, or is already lowercase, this function returns `x`.
  2296. *
  2297. * \param x character value to check.
  2298. * \returns lowercase version of x, or x if no conversion available.
  2299. *
  2300. * \threadsafety It is safe to call this function from any thread.
  2301. *
  2302. * \since This function is available since SDL 3.2.0.
  2303. */
  2304. extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
  2305. /**
  2306. * Calculate a CRC-16 value.
  2307. *
  2308. * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
  2309. *
  2310. * This function can be called multiple times, to stream data to be
  2311. * checksummed in blocks. Each call must provide the previous CRC-16 return
  2312. * value to be updated with the next block. The first call to this function
  2313. * for a set of blocks should pass in a zero CRC value.
  2314. *
  2315. * \param crc the current checksum for this data set, or 0 for a new data set.
  2316. * \param data a new block of data to add to the checksum.
  2317. * \param len the size, in bytes, of the new block of data.
  2318. * \returns a CRC-16 checksum value of all blocks in the data set.
  2319. *
  2320. * \threadsafety It is safe to call this function from any thread.
  2321. *
  2322. * \since This function is available since SDL 3.2.0.
  2323. */
  2324. extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  2325. /**
  2326. * Calculate a CRC-32 value.
  2327. *
  2328. * https://en.wikipedia.org/wiki/Cyclic_redundancy_check
  2329. *
  2330. * This function can be called multiple times, to stream data to be
  2331. * checksummed in blocks. Each call must provide the previous CRC-32 return
  2332. * value to be updated with the next block. The first call to this function
  2333. * for a set of blocks should pass in a zero CRC value.
  2334. *
  2335. * \param crc the current checksum for this data set, or 0 for a new data set.
  2336. * \param data a new block of data to add to the checksum.
  2337. * \param len the size, in bytes, of the new block of data.
  2338. * \returns a CRC-32 checksum value of all blocks in the data set.
  2339. *
  2340. * \threadsafety It is safe to call this function from any thread.
  2341. *
  2342. * \since This function is available since SDL 3.2.0.
  2343. */
  2344. extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  2345. /**
  2346. * Calculate a 32-bit MurmurHash3 value for a block of data.
  2347. *
  2348. * https://en.wikipedia.org/wiki/MurmurHash
  2349. *
  2350. * A seed may be specified, which changes the final results consistently, but
  2351. * this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous
  2352. * result from this function back into itself as the next seed value to
  2353. * calculate a hash in chunks; it won't produce the same hash as it would if
  2354. * the same data was provided in a single call.
  2355. *
  2356. * If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not
  2357. * cryptographically secure, so it shouldn't be used for hashing top-secret
  2358. * data.
  2359. *
  2360. * \param data the data to be hashed.
  2361. * \param len the size of data, in bytes.
  2362. * \param seed a value that alters the final hash value.
  2363. * \returns a Murmur3 32-bit hash value.
  2364. *
  2365. * \threadsafety It is safe to call this function from any thread.
  2366. *
  2367. * \since This function is available since SDL 3.2.0.
  2368. */
  2369. extern SDL_DECLSPEC Uint32 SDLCALL SDL_murmur3_32(const void *data, size_t len, Uint32 seed);
  2370. /**
  2371. * Copy non-overlapping memory.
  2372. *
  2373. * The memory regions must not overlap. If they do, use SDL_memmove() instead.
  2374. *
  2375. * \param dst The destination memory region. Must not be NULL, and must not
  2376. * overlap with `src`.
  2377. * \param src The source memory region. Must not be NULL, and must not overlap
  2378. * with `dst`.
  2379. * \param len The length in bytes of both `dst` and `src`.
  2380. * \returns `dst`.
  2381. *
  2382. * \threadsafety It is safe to call this function from any thread.
  2383. *
  2384. * \since This function is available since SDL 3.2.0.
  2385. *
  2386. * \sa SDL_memmove
  2387. */
  2388. extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  2389. /* Take advantage of compiler optimizations for memcpy */
  2390. #ifndef SDL_SLOW_MEMCPY
  2391. #ifdef SDL_memcpy
  2392. #undef SDL_memcpy
  2393. #endif
  2394. #define SDL_memcpy memcpy
  2395. #endif
  2396. /**
  2397. * A macro to copy memory between objects, with basic type checking.
  2398. *
  2399. * SDL_memcpy and SDL_memmove do not care where you copy memory to and from,
  2400. * which can lead to bugs. This macro aims to avoid most of those bugs by
  2401. * making sure that the source and destination are both pointers to objects
  2402. * that are the same size. It does not check that the objects are the same
  2403. * _type_, just that the copy will not overflow either object.
  2404. *
  2405. * The size check happens at compile time, and the compiler will throw an
  2406. * error if the objects are different sizes.
  2407. *
  2408. * Generally this is intended to copy a single object, not an array.
  2409. *
  2410. * This macro looks like it double-evaluates its parameters, but the extras
  2411. * them are in `sizeof` sections, which generate no code nor side-effects.
  2412. *
  2413. * \param dst a pointer to the destination object. Must not be NULL.
  2414. * \param src a pointer to the source object. Must not be NULL.
  2415. *
  2416. * \threadsafety It is safe to call this function from any thread.
  2417. *
  2418. * \since This function is available since SDL 3.2.0.
  2419. */
  2420. #define SDL_copyp(dst, src) \
  2421. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  2422. SDL_memcpy((dst), (src), sizeof(*(src)))
  2423. /**
  2424. * Copy memory ranges that might overlap.
  2425. *
  2426. * It is okay for the memory regions to overlap. If you are confident that the
  2427. * regions never overlap, using SDL_memcpy() may improve performance.
  2428. *
  2429. * \param dst The destination memory region. Must not be NULL.
  2430. * \param src The source memory region. Must not be NULL.
  2431. * \param len The length in bytes of both `dst` and `src`.
  2432. * \returns `dst`.
  2433. *
  2434. * \threadsafety It is safe to call this function from any thread.
  2435. *
  2436. * \since This function is available since SDL 3.2.0.
  2437. *
  2438. * \sa SDL_memcpy
  2439. */
  2440. extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  2441. /* Take advantage of compiler optimizations for memmove */
  2442. #ifndef SDL_SLOW_MEMMOVE
  2443. #ifdef SDL_memmove
  2444. #undef SDL_memmove
  2445. #endif
  2446. #define SDL_memmove memmove
  2447. #endif
  2448. /**
  2449. * Initialize all bytes of buffer of memory to a specific value.
  2450. *
  2451. * This function will set `len` bytes, pointed to by `dst`, to the value
  2452. * specified in `c`.
  2453. *
  2454. * Despite `c` being an `int` instead of a `char`, this only operates on
  2455. * bytes; `c` must be a value between 0 and 255, inclusive.
  2456. *
  2457. * \param dst the destination memory region. Must not be NULL.
  2458. * \param c the byte value to set.
  2459. * \param len the length, in bytes, to set in `dst`.
  2460. * \returns `dst`.
  2461. *
  2462. * \threadsafety It is safe to call this function from any thread.
  2463. *
  2464. * \since This function is available since SDL 3.2.0.
  2465. */
  2466. extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  2467. /**
  2468. * Initialize all 32-bit words of buffer of memory to a specific value.
  2469. *
  2470. * This function will set a buffer of `dwords` Uint32 values, pointed to by
  2471. * `dst`, to the value specified in `val`.
  2472. *
  2473. * Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited
  2474. * to a range of 0-255.
  2475. *
  2476. * \param dst the destination memory region. Must not be NULL.
  2477. * \param val the Uint32 value to set.
  2478. * \param dwords the number of Uint32 values to set in `dst`.
  2479. * \returns `dst`.
  2480. *
  2481. * \threadsafety It is safe to call this function from any thread.
  2482. *
  2483. * \since This function is available since SDL 3.2.0.
  2484. */
  2485. extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  2486. /* Take advantage of compiler optimizations for memset */
  2487. #ifndef SDL_SLOW_MEMSET
  2488. #ifdef SDL_memset
  2489. #undef SDL_memset
  2490. #endif
  2491. #define SDL_memset memset
  2492. #endif
  2493. /**
  2494. * Clear an object's memory to zero.
  2495. *
  2496. * This is wrapper over SDL_memset that handles calculating the object size,
  2497. * so there's no chance of copy/paste errors, and the code is cleaner.
  2498. *
  2499. * This requires an object, not a pointer to an object, nor an array.
  2500. *
  2501. * \param x the object to clear.
  2502. *
  2503. * \threadsafety It is safe to call this macro from any thread.
  2504. *
  2505. * \since This macro is available since SDL 3.2.0.
  2506. *
  2507. * \sa SDL_zerop
  2508. * \sa SDL_zeroa
  2509. */
  2510. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  2511. /**
  2512. * Clear an object's memory to zero, using a pointer.
  2513. *
  2514. * This is wrapper over SDL_memset that handles calculating the object size,
  2515. * so there's no chance of copy/paste errors, and the code is cleaner.
  2516. *
  2517. * This requires a pointer to an object, not an object itself, nor an array.
  2518. *
  2519. * \param x a pointer to the object to clear.
  2520. *
  2521. * \threadsafety It is safe to call this macro from any thread.
  2522. *
  2523. * \since This macro is available since SDL 3.2.0.
  2524. *
  2525. * \sa SDL_zero
  2526. * \sa SDL_zeroa
  2527. */
  2528. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  2529. /**
  2530. * Clear an array's memory to zero.
  2531. *
  2532. * This is wrapper over SDL_memset that handles calculating the array size, so
  2533. * there's no chance of copy/paste errors, and the code is cleaner.
  2534. *
  2535. * This requires an array, not an object, nor a pointer to an object.
  2536. *
  2537. * \param x an array to clear.
  2538. *
  2539. * \threadsafety It is safe to call this macro from any thread.
  2540. *
  2541. * \since This macro is available since SDL 3.2.0.
  2542. *
  2543. * \sa SDL_zero
  2544. * \sa SDL_zerop
  2545. */
  2546. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  2547. /**
  2548. * Compare two buffers of memory.
  2549. *
  2550. * \param s1 the first buffer to compare. NULL is not permitted!
  2551. * \param s2 the second buffer to compare. NULL is not permitted!
  2552. * \param len the number of bytes to compare between the buffers.
  2553. * \returns less than zero if s1 is "less than" s2, greater than zero if s1 is
  2554. * "greater than" s2, and zero if the buffers match exactly for `len`
  2555. * bytes.
  2556. *
  2557. * \threadsafety It is safe to call this function from any thread.
  2558. *
  2559. * \since This function is available since SDL 3.2.0.
  2560. */
  2561. extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  2562. /**
  2563. * This works exactly like wcslen() but doesn't require access to a C runtime.
  2564. *
  2565. * Counts the number of wchar_t values in `wstr`, excluding the null
  2566. * terminator.
  2567. *
  2568. * Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string,
  2569. * this counts wchar_t values in a string, even if the string's encoding is of
  2570. * variable width, like UTF-16.
  2571. *
  2572. * Also be aware that wchar_t is different sizes on different platforms (4
  2573. * bytes on Linux, 2 on Windows, etc).
  2574. *
  2575. * \param wstr The null-terminated wide string to read. Must not be NULL.
  2576. * \returns the length (in wchar_t values, excluding the null terminator) of
  2577. * `wstr`.
  2578. *
  2579. * \threadsafety It is safe to call this function from any thread.
  2580. *
  2581. * \since This function is available since SDL 3.2.0.
  2582. *
  2583. * \sa SDL_wcsnlen
  2584. * \sa SDL_utf8strlen
  2585. * \sa SDL_utf8strnlen
  2586. */
  2587. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  2588. /**
  2589. * This works exactly like wcsnlen() but doesn't require access to a C
  2590. * runtime.
  2591. *
  2592. * Counts up to a maximum of `maxlen` wchar_t values in `wstr`, excluding the
  2593. * null terminator.
  2594. *
  2595. * Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string,
  2596. * this counts wchar_t values in a string, even if the string's encoding is of
  2597. * variable width, like UTF-16.
  2598. *
  2599. * Also be aware that wchar_t is different sizes on different platforms (4
  2600. * bytes on Linux, 2 on Windows, etc).
  2601. *
  2602. * Also, `maxlen` is a count of wide characters, not bytes!
  2603. *
  2604. * \param wstr The null-terminated wide string to read. Must not be NULL.
  2605. * \param maxlen The maximum amount of wide characters to count.
  2606. * \returns the length (in wide characters, excluding the null terminator) of
  2607. * `wstr` but never more than `maxlen`.
  2608. *
  2609. * \threadsafety It is safe to call this function from any thread.
  2610. *
  2611. * \since This function is available since SDL 3.2.0.
  2612. *
  2613. * \sa SDL_wcslen
  2614. * \sa SDL_utf8strlen
  2615. * \sa SDL_utf8strnlen
  2616. */
  2617. extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  2618. /**
  2619. * Copy a wide string.
  2620. *
  2621. * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
  2622. * appends a null terminator.
  2623. *
  2624. * `src` and `dst` must not overlap.
  2625. *
  2626. * If `maxlen` is 0, no wide characters are copied and no null terminator is
  2627. * written.
  2628. *
  2629. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2630. * with `src`.
  2631. * \param src The null-terminated wide string to copy. Must not be NULL, and
  2632. * must not overlap with `dst`.
  2633. * \param maxlen The length (in wide characters) of the destination buffer.
  2634. * \returns the length (in wide characters, excluding the null terminator) of
  2635. * `src`.
  2636. *
  2637. * \threadsafety It is safe to call this function from any thread.
  2638. *
  2639. * \since This function is available since SDL 3.2.0.
  2640. *
  2641. * \sa SDL_wcslcat
  2642. */
  2643. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  2644. /**
  2645. * Concatenate wide strings.
  2646. *
  2647. * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
  2648. * from `src` to the end of the wide string in `dst`, then appends a null
  2649. * terminator.
  2650. *
  2651. * `src` and `dst` must not overlap.
  2652. *
  2653. * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
  2654. * unmodified.
  2655. *
  2656. * \param dst The destination buffer already containing the first
  2657. * null-terminated wide string. Must not be NULL and must not
  2658. * overlap with `src`.
  2659. * \param src The second null-terminated wide string. Must not be NULL, and
  2660. * must not overlap with `dst`.
  2661. * \param maxlen The length (in wide characters) of the destination buffer.
  2662. * \returns the length (in wide characters, excluding the null terminator) of
  2663. * the string in `dst` plus the length of `src`.
  2664. *
  2665. * \threadsafety It is safe to call this function from any thread.
  2666. *
  2667. * \since This function is available since SDL 3.2.0.
  2668. *
  2669. * \sa SDL_wcslcpy
  2670. */
  2671. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  2672. /**
  2673. * Allocate a copy of a wide string.
  2674. *
  2675. * This allocates enough space for a null-terminated copy of `wstr`, using
  2676. * SDL_malloc, and then makes a copy of the string into this space.
  2677. *
  2678. * The returned string is owned by the caller, and should be passed to
  2679. * SDL_free when no longer needed.
  2680. *
  2681. * \param wstr the string to copy.
  2682. * \returns a pointer to the newly-allocated wide string.
  2683. *
  2684. * \threadsafety It is safe to call this function from any thread.
  2685. *
  2686. * \since This function is available since SDL 3.2.0.
  2687. */
  2688. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
  2689. /**
  2690. * Search a wide string for the first instance of a specific substring.
  2691. *
  2692. * The search ends once it finds the requested substring, or a null terminator
  2693. * byte to end the string.
  2694. *
  2695. * Note that this looks for strings of _wide characters_, not _codepoints_, so
  2696. * it's legal to search for malformed and incomplete UTF-16 sequences.
  2697. *
  2698. * \param haystack the wide string to search. Must not be NULL.
  2699. * \param needle the wide string to search for. Must not be NULL.
  2700. * \returns a pointer to the first instance of `needle` in the string, or NULL
  2701. * if not found.
  2702. *
  2703. * \threadsafety It is safe to call this function from any thread.
  2704. *
  2705. * \since This function is available since SDL 3.2.0.
  2706. */
  2707. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  2708. /**
  2709. * Search a wide string, up to n wide chars, for the first instance of a
  2710. * specific substring.
  2711. *
  2712. * The search ends once it finds the requested substring, or a null terminator
  2713. * value to end the string, or `maxlen` wide character have been examined. It
  2714. * is possible to use this function on a wide string without a null
  2715. * terminator.
  2716. *
  2717. * Note that this looks for strings of _wide characters_, not _codepoints_, so
  2718. * it's legal to search for malformed and incomplete UTF-16 sequences.
  2719. *
  2720. * \param haystack the wide string to search. Must not be NULL.
  2721. * \param needle the wide string to search for. Must not be NULL.
  2722. * \param maxlen the maximum number of wide characters to search in
  2723. * `haystack`.
  2724. * \returns a pointer to the first instance of `needle` in the string, or NULL
  2725. * if not found.
  2726. *
  2727. * \threadsafety It is safe to call this function from any thread.
  2728. *
  2729. * \since This function is available since SDL 3.2.0.
  2730. */
  2731. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  2732. /**
  2733. * Compare two null-terminated wide strings.
  2734. *
  2735. * This only compares wchar_t values until it hits a null-terminating
  2736. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  2737. * depending on your platform's wchar_t size), or uses valid Unicode values.
  2738. *
  2739. * \param str1 the first string to compare. NULL is not permitted!
  2740. * \param str2 the second string to compare. NULL is not permitted!
  2741. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2742. * str1 is "greater than" str2, and zero if the strings match
  2743. * exactly.
  2744. *
  2745. * \threadsafety It is safe to call this function from any thread.
  2746. *
  2747. * \since This function is available since SDL 3.2.0.
  2748. */
  2749. extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  2750. /**
  2751. * Compare two wide strings up to a number of wchar_t values.
  2752. *
  2753. * This only compares wchar_t values; it does not care if the string is
  2754. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  2755. * or uses valid Unicode values.
  2756. *
  2757. * Note that while this function is intended to be used with UTF-16 (or
  2758. * UTF-32, depending on your platform's definition of wchar_t), it is
  2759. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  2760. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  2761. * sequence, it will only compare a portion of the final character.
  2762. *
  2763. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  2764. * match to this number of wide chars (or both have matched to a
  2765. * null-terminator character before this count), they will be considered
  2766. * equal.
  2767. *
  2768. * \param str1 the first string to compare. NULL is not permitted!
  2769. * \param str2 the second string to compare. NULL is not permitted!
  2770. * \param maxlen the maximum number of wchar_t to compare.
  2771. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2772. * str1 is "greater than" str2, and zero if the strings match
  2773. * exactly.
  2774. *
  2775. * \threadsafety It is safe to call this function from any thread.
  2776. *
  2777. * \since This function is available since SDL 3.2.0.
  2778. */
  2779. extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  2780. /**
  2781. * Compare two null-terminated wide strings, case-insensitively.
  2782. *
  2783. * This will work with Unicode strings, using a technique called
  2784. * "case-folding" to handle the vast majority of case-sensitive human
  2785. * languages regardless of system locale. It can deal with expanding values: a
  2786. * German Eszett character can compare against two ASCII 's' chars and be
  2787. * considered a match, for example. A notable exception: it does not handle
  2788. * the Turkish 'i' character; human language is complicated!
  2789. *
  2790. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  2791. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  2792. * handles Unicode, it expects the string to be well-formed and not a
  2793. * null-terminated string of arbitrary bytes. Characters that are not valid
  2794. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  2795. * CHARACTER), which is to say two strings of random bits may turn out to
  2796. * match if they convert to the same amount of replacement characters.
  2797. *
  2798. * \param str1 the first string to compare. NULL is not permitted!
  2799. * \param str2 the second string to compare. NULL is not permitted!
  2800. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2801. * str1 is "greater than" str2, and zero if the strings match
  2802. * exactly.
  2803. *
  2804. * \threadsafety It is safe to call this function from any thread.
  2805. *
  2806. * \since This function is available since SDL 3.2.0.
  2807. */
  2808. extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  2809. /**
  2810. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  2811. *
  2812. * This will work with Unicode strings, using a technique called
  2813. * "case-folding" to handle the vast majority of case-sensitive human
  2814. * languages regardless of system locale. It can deal with expanding values: a
  2815. * German Eszett character can compare against two ASCII 's' chars and be
  2816. * considered a match, for example. A notable exception: it does not handle
  2817. * the Turkish 'i' character; human language is complicated!
  2818. *
  2819. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  2820. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  2821. * handles Unicode, it expects the string to be well-formed and not a
  2822. * null-terminated string of arbitrary bytes. Characters that are not valid
  2823. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  2824. * CHARACTER), which is to say two strings of random bits may turn out to
  2825. * match if they convert to the same amount of replacement characters.
  2826. *
  2827. * Note that while this function might deal with variable-sized characters,
  2828. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  2829. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  2830. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  2831. * to overflow a buffer.
  2832. *
  2833. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  2834. * strings match to this number of wchar_t (or both have matched to a
  2835. * null-terminator character before this number of bytes), they will be
  2836. * considered equal.
  2837. *
  2838. * \param str1 the first string to compare. NULL is not permitted!
  2839. * \param str2 the second string to compare. NULL is not permitted!
  2840. * \param maxlen the maximum number of wchar_t values to compare.
  2841. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2842. * str1 is "greater than" str2, and zero if the strings match
  2843. * exactly.
  2844. *
  2845. * \threadsafety It is safe to call this function from any thread.
  2846. *
  2847. * \since This function is available since SDL 3.2.0.
  2848. */
  2849. extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  2850. /**
  2851. * Parse a `long` from a wide string.
  2852. *
  2853. * If `str` starts with whitespace, then those whitespace characters are
  2854. * skipped before attempting to parse the number.
  2855. *
  2856. * If the parsed number does not fit inside a `long`, the result is clamped to
  2857. * the minimum and maximum representable `long` values.
  2858. *
  2859. * \param str The null-terminated wide string to read. Must not be NULL.
  2860. * \param endp If not NULL, the address of the first invalid wide character
  2861. * (i.e. the next character after the parsed number) will be
  2862. * written to this pointer.
  2863. * \param base The base of the integer to read. Supported values are 0 and 2
  2864. * to 36 inclusive. If 0, the base will be inferred from the
  2865. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  2866. * otherwise).
  2867. * \returns the parsed `long`, or 0 if no number could be parsed.
  2868. *
  2869. * \threadsafety It is safe to call this function from any thread.
  2870. *
  2871. * \since This function is available since SDL 3.2.0.
  2872. *
  2873. * \sa SDL_strtol
  2874. */
  2875. extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  2876. /**
  2877. * This works exactly like strlen() but doesn't require access to a C runtime.
  2878. *
  2879. * Counts the bytes in `str`, excluding the null terminator.
  2880. *
  2881. * If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
  2882. *
  2883. * \param str The null-terminated string to read. Must not be NULL.
  2884. * \returns the length (in bytes, excluding the null terminator) of `str`.
  2885. *
  2886. * \threadsafety It is safe to call this function from any thread.
  2887. *
  2888. * \since This function is available since SDL 3.2.0.
  2889. *
  2890. * \sa SDL_strnlen
  2891. * \sa SDL_utf8strlen
  2892. * \sa SDL_utf8strnlen
  2893. */
  2894. extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  2895. /**
  2896. * This works exactly like strnlen() but doesn't require access to a C
  2897. * runtime.
  2898. *
  2899. * Counts up to a maximum of `maxlen` bytes in `str`, excluding the null
  2900. * terminator.
  2901. *
  2902. * If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().
  2903. *
  2904. * \param str The null-terminated string to read. Must not be NULL.
  2905. * \param maxlen The maximum amount of bytes to count.
  2906. * \returns the length (in bytes, excluding the null terminator) of `src` but
  2907. * never more than `maxlen`.
  2908. *
  2909. * \threadsafety It is safe to call this function from any thread.
  2910. *
  2911. * \since This function is available since SDL 3.2.0.
  2912. *
  2913. * \sa SDL_strlen
  2914. * \sa SDL_utf8strlen
  2915. * \sa SDL_utf8strnlen
  2916. */
  2917. extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  2918. /**
  2919. * Copy a string.
  2920. *
  2921. * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
  2922. * then appends a null terminator.
  2923. *
  2924. * If `maxlen` is 0, no characters are copied and no null terminator is
  2925. * written.
  2926. *
  2927. * If you want to copy an UTF-8 string but need to ensure that multi-byte
  2928. * sequences are not truncated, consider using SDL_utf8strlcpy().
  2929. *
  2930. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2931. * with `src`.
  2932. * \param src The null-terminated string to copy. Must not be NULL, and must
  2933. * not overlap with `dst`.
  2934. * \param maxlen The length (in characters) of the destination buffer.
  2935. * \returns the length (in characters, excluding the null terminator) of
  2936. * `src`.
  2937. *
  2938. * \threadsafety It is safe to call this function from any thread.
  2939. *
  2940. * \since This function is available since SDL 3.2.0.
  2941. *
  2942. * \sa SDL_strlcat
  2943. * \sa SDL_utf8strlcpy
  2944. */
  2945. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  2946. /**
  2947. * Copy an UTF-8 string.
  2948. *
  2949. * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
  2950. * also ensuring that the string written to `dst` does not end in a truncated
  2951. * multi-byte sequence. Finally, it appends a null terminator.
  2952. *
  2953. * `src` and `dst` must not overlap.
  2954. *
  2955. * Note that unlike SDL_strlcpy(), this function returns the number of bytes
  2956. * written, not the length of `src`.
  2957. *
  2958. * \param dst The destination buffer. Must not be NULL, and must not overlap
  2959. * with `src`.
  2960. * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
  2961. * must not overlap with `dst`.
  2962. * \param dst_bytes The length (in bytes) of the destination buffer. Must not
  2963. * be 0.
  2964. * \returns the number of bytes written, excluding the null terminator.
  2965. *
  2966. * \threadsafety It is safe to call this function from any thread.
  2967. *
  2968. * \since This function is available since SDL 3.2.0.
  2969. *
  2970. * \sa SDL_strlcpy
  2971. */
  2972. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  2973. /**
  2974. * Concatenate strings.
  2975. *
  2976. * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
  2977. * `src` to the end of the string in `dst`, then appends a null terminator.
  2978. *
  2979. * `src` and `dst` must not overlap.
  2980. *
  2981. * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
  2982. * unmodified.
  2983. *
  2984. * \param dst The destination buffer already containing the first
  2985. * null-terminated string. Must not be NULL and must not overlap
  2986. * with `src`.
  2987. * \param src The second null-terminated string. Must not be NULL, and must
  2988. * not overlap with `dst`.
  2989. * \param maxlen The length (in characters) of the destination buffer.
  2990. * \returns the length (in characters, excluding the null terminator) of the
  2991. * string in `dst` plus the length of `src`.
  2992. *
  2993. * \threadsafety It is safe to call this function from any thread.
  2994. *
  2995. * \since This function is available since SDL 3.2.0.
  2996. *
  2997. * \sa SDL_strlcpy
  2998. */
  2999. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  3000. /**
  3001. * Allocate a copy of a string.
  3002. *
  3003. * This allocates enough space for a null-terminated copy of `str`, using
  3004. * SDL_malloc, and then makes a copy of the string into this space.
  3005. *
  3006. * The returned string is owned by the caller, and should be passed to
  3007. * SDL_free when no longer needed.
  3008. *
  3009. * \param str the string to copy.
  3010. * \returns a pointer to the newly-allocated string.
  3011. *
  3012. * \threadsafety It is safe to call this function from any thread.
  3013. *
  3014. * \since This function is available since SDL 3.2.0.
  3015. */
  3016. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
  3017. /**
  3018. * Allocate a copy of a string, up to n characters.
  3019. *
  3020. * This allocates enough space for a null-terminated copy of `str`, up to
  3021. * `maxlen` bytes, using SDL_malloc, and then makes a copy of the string into
  3022. * this space.
  3023. *
  3024. * If the string is longer than `maxlen` bytes, the returned string will be
  3025. * `maxlen` bytes long, plus a null-terminator character that isn't included
  3026. * in the count.
  3027. *
  3028. * The returned string is owned by the caller, and should be passed to
  3029. * SDL_free when no longer needed.
  3030. *
  3031. * \param str the string to copy.
  3032. * \param maxlen the maximum length of the copied string, not counting the
  3033. * null-terminator character.
  3034. * \returns a pointer to the newly-allocated string.
  3035. *
  3036. * \threadsafety It is safe to call this function from any thread.
  3037. *
  3038. * \since This function is available since SDL 3.2.0.
  3039. */
  3040. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
  3041. /**
  3042. * Reverse a string's contents.
  3043. *
  3044. * This reverses a null-terminated string in-place. Only the content of the
  3045. * string is reversed; the null-terminator character remains at the end of the
  3046. * reversed string.
  3047. *
  3048. * **WARNING**: This function reverses the _bytes_ of the string, not the
  3049. * codepoints. If `str` is a UTF-8 string with Unicode codepoints > 127, this
  3050. * will ruin the string data. You should only use this function on strings
  3051. * that are completely comprised of low ASCII characters.
  3052. *
  3053. * \param str the string to reverse.
  3054. * \returns `str`.
  3055. *
  3056. * \threadsafety It is safe to call this function from any thread.
  3057. *
  3058. * \since This function is available since SDL 3.2.0.
  3059. */
  3060. extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
  3061. /**
  3062. * Convert a string to uppercase.
  3063. *
  3064. * **WARNING**: Regardless of system locale, this will only convert ASCII
  3065. * values 'a' through 'z' to uppercase.
  3066. *
  3067. * This function operates on a null-terminated string of bytes--even if it is
  3068. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  3069. * uppercase equivalents in-place, returning the original `str` pointer.
  3070. *
  3071. * \param str the string to convert in-place. Can not be NULL.
  3072. * \returns the `str` pointer passed into this function.
  3073. *
  3074. * \threadsafety It is safe to call this function from any thread.
  3075. *
  3076. * \since This function is available since SDL 3.2.0.
  3077. *
  3078. * \sa SDL_strlwr
  3079. */
  3080. extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
  3081. /**
  3082. * Convert a string to lowercase.
  3083. *
  3084. * **WARNING**: Regardless of system locale, this will only convert ASCII
  3085. * values 'A' through 'Z' to lowercase.
  3086. *
  3087. * This function operates on a null-terminated string of bytes--even if it is
  3088. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  3089. * lowercase equivalents in-place, returning the original `str` pointer.
  3090. *
  3091. * \param str the string to convert in-place. Can not be NULL.
  3092. * \returns the `str` pointer passed into this function.
  3093. *
  3094. * \threadsafety It is safe to call this function from any thread.
  3095. *
  3096. * \since This function is available since SDL 3.2.0.
  3097. *
  3098. * \sa SDL_strupr
  3099. */
  3100. extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
  3101. /**
  3102. * Search a string for the first instance of a specific byte.
  3103. *
  3104. * The search ends once it finds the requested byte value, or a null
  3105. * terminator byte to end the string.
  3106. *
  3107. * Note that this looks for _bytes_, not _characters_, so you cannot match
  3108. * against a Unicode codepoint > 255, regardless of character encoding.
  3109. *
  3110. * \param str the string to search. Must not be NULL.
  3111. * \param c the byte value to search for.
  3112. * \returns a pointer to the first instance of `c` in the string, or NULL if
  3113. * not found.
  3114. *
  3115. * \threadsafety It is safe to call this function from any thread.
  3116. *
  3117. * \since This function is available since SDL 3.2.0.
  3118. */
  3119. extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
  3120. /**
  3121. * Search a string for the last instance of a specific byte.
  3122. *
  3123. * The search must go until it finds a null terminator byte to end the string.
  3124. *
  3125. * Note that this looks for _bytes_, not _characters_, so you cannot match
  3126. * against a Unicode codepoint > 255, regardless of character encoding.
  3127. *
  3128. * \param str the string to search. Must not be NULL.
  3129. * \param c the byte value to search for.
  3130. * \returns a pointer to the last instance of `c` in the string, or NULL if
  3131. * not found.
  3132. *
  3133. * \threadsafety It is safe to call this function from any thread.
  3134. *
  3135. * \since This function is available since SDL 3.2.0.
  3136. */
  3137. extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
  3138. /**
  3139. * Search a string for the first instance of a specific substring.
  3140. *
  3141. * The search ends once it finds the requested substring, or a null terminator
  3142. * byte to end the string.
  3143. *
  3144. * Note that this looks for strings of _bytes_, not _characters_, so it's
  3145. * legal to search for malformed and incomplete UTF-8 sequences.
  3146. *
  3147. * \param haystack the string to search. Must not be NULL.
  3148. * \param needle the string to search for. Must not be NULL.
  3149. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3150. * if not found.
  3151. *
  3152. * \threadsafety It is safe to call this function from any thread.
  3153. *
  3154. * \since This function is available since SDL 3.2.0.
  3155. */
  3156. extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
  3157. /**
  3158. * Search a string, up to n bytes, for the first instance of a specific
  3159. * substring.
  3160. *
  3161. * The search ends once it finds the requested substring, or a null terminator
  3162. * byte to end the string, or `maxlen` bytes have been examined. It is
  3163. * possible to use this function on a string without a null terminator.
  3164. *
  3165. * Note that this looks for strings of _bytes_, not _characters_, so it's
  3166. * legal to search for malformed and incomplete UTF-8 sequences.
  3167. *
  3168. * \param haystack the string to search. Must not be NULL.
  3169. * \param needle the string to search for. Must not be NULL.
  3170. * \param maxlen the maximum number of bytes to search in `haystack`.
  3171. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3172. * if not found.
  3173. *
  3174. * \threadsafety It is safe to call this function from any thread.
  3175. *
  3176. * \since This function is available since SDL 3.2.0.
  3177. */
  3178. extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  3179. /**
  3180. * Search a UTF-8 string for the first instance of a specific substring,
  3181. * case-insensitively.
  3182. *
  3183. * This will work with Unicode strings, using a technique called
  3184. * "case-folding" to handle the vast majority of case-sensitive human
  3185. * languages regardless of system locale. It can deal with expanding values: a
  3186. * German Eszett character can compare against two ASCII 's' chars and be
  3187. * considered a match, for example. A notable exception: it does not handle
  3188. * the Turkish 'i' character; human language is complicated!
  3189. *
  3190. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3191. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3192. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3193. * CHARACTER), which is to say two strings of random bits may turn out to
  3194. * match if they convert to the same amount of replacement characters.
  3195. *
  3196. * \param haystack the string to search. Must not be NULL.
  3197. * \param needle the string to search for. Must not be NULL.
  3198. * \returns a pointer to the first instance of `needle` in the string, or NULL
  3199. * if not found.
  3200. *
  3201. * \threadsafety It is safe to call this function from any thread.
  3202. *
  3203. * \since This function is available since SDL 3.2.0.
  3204. */
  3205. extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  3206. /**
  3207. * This works exactly like strtok_r() but doesn't require access to a C
  3208. * runtime.
  3209. *
  3210. * Break a string up into a series of tokens.
  3211. *
  3212. * To start tokenizing a new string, `str` should be the non-NULL address of
  3213. * the string to start tokenizing. Future calls to get the next token from the
  3214. * same string should specify a NULL.
  3215. *
  3216. * Note that this function will overwrite pieces of `str` with null chars to
  3217. * split it into tokens. This function cannot be used with const/read-only
  3218. * strings!
  3219. *
  3220. * `saveptr` just needs to point to a `char *` that can be overwritten; SDL
  3221. * will use this to save tokenizing state between calls. It is initialized if
  3222. * `str` is non-NULL, and used to resume tokenizing when `str` is NULL.
  3223. *
  3224. * \param str the string to tokenize, or NULL to continue tokenizing.
  3225. * \param delim the delimiter string that separates tokens.
  3226. * \param saveptr pointer to a char *, used for ongoing state.
  3227. * \returns A pointer to the next token, or NULL if no tokens remain.
  3228. *
  3229. * \threadsafety It is safe to call this function from any thread.
  3230. *
  3231. * \since This function is available since SDL 3.2.0.
  3232. */
  3233. extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *str, const char *delim, char **saveptr);
  3234. /**
  3235. * Count the number of codepoints in a UTF-8 string.
  3236. *
  3237. * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
  3238. * terminator.
  3239. *
  3240. * If you need to count the bytes in a string instead, consider using
  3241. * SDL_strlen().
  3242. *
  3243. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3244. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3245. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3246. * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
  3247. * count by several replacement characters.
  3248. *
  3249. * \param str The null-terminated UTF-8 string to read. Must not be NULL.
  3250. * \returns The length (in codepoints, excluding the null terminator) of
  3251. * `src`.
  3252. *
  3253. * \threadsafety It is safe to call this function from any thread.
  3254. *
  3255. * \since This function is available since SDL 3.2.0.
  3256. *
  3257. * \sa SDL_utf8strnlen
  3258. * \sa SDL_strlen
  3259. */
  3260. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  3261. /**
  3262. * Count the number of codepoints in a UTF-8 string, up to n bytes.
  3263. *
  3264. * Counts the _codepoints_, not _bytes_, in `str`, excluding the null
  3265. * terminator.
  3266. *
  3267. * If you need to count the bytes in a string instead, consider using
  3268. * SDL_strnlen().
  3269. *
  3270. * The counting stops at `bytes` bytes (not codepoints!). This seems
  3271. * counterintuitive, but makes it easy to express the total size of the
  3272. * string's buffer.
  3273. *
  3274. * Since this handles Unicode, it expects the strings to be well-formed UTF-8
  3275. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3276. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3277. * CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the
  3278. * count by several replacement characters.
  3279. *
  3280. * \param str The null-terminated UTF-8 string to read. Must not be NULL.
  3281. * \param bytes The maximum amount of bytes to count.
  3282. * \returns The length (in codepoints, excluding the null terminator) of `src`
  3283. * but never more than `maxlen`.
  3284. *
  3285. * \threadsafety It is safe to call this function from any thread.
  3286. *
  3287. * \since This function is available since SDL 3.2.0.
  3288. *
  3289. * \sa SDL_utf8strlen
  3290. * \sa SDL_strnlen
  3291. */
  3292. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  3293. /**
  3294. * Convert an integer into a string.
  3295. *
  3296. * This requires a radix to specified for string format. Specifying 10
  3297. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3298. * to 36.
  3299. *
  3300. * Note that this function will overflow a buffer if `str` is not large enough
  3301. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3302. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3303. * much more space than you expect to use (and don't forget possible negative
  3304. * signs, null terminator bytes, etc).
  3305. *
  3306. * \param value the integer to convert.
  3307. * \param str the buffer to write the string into.
  3308. * \param radix the radix to use for string generation.
  3309. * \returns `str`.
  3310. *
  3311. * \threadsafety It is safe to call this function from any thread.
  3312. *
  3313. * \since This function is available since SDL 3.2.0.
  3314. *
  3315. * \sa SDL_uitoa
  3316. * \sa SDL_ltoa
  3317. * \sa SDL_lltoa
  3318. */
  3319. extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
  3320. /**
  3321. * Convert an unsigned integer into a string.
  3322. *
  3323. * This requires a radix to specified for string format. Specifying 10
  3324. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3325. * to 36.
  3326. *
  3327. * Note that this function will overflow a buffer if `str` is not large enough
  3328. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3329. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3330. * much more space than you expect to use (and don't forget null terminator
  3331. * bytes, etc).
  3332. *
  3333. * \param value the unsigned integer to convert.
  3334. * \param str the buffer to write the string into.
  3335. * \param radix the radix to use for string generation.
  3336. * \returns `str`.
  3337. *
  3338. * \threadsafety It is safe to call this function from any thread.
  3339. *
  3340. * \since This function is available since SDL 3.2.0.
  3341. *
  3342. * \sa SDL_itoa
  3343. * \sa SDL_ultoa
  3344. * \sa SDL_ulltoa
  3345. */
  3346. extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  3347. /**
  3348. * Convert a long integer into a string.
  3349. *
  3350. * This requires a radix to specified for string format. Specifying 10
  3351. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3352. * to 36.
  3353. *
  3354. * Note that this function will overflow a buffer if `str` is not large enough
  3355. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3356. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3357. * much more space than you expect to use (and don't forget possible negative
  3358. * signs, null terminator bytes, etc).
  3359. *
  3360. * \param value the long integer to convert.
  3361. * \param str the buffer to write the string into.
  3362. * \param radix the radix to use for string generation.
  3363. * \returns `str`.
  3364. *
  3365. * \threadsafety It is safe to call this function from any thread.
  3366. *
  3367. * \since This function is available since SDL 3.2.0.
  3368. *
  3369. * \sa SDL_ultoa
  3370. * \sa SDL_itoa
  3371. * \sa SDL_lltoa
  3372. */
  3373. extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
  3374. /**
  3375. * Convert an unsigned long integer into a string.
  3376. *
  3377. * This requires a radix to specified for string format. Specifying 10
  3378. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3379. * to 36.
  3380. *
  3381. * Note that this function will overflow a buffer if `str` is not large enough
  3382. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3383. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3384. * much more space than you expect to use (and don't forget null terminator
  3385. * bytes, etc).
  3386. *
  3387. * \param value the unsigned long integer to convert.
  3388. * \param str the buffer to write the string into.
  3389. * \param radix the radix to use for string generation.
  3390. * \returns `str`.
  3391. *
  3392. * \threadsafety It is safe to call this function from any thread.
  3393. *
  3394. * \since This function is available since SDL 3.2.0.
  3395. *
  3396. * \sa SDL_ltoa
  3397. * \sa SDL_uitoa
  3398. * \sa SDL_ulltoa
  3399. */
  3400. extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  3401. #ifndef SDL_NOLONGLONG
  3402. /**
  3403. * Convert a long long integer into a string.
  3404. *
  3405. * This requires a radix to specified for string format. Specifying 10
  3406. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3407. * to 36.
  3408. *
  3409. * Note that this function will overflow a buffer if `str` is not large enough
  3410. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3411. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3412. * much more space than you expect to use (and don't forget possible negative
  3413. * signs, null terminator bytes, etc).
  3414. *
  3415. * \param value the long long integer to convert.
  3416. * \param str the buffer to write the string into.
  3417. * \param radix the radix to use for string generation.
  3418. * \returns `str`.
  3419. *
  3420. * \threadsafety It is safe to call this function from any thread.
  3421. *
  3422. * \since This function is available since SDL 3.2.0.
  3423. *
  3424. * \sa SDL_ulltoa
  3425. * \sa SDL_itoa
  3426. * \sa SDL_ltoa
  3427. */
  3428. extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
  3429. /**
  3430. * Convert an unsigned long long integer into a string.
  3431. *
  3432. * This requires a radix to specified for string format. Specifying 10
  3433. * produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2
  3434. * to 36.
  3435. *
  3436. * Note that this function will overflow a buffer if `str` is not large enough
  3437. * to hold the output! It may be safer to use SDL_snprintf to clamp output, or
  3438. * SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate
  3439. * much more space than you expect to use (and don't forget null terminator
  3440. * bytes, etc).
  3441. *
  3442. * \param value the unsigned long long integer to convert.
  3443. * \param str the buffer to write the string into.
  3444. * \param radix the radix to use for string generation.
  3445. * \returns `str`.
  3446. *
  3447. * \threadsafety It is safe to call this function from any thread.
  3448. *
  3449. * \since This function is available since SDL 3.2.0.
  3450. *
  3451. * \sa SDL_lltoa
  3452. * \sa SDL_uitoa
  3453. * \sa SDL_ultoa
  3454. */
  3455. extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
  3456. #endif
  3457. /**
  3458. * Parse an `int` from a string.
  3459. *
  3460. * The result of calling `SDL_atoi(str)` is equivalent to
  3461. * `(int)SDL_strtol(str, NULL, 10)`.
  3462. *
  3463. * \param str The null-terminated string to read. Must not be NULL.
  3464. * \returns the parsed `int`.
  3465. *
  3466. * \threadsafety It is safe to call this function from any thread.
  3467. *
  3468. * \since This function is available since SDL 3.2.0.
  3469. *
  3470. * \sa SDL_atof
  3471. * \sa SDL_strtol
  3472. * \sa SDL_strtoul
  3473. * \sa SDL_strtoll
  3474. * \sa SDL_strtoull
  3475. * \sa SDL_strtod
  3476. * \sa SDL_itoa
  3477. */
  3478. extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
  3479. /**
  3480. * Parse a `double` from a string.
  3481. *
  3482. * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
  3483. * NULL)`.
  3484. *
  3485. * \param str The null-terminated string to read. Must not be NULL.
  3486. * \returns the parsed `double`.
  3487. *
  3488. * \threadsafety It is safe to call this function from any thread.
  3489. *
  3490. * \since This function is available since SDL 3.2.0.
  3491. *
  3492. * \sa SDL_atoi
  3493. * \sa SDL_strtol
  3494. * \sa SDL_strtoul
  3495. * \sa SDL_strtoll
  3496. * \sa SDL_strtoull
  3497. * \sa SDL_strtod
  3498. */
  3499. extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
  3500. /**
  3501. * Parse a `long` from a string.
  3502. *
  3503. * If `str` starts with whitespace, then those whitespace characters are
  3504. * skipped before attempting to parse the number.
  3505. *
  3506. * If the parsed number does not fit inside a `long`, the result is clamped to
  3507. * the minimum and maximum representable `long` values.
  3508. *
  3509. * \param str The null-terminated string to read. Must not be NULL.
  3510. * \param endp If not NULL, the address of the first invalid character (i.e.
  3511. * the next character after the parsed number) will be written to
  3512. * this pointer.
  3513. * \param base The base of the integer to read. Supported values are 0 and 2
  3514. * to 36 inclusive. If 0, the base will be inferred from the
  3515. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3516. * otherwise).
  3517. * \returns the parsed `long`, or 0 if no number could be parsed.
  3518. *
  3519. * \threadsafety It is safe to call this function from any thread.
  3520. *
  3521. * \since This function is available since SDL 3.2.0.
  3522. *
  3523. * \sa SDL_atoi
  3524. * \sa SDL_atof
  3525. * \sa SDL_strtoul
  3526. * \sa SDL_strtoll
  3527. * \sa SDL_strtoull
  3528. * \sa SDL_strtod
  3529. * \sa SDL_ltoa
  3530. * \sa SDL_wcstol
  3531. */
  3532. extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  3533. /**
  3534. * Parse an `unsigned long` from a string.
  3535. *
  3536. * If `str` starts with whitespace, then those whitespace characters are
  3537. * skipped before attempting to parse the number.
  3538. *
  3539. * If the parsed number does not fit inside an `unsigned long`, the result is
  3540. * clamped to the maximum representable `unsigned long` value.
  3541. *
  3542. * \param str The null-terminated string to read. Must not be NULL.
  3543. * \param endp If not NULL, the address of the first invalid character (i.e.
  3544. * the next character after the parsed number) will be written to
  3545. * this pointer.
  3546. * \param base The base of the integer to read. Supported values are 0 and 2
  3547. * to 36 inclusive. If 0, the base will be inferred from the
  3548. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3549. * otherwise).
  3550. * \returns the parsed `unsigned long`, or 0 if no number could be parsed.
  3551. *
  3552. * \threadsafety It is safe to call this function from any thread.
  3553. *
  3554. * \since This function is available since SDL 3.2.0.
  3555. *
  3556. * \sa SDL_atoi
  3557. * \sa SDL_atof
  3558. * \sa SDL_strtol
  3559. * \sa SDL_strtoll
  3560. * \sa SDL_strtoull
  3561. * \sa SDL_strtod
  3562. * \sa SDL_ultoa
  3563. */
  3564. extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  3565. #ifndef SDL_NOLONGLONG
  3566. /**
  3567. * Parse a `long long` from a string.
  3568. *
  3569. * If `str` starts with whitespace, then those whitespace characters are
  3570. * skipped before attempting to parse the number.
  3571. *
  3572. * If the parsed number does not fit inside a `long long`, the result is
  3573. * clamped to the minimum and maximum representable `long long` values.
  3574. *
  3575. * \param str The null-terminated string to read. Must not be NULL.
  3576. * \param endp If not NULL, the address of the first invalid character (i.e.
  3577. * the next character after the parsed number) will be written to
  3578. * this pointer.
  3579. * \param base The base of the integer to read. Supported values are 0 and 2
  3580. * to 36 inclusive. If 0, the base will be inferred from the
  3581. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3582. * otherwise).
  3583. * \returns the parsed `long long`, or 0 if no number could be parsed.
  3584. *
  3585. * \threadsafety It is safe to call this function from any thread.
  3586. *
  3587. * \since This function is available since SDL 3.2.0.
  3588. *
  3589. * \sa SDL_atoi
  3590. * \sa SDL_atof
  3591. * \sa SDL_strtol
  3592. * \sa SDL_strtoul
  3593. * \sa SDL_strtoull
  3594. * \sa SDL_strtod
  3595. * \sa SDL_lltoa
  3596. */
  3597. extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  3598. /**
  3599. * Parse an `unsigned long long` from a string.
  3600. *
  3601. * If `str` starts with whitespace, then those whitespace characters are
  3602. * skipped before attempting to parse the number.
  3603. *
  3604. * If the parsed number does not fit inside an `unsigned long long`, the
  3605. * result is clamped to the maximum representable `unsigned long long` value.
  3606. *
  3607. * \param str The null-terminated string to read. Must not be NULL.
  3608. * \param endp If not NULL, the address of the first invalid character (i.e.
  3609. * the next character after the parsed number) will be written to
  3610. * this pointer.
  3611. * \param base The base of the integer to read. Supported values are 0 and 2
  3612. * to 36 inclusive. If 0, the base will be inferred from the
  3613. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  3614. * otherwise).
  3615. * \returns the parsed `unsigned long long`, or 0 if no number could be
  3616. * parsed.
  3617. *
  3618. * \threadsafety It is safe to call this function from any thread.
  3619. *
  3620. * \since This function is available since SDL 3.2.0.
  3621. *
  3622. * \sa SDL_atoi
  3623. * \sa SDL_atof
  3624. * \sa SDL_strtol
  3625. * \sa SDL_strtoll
  3626. * \sa SDL_strtoul
  3627. * \sa SDL_strtod
  3628. * \sa SDL_ulltoa
  3629. */
  3630. extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  3631. #endif
  3632. /**
  3633. * Parse a `double` from a string.
  3634. *
  3635. * This function makes fewer guarantees than the C runtime `strtod`:
  3636. *
  3637. * - Only decimal notation is guaranteed to be supported. The handling of
  3638. * scientific and hexadecimal notation is unspecified.
  3639. * - Whether or not INF and NAN can be parsed is unspecified.
  3640. * - The precision of the result is unspecified.
  3641. *
  3642. * \param str the null-terminated string to read. Must not be NULL.
  3643. * \param endp if not NULL, the address of the first invalid character (i.e.
  3644. * the next character after the parsed number) will be written to
  3645. * this pointer.
  3646. * \returns the parsed `double`, or 0 if no number could be parsed.
  3647. *
  3648. * \threadsafety It is safe to call this function from any thread.
  3649. *
  3650. * \since This function is available since SDL 3.2.0.
  3651. *
  3652. * \sa SDL_atoi
  3653. * \sa SDL_atof
  3654. * \sa SDL_strtol
  3655. * \sa SDL_strtoll
  3656. * \sa SDL_strtoul
  3657. * \sa SDL_strtoull
  3658. */
  3659. extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  3660. /**
  3661. * Compare two null-terminated UTF-8 strings.
  3662. *
  3663. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  3664. * since effectively this function just compares bytes until it hits a
  3665. * null-terminating character. Also due to the nature of UTF-8, this can be
  3666. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  3667. *
  3668. * \param str1 the first string to compare. NULL is not permitted!
  3669. * \param str2 the second string to compare. NULL is not permitted!
  3670. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3671. * str1 is "greater than" str2, and zero if the strings match
  3672. * exactly.
  3673. *
  3674. * \threadsafety It is safe to call this function from any thread.
  3675. *
  3676. * \since This function is available since SDL 3.2.0.
  3677. */
  3678. extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  3679. /**
  3680. * Compare two UTF-8 strings up to a number of bytes.
  3681. *
  3682. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  3683. * since effectively this function just compares bytes until it hits a
  3684. * null-terminating character. Also due to the nature of UTF-8, this can be
  3685. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  3686. *
  3687. * Note that while this function is intended to be used with UTF-8, it is
  3688. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  3689. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  3690. * compare a portion of the final character.
  3691. *
  3692. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  3693. * match to this number of bytes (or both have matched to a null-terminator
  3694. * character before this number of bytes), they will be considered equal.
  3695. *
  3696. * \param str1 the first string to compare. NULL is not permitted!
  3697. * \param str2 the second string to compare. NULL is not permitted!
  3698. * \param maxlen the maximum number of _bytes_ to compare.
  3699. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3700. * str1 is "greater than" str2, and zero if the strings match
  3701. * exactly.
  3702. *
  3703. * \threadsafety It is safe to call this function from any thread.
  3704. *
  3705. * \since This function is available since SDL 3.2.0.
  3706. */
  3707. extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  3708. /**
  3709. * Compare two null-terminated UTF-8 strings, case-insensitively.
  3710. *
  3711. * This will work with Unicode strings, using a technique called
  3712. * "case-folding" to handle the vast majority of case-sensitive human
  3713. * languages regardless of system locale. It can deal with expanding values: a
  3714. * German Eszett character can compare against two ASCII 's' chars and be
  3715. * considered a match, for example. A notable exception: it does not handle
  3716. * the Turkish 'i' character; human language is complicated!
  3717. *
  3718. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  3719. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3720. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3721. * CHARACTER), which is to say two strings of random bits may turn out to
  3722. * match if they convert to the same amount of replacement characters.
  3723. *
  3724. * \param str1 the first string to compare. NULL is not permitted!
  3725. * \param str2 the second string to compare. NULL is not permitted!
  3726. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3727. * str1 is "greater than" str2, and zero if the strings match
  3728. * exactly.
  3729. *
  3730. * \threadsafety It is safe to call this function from any thread.
  3731. *
  3732. * \since This function is available since SDL 3.2.0.
  3733. */
  3734. extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  3735. /**
  3736. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  3737. *
  3738. * This will work with Unicode strings, using a technique called
  3739. * "case-folding" to handle the vast majority of case-sensitive human
  3740. * languages regardless of system locale. It can deal with expanding values: a
  3741. * German Eszett character can compare against two ASCII 's' chars and be
  3742. * considered a match, for example. A notable exception: it does not handle
  3743. * the Turkish 'i' character; human language is complicated!
  3744. *
  3745. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  3746. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  3747. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  3748. * CHARACTER), which is to say two strings of random bits may turn out to
  3749. * match if they convert to the same amount of replacement characters.
  3750. *
  3751. * Note that while this function is intended to be used with UTF-8, `maxlen`
  3752. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  3753. * UTF-8 sequence, it may convert a portion of the final character to one or
  3754. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  3755. * a buffer.
  3756. *
  3757. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  3758. * match to this number of bytes (or both have matched to a null-terminator
  3759. * character before this number of bytes), they will be considered equal.
  3760. *
  3761. * \param str1 the first string to compare. NULL is not permitted!
  3762. * \param str2 the second string to compare. NULL is not permitted!
  3763. * \param maxlen the maximum number of bytes to compare.
  3764. * \returns less than zero if str1 is "less than" str2, greater than zero if
  3765. * str1 is "greater than" str2, and zero if the strings match
  3766. * exactly.
  3767. *
  3768. * \threadsafety It is safe to call this function from any thread.
  3769. *
  3770. * \since This function is available since SDL 3.2.0.
  3771. */
  3772. extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  3773. /**
  3774. * Searches a string for the first occurrence of any character contained in a
  3775. * breakset, and returns a pointer from the string to that character.
  3776. *
  3777. * \param str The null-terminated string to be searched. Must not be NULL, and
  3778. * must not overlap with `breakset`.
  3779. * \param breakset A null-terminated string containing the list of characters
  3780. * to look for. Must not be NULL, and must not overlap with
  3781. * `str`.
  3782. * \returns A pointer to the location, in str, of the first occurrence of a
  3783. * character present in the breakset, or NULL if none is found.
  3784. *
  3785. * \threadsafety It is safe to call this function from any thread.
  3786. *
  3787. * \since This function is available since SDL 3.2.0.
  3788. */
  3789. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
  3790. /**
  3791. * The Unicode REPLACEMENT CHARACTER codepoint.
  3792. *
  3793. * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they
  3794. * encounter a UTF-8 string with encoding errors.
  3795. *
  3796. * This tends to render as something like a question mark in most places.
  3797. *
  3798. * \since This macro is available since SDL 3.2.0.
  3799. *
  3800. * \sa SDL_StepBackUTF8
  3801. * \sa SDL_StepUTF8
  3802. */
  3803. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  3804. /**
  3805. * Decode a UTF-8 string, one Unicode codepoint at a time.
  3806. *
  3807. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  3808. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  3809. *
  3810. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  3811. * be adjusted, as well, subtracting the number of bytes consumed.
  3812. *
  3813. * `pslen` is allowed to be NULL, in which case the string _must_ be
  3814. * NULL-terminated, as the function will blindly read until it sees the NULL
  3815. * char.
  3816. *
  3817. * If `*pslen` is zero, it assumes the end of string is reached and returns a
  3818. * zero codepoint regardless of the contents of the string buffer.
  3819. *
  3820. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  3821. * zero, it will not advance `*pstr` or `*pslen` at all.
  3822. *
  3823. * Generally this function is called in a loop until it returns zero,
  3824. * adjusting its parameters each iteration.
  3825. *
  3826. * If an invalid UTF-8 sequence is encountered, this function returns
  3827. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  3828. * (which is to say, a multibyte sequence might produce several
  3829. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  3830. * UTF-8 sequence).
  3831. *
  3832. * Several things can generate invalid UTF-8 sequences, including overlong
  3833. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  3834. * refer to
  3835. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  3836. * for details.
  3837. *
  3838. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  3839. * \param pslen a pointer to the number of bytes in the string, to be read and
  3840. * adjusted. NULL is allowed.
  3841. * \returns the first Unicode codepoint in the string.
  3842. *
  3843. * \threadsafety It is safe to call this function from any thread.
  3844. *
  3845. * \since This function is available since SDL 3.2.0.
  3846. */
  3847. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  3848. /**
  3849. * Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
  3850. *
  3851. * This will go to the start of the previous Unicode codepoint in the string,
  3852. * move `*pstr` to that location and return that codepoint.
  3853. *
  3854. * If `*pstr` is already at the start of the string), it will not advance
  3855. * `*pstr` at all.
  3856. *
  3857. * Generally this function is called in a loop until it returns zero,
  3858. * adjusting its parameter each iteration.
  3859. *
  3860. * If an invalid UTF-8 sequence is encountered, this function returns
  3861. * SDL_INVALID_UNICODE_CODEPOINT.
  3862. *
  3863. * Several things can generate invalid UTF-8 sequences, including overlong
  3864. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  3865. * refer to
  3866. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  3867. * for details.
  3868. *
  3869. * \param start a pointer to the beginning of the UTF-8 string.
  3870. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  3871. * \returns the previous Unicode codepoint in the string.
  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 Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr);
  3878. /**
  3879. * Convert a single Unicode codepoint to UTF-8.
  3880. *
  3881. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  3882. * function may generate between 1 and 4 bytes of output.
  3883. *
  3884. * This function returns the first byte _after_ the newly-written UTF-8
  3885. * sequence, which is useful for encoding multiple codepoints in a loop, or
  3886. * knowing where to write a NULL-terminator character to end the string (in
  3887. * either case, plan to have a buffer of _more_ than 4 bytes!).
  3888. *
  3889. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  3890. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  3891. * codepoint instead, and not set an error.
  3892. *
  3893. * If `dst` is NULL, this returns NULL immediately without writing to the
  3894. * pointer and without setting an error.
  3895. *
  3896. * \param codepoint a Unicode codepoint to convert to UTF-8.
  3897. * \param dst the location to write the encoded UTF-8. Must point to at least
  3898. * 4 bytes!
  3899. * \returns the first byte past the newly-written UTF-8 sequence.
  3900. *
  3901. * \threadsafety It is safe to call this function from any thread.
  3902. *
  3903. * \since This function is available since SDL 3.2.0.
  3904. */
  3905. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  3906. /**
  3907. * This works exactly like sscanf() but doesn't require access to a C runtime.
  3908. *
  3909. * Scan a string, matching a format string, converting each '%' item and
  3910. * storing it to pointers provided through variable arguments.
  3911. *
  3912. * \param text the string to scan. Must not be NULL.
  3913. * \param fmt a printf-style format string. Must not be NULL.
  3914. * \param ... a list of pointers to values to be filled in with scanned items.
  3915. * \returns the number of items that matched the format string.
  3916. *
  3917. * \threadsafety It is safe to call this function from any thread.
  3918. *
  3919. * \since This function is available since SDL 3.2.0.
  3920. */
  3921. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  3922. /**
  3923. * This works exactly like vsscanf() but doesn't require access to a C
  3924. * runtime.
  3925. *
  3926. * Functions identically to SDL_sscanf(), except it takes a `va_list` instead
  3927. * of using `...` variable arguments.
  3928. *
  3929. * \param text the string to scan. Must not be NULL.
  3930. * \param fmt a printf-style format string. Must not be NULL.
  3931. * \param ap a `va_list` of pointers to values to be filled in with scanned
  3932. * items.
  3933. * \returns the number of items that matched the format string.
  3934. *
  3935. * \threadsafety It is safe to call this function from any thread.
  3936. *
  3937. * \since This function is available since SDL 3.2.0.
  3938. */
  3939. 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);
  3940. /**
  3941. * This works exactly like snprintf() but doesn't require access to a C
  3942. * runtime.
  3943. *
  3944. * Format a string of up to `maxlen`-1 bytes, converting each '%' item with
  3945. * values provided through variable arguments.
  3946. *
  3947. * While some C runtimes differ on how to deal with too-large strings, this
  3948. * function null-terminates the output, by treating the null-terminator as
  3949. * part of the `maxlen` count. Note that if `maxlen` is zero, however, no
  3950. * bytes will be written at all.
  3951. *
  3952. * This function returns the number of _bytes_ (not _characters_) that should
  3953. * be written, excluding the null-terminator character. If this returns a
  3954. * number >= `maxlen`, it means the output string was truncated. A negative
  3955. * return value means an error occurred.
  3956. *
  3957. * Referencing the output string's pointer with a format item is undefined
  3958. * behavior.
  3959. *
  3960. * \param text the buffer to write the string into. Must not be NULL.
  3961. * \param maxlen the maximum bytes to write, including the null-terminator.
  3962. * \param fmt a printf-style format string. Must not be NULL.
  3963. * \param ... a list of values to be used with the format string.
  3964. * \returns the number of bytes that should be written, not counting the
  3965. * null-terminator char, or a negative value on error.
  3966. *
  3967. * \threadsafety It is safe to call this function from any thread.
  3968. *
  3969. * \since This function is available since SDL 3.2.0.
  3970. */
  3971. 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);
  3972. /**
  3973. * This works exactly like swprintf() but doesn't require access to a C
  3974. * runtime.
  3975. *
  3976. * Format a wide string of up to `maxlen`-1 wchar_t values, converting each
  3977. * '%' item with values provided through variable arguments.
  3978. *
  3979. * While some C runtimes differ on how to deal with too-large strings, this
  3980. * function null-terminates the output, by treating the null-terminator as
  3981. * part of the `maxlen` count. Note that if `maxlen` is zero, however, no wide
  3982. * characters will be written at all.
  3983. *
  3984. * This function returns the number of _wide characters_ (not _codepoints_)
  3985. * that should be written, excluding the null-terminator character. If this
  3986. * returns a number >= `maxlen`, it means the output string was truncated. A
  3987. * negative return value means an error occurred.
  3988. *
  3989. * Referencing the output string's pointer with a format item is undefined
  3990. * behavior.
  3991. *
  3992. * \param text the buffer to write the wide string into. Must not be NULL.
  3993. * \param maxlen the maximum wchar_t values to write, including the
  3994. * null-terminator.
  3995. * \param fmt a printf-style format string. Must not be NULL.
  3996. * \param ... a list of values to be used with the format string.
  3997. * \returns the number of wide characters that should be written, not counting
  3998. * the null-terminator char, or a negative value on error.
  3999. *
  4000. * \threadsafety It is safe to call this function from any thread.
  4001. *
  4002. * \since This function is available since SDL 3.2.0.
  4003. */
  4004. 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);
  4005. /**
  4006. * This works exactly like vsnprintf() but doesn't require access to a C
  4007. * runtime.
  4008. *
  4009. * Functions identically to SDL_snprintf(), except it takes a `va_list`
  4010. * instead of using `...` variable arguments.
  4011. *
  4012. * \param text the buffer to write the string into. Must not be NULL.
  4013. * \param maxlen the maximum bytes to write, including the null-terminator.
  4014. * \param fmt a printf-style format string. Must not be NULL.
  4015. * \param ap a `va_list` values to be used with the format string.
  4016. * \returns the number of bytes that should be written, not counting the
  4017. * null-terminator char, or a negative value on error.
  4018. *
  4019. * \threadsafety It is safe to call this function from any thread.
  4020. *
  4021. * \since This function is available since SDL 3.2.0.
  4022. */
  4023. 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);
  4024. /**
  4025. * This works exactly like vswprintf() but doesn't require access to a C
  4026. * runtime.
  4027. *
  4028. * Functions identically to SDL_swprintf(), except it takes a `va_list`
  4029. * instead of using `...` variable arguments.
  4030. *
  4031. * \param text the buffer to write the string into. Must not be NULL.
  4032. * \param maxlen the maximum wide characters to write, including the
  4033. * null-terminator.
  4034. * \param fmt a printf-style format wide string. Must not be NULL.
  4035. * \param ap a `va_list` values to be used with the format string.
  4036. * \returns the number of wide characters that should be written, not counting
  4037. * the null-terminator char, or a negative value on error.
  4038. *
  4039. * \threadsafety It is safe to call this function from any thread.
  4040. *
  4041. * \since This function is available since SDL 3.2.0.
  4042. */
  4043. 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);
  4044. /**
  4045. * This works exactly like asprintf() but doesn't require access to a C
  4046. * runtime.
  4047. *
  4048. * Functions identically to SDL_snprintf(), except it allocates a buffer large
  4049. * enough to hold the output string on behalf of the caller.
  4050. *
  4051. * On success, this function returns the number of bytes (not characters)
  4052. * comprising the output string, not counting the null-terminator character,
  4053. * and sets `*strp` to the newly-allocated string.
  4054. *
  4055. * On error, this function returns a negative number, and the value of `*strp`
  4056. * is undefined.
  4057. *
  4058. * The returned string is owned by the caller, and should be passed to
  4059. * SDL_free when no longer needed.
  4060. *
  4061. * \param strp on output, is set to the new string. Must not be NULL.
  4062. * \param fmt a printf-style format string. Must not be NULL.
  4063. * \param ... a list of values to be used with the format string.
  4064. * \returns the number of bytes in the newly-allocated string, not counting
  4065. * the null-terminator char, or a negative value on error.
  4066. *
  4067. * \threadsafety It is safe to call this function from any thread.
  4068. *
  4069. * \since This function is available since SDL 3.2.0.
  4070. */
  4071. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  4072. /**
  4073. * This works exactly like vasprintf() but doesn't require access to a C
  4074. * runtime.
  4075. *
  4076. * Functions identically to SDL_asprintf(), except it takes a `va_list`
  4077. * instead of using `...` variable arguments.
  4078. *
  4079. * \param strp on output, is set to the new string. Must not be NULL.
  4080. * \param fmt a printf-style format string. Must not be NULL.
  4081. * \param ap a `va_list` values to be used with the format string.
  4082. * \returns the number of bytes in the newly-allocated string, not counting
  4083. * the null-terminator char, or a negative value on error.
  4084. *
  4085. * \threadsafety It is safe to call this function from any thread.
  4086. *
  4087. * \since This function is available since SDL 3.2.0.
  4088. */
  4089. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  4090. /**
  4091. * Seeds the pseudo-random number generator.
  4092. *
  4093. * Reusing the seed number will cause SDL_rand() to repeat the same stream of
  4094. * 'random' numbers.
  4095. *
  4096. * \param seed the value to use as a random number seed, or 0 to use
  4097. * SDL_GetPerformanceCounter().
  4098. *
  4099. * \threadsafety This should be called on the same thread that calls
  4100. * SDL_rand()
  4101. *
  4102. * \since This function is available since SDL 3.2.0.
  4103. *
  4104. * \sa SDL_rand
  4105. * \sa SDL_rand_bits
  4106. * \sa SDL_randf
  4107. */
  4108. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  4109. /**
  4110. * Generate a pseudo-random number less than n for positive n
  4111. *
  4112. * The method used is faster and of better quality than `rand() % n`. Odds are
  4113. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  4114. * much worse as n gets bigger.
  4115. *
  4116. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  4117. * 1..6
  4118. *
  4119. * If you want to generate a pseudo-random number in the full range of Sint32,
  4120. * you should use: (Sint32)SDL_rand_bits()
  4121. *
  4122. * If you want reproducible output, be sure to initialize with SDL_srand()
  4123. * first.
  4124. *
  4125. * There are no guarantees as to the quality of the random sequence produced,
  4126. * and this should not be used for security (cryptography, passwords) or where
  4127. * money is on the line (loot-boxes, casinos). There are many random number
  4128. * libraries available with different characteristics and you should pick one
  4129. * of those to meet any serious needs.
  4130. *
  4131. * \param n the number of possible outcomes. n must be positive.
  4132. * \returns a random value in the range of [0 .. n-1].
  4133. *
  4134. * \threadsafety All calls should be made from a single thread
  4135. *
  4136. * \since This function is available since SDL 3.2.0.
  4137. *
  4138. * \sa SDL_srand
  4139. * \sa SDL_randf
  4140. */
  4141. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  4142. /**
  4143. * Generate a uniform pseudo-random floating point number less than 1.0
  4144. *
  4145. * If you want reproducible output, be sure to initialize with SDL_srand()
  4146. * first.
  4147. *
  4148. * There are no guarantees as to the quality of the random sequence produced,
  4149. * and this should not be used for security (cryptography, passwords) or where
  4150. * money is on the line (loot-boxes, casinos). There are many random number
  4151. * libraries available with different characteristics and you should pick one
  4152. * of those to meet any serious needs.
  4153. *
  4154. * \returns a random value in the range of [0.0, 1.0).
  4155. *
  4156. * \threadsafety All calls should be made from a single thread
  4157. *
  4158. * \since This function is available since SDL 3.2.0.
  4159. *
  4160. * \sa SDL_srand
  4161. * \sa SDL_rand
  4162. */
  4163. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  4164. /**
  4165. * Generate 32 pseudo-random bits.
  4166. *
  4167. * You likely want to use SDL_rand() to get a pseudo-random number instead.
  4168. *
  4169. * There are no guarantees as to the quality of the random sequence produced,
  4170. * and this should not be used for security (cryptography, passwords) or where
  4171. * money is on the line (loot-boxes, casinos). There are many random number
  4172. * libraries available with different characteristics and you should pick one
  4173. * of those to meet any serious needs.
  4174. *
  4175. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  4176. *
  4177. * \threadsafety All calls should be made from a single thread
  4178. *
  4179. * \since This function is available since SDL 3.2.0.
  4180. *
  4181. * \sa SDL_rand
  4182. * \sa SDL_randf
  4183. * \sa SDL_srand
  4184. */
  4185. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  4186. /**
  4187. * Generate a pseudo-random number less than n for positive n
  4188. *
  4189. * The method used is faster and of better quality than `rand() % n`. Odds are
  4190. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  4191. * much worse as n gets bigger.
  4192. *
  4193. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  4194. * 0..5 to 1..6
  4195. *
  4196. * If you want to generate a pseudo-random number in the full range of Sint32,
  4197. * you should use: (Sint32)SDL_rand_bits_r(state)
  4198. *
  4199. * There are no guarantees as to the quality of the random sequence produced,
  4200. * and this should not be used for security (cryptography, passwords) or where
  4201. * money is on the line (loot-boxes, casinos). There are many random number
  4202. * libraries available with different characteristics and you should pick one
  4203. * of those to meet any serious needs.
  4204. *
  4205. * \param state a pointer to the current random number state, this may not be
  4206. * NULL.
  4207. * \param n the number of possible outcomes. n must be positive.
  4208. * \returns a random value in the range of [0 .. n-1].
  4209. *
  4210. * \threadsafety This function is thread-safe, as long as the state pointer
  4211. * isn't shared between threads.
  4212. *
  4213. * \since This function is available since SDL 3.2.0.
  4214. *
  4215. * \sa SDL_rand
  4216. * \sa SDL_rand_bits_r
  4217. * \sa SDL_randf_r
  4218. */
  4219. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  4220. /**
  4221. * Generate a uniform pseudo-random floating point number less than 1.0
  4222. *
  4223. * There are no guarantees as to the quality of the random sequence produced,
  4224. * and this should not be used for security (cryptography, passwords) or where
  4225. * money is on the line (loot-boxes, casinos). There are many random number
  4226. * libraries available with different characteristics and you should pick one
  4227. * of those to meet any serious needs.
  4228. *
  4229. * \param state a pointer to the current random number state, this may not be
  4230. * NULL.
  4231. * \returns a random value in the range of [0.0, 1.0).
  4232. *
  4233. * \threadsafety This function is thread-safe, as long as the state pointer
  4234. * isn't shared between threads.
  4235. *
  4236. * \since This function is available since SDL 3.2.0.
  4237. *
  4238. * \sa SDL_rand_bits_r
  4239. * \sa SDL_rand_r
  4240. * \sa SDL_randf
  4241. */
  4242. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  4243. /**
  4244. * Generate 32 pseudo-random bits.
  4245. *
  4246. * You likely want to use SDL_rand_r() to get a pseudo-random number instead.
  4247. *
  4248. * There are no guarantees as to the quality of the random sequence produced,
  4249. * and this should not be used for security (cryptography, passwords) or where
  4250. * money is on the line (loot-boxes, casinos). There are many random number
  4251. * libraries available with different characteristics and you should pick one
  4252. * of those to meet any serious needs.
  4253. *
  4254. * \param state a pointer to the current random number state, this may not be
  4255. * NULL.
  4256. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  4257. *
  4258. * \threadsafety This function is thread-safe, as long as the state pointer
  4259. * isn't shared between threads.
  4260. *
  4261. * \since This function is available since SDL 3.2.0.
  4262. *
  4263. * \sa SDL_rand_r
  4264. * \sa SDL_randf_r
  4265. */
  4266. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  4267. #ifndef SDL_PI_D
  4268. /**
  4269. * The value of Pi, as a double-precision floating point literal.
  4270. *
  4271. * \since This macro is available since SDL 3.2.0.
  4272. *
  4273. * \sa SDL_PI_F
  4274. */
  4275. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  4276. #endif
  4277. #ifndef SDL_PI_F
  4278. /**
  4279. * The value of Pi, as a single-precision floating point literal.
  4280. *
  4281. * \since This macro is available since SDL 3.2.0.
  4282. *
  4283. * \sa SDL_PI_D
  4284. */
  4285. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  4286. #endif
  4287. /**
  4288. * Compute the arc cosine of `x`.
  4289. *
  4290. * The definition of `y = acos(x)` is `x = cos(y)`.
  4291. *
  4292. * Domain: `-1 <= x <= 1`
  4293. *
  4294. * Range: `0 <= y <= Pi`
  4295. *
  4296. * This function operates on double-precision floating point values, use
  4297. * SDL_acosf for single-precision floats.
  4298. *
  4299. * This function may use a different approximation across different versions,
  4300. * platforms and configurations. i.e, it can return a different value given
  4301. * the same input on different machines or operating systems, or if SDL is
  4302. * updated.
  4303. *
  4304. * \param x floating point value.
  4305. * \returns arc cosine of `x`, in radians.
  4306. *
  4307. * \threadsafety It is safe to call this function from any thread.
  4308. *
  4309. * \since This function is available since SDL 3.2.0.
  4310. *
  4311. * \sa SDL_acosf
  4312. * \sa SDL_asin
  4313. * \sa SDL_cos
  4314. */
  4315. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  4316. /**
  4317. * Compute the arc cosine of `x`.
  4318. *
  4319. * The definition of `y = acos(x)` is `x = cos(y)`.
  4320. *
  4321. * Domain: `-1 <= x <= 1`
  4322. *
  4323. * Range: `0 <= y <= Pi`
  4324. *
  4325. * This function operates on single-precision floating point values, use
  4326. * SDL_acos for double-precision floats.
  4327. *
  4328. * This function may use a different approximation across different versions,
  4329. * platforms and configurations. i.e, it can return a different value given
  4330. * the same input on different machines or operating systems, or if SDL is
  4331. * updated.
  4332. *
  4333. * \param x floating point value.
  4334. * \returns arc cosine of `x`, in radians.
  4335. *
  4336. * \threadsafety It is safe to call this function from any thread.
  4337. *
  4338. * \since This function is available since SDL 3.2.0.
  4339. *
  4340. * \sa SDL_acos
  4341. * \sa SDL_asinf
  4342. * \sa SDL_cosf
  4343. */
  4344. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  4345. /**
  4346. * Compute the arc sine of `x`.
  4347. *
  4348. * The definition of `y = asin(x)` is `x = sin(y)`.
  4349. *
  4350. * Domain: `-1 <= x <= 1`
  4351. *
  4352. * Range: `-Pi/2 <= y <= Pi/2`
  4353. *
  4354. * This function operates on double-precision floating point values, use
  4355. * SDL_asinf for single-precision floats.
  4356. *
  4357. * This function may use a different approximation across different versions,
  4358. * platforms and configurations. i.e, it can return a different value given
  4359. * the same input on different machines or operating systems, or if SDL is
  4360. * updated.
  4361. *
  4362. * \param x floating point value.
  4363. * \returns arc sine of `x`, in radians.
  4364. *
  4365. * \threadsafety It is safe to call this function from any thread.
  4366. *
  4367. * \since This function is available since SDL 3.2.0.
  4368. *
  4369. * \sa SDL_asinf
  4370. * \sa SDL_acos
  4371. * \sa SDL_sin
  4372. */
  4373. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  4374. /**
  4375. * Compute the arc sine of `x`.
  4376. *
  4377. * The definition of `y = asin(x)` is `x = sin(y)`.
  4378. *
  4379. * Domain: `-1 <= x <= 1`
  4380. *
  4381. * Range: `-Pi/2 <= y <= Pi/2`
  4382. *
  4383. * This function operates on single-precision floating point values, use
  4384. * SDL_asin for double-precision floats.
  4385. *
  4386. * This function may use a different approximation across different versions,
  4387. * platforms and configurations. i.e, it can return a different value given
  4388. * the same input on different machines or operating systems, or if SDL is
  4389. * updated.
  4390. *
  4391. * \param x floating point value.
  4392. * \returns arc sine of `x`, in radians.
  4393. *
  4394. * \threadsafety It is safe to call this function from any thread.
  4395. *
  4396. * \since This function is available since SDL 3.2.0.
  4397. *
  4398. * \sa SDL_asin
  4399. * \sa SDL_acosf
  4400. * \sa SDL_sinf
  4401. */
  4402. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  4403. /**
  4404. * Compute the arc tangent of `x`.
  4405. *
  4406. * The definition of `y = atan(x)` is `x = tan(y)`.
  4407. *
  4408. * Domain: `-INF <= x <= INF`
  4409. *
  4410. * Range: `-Pi/2 <= y <= Pi/2`
  4411. *
  4412. * This function operates on double-precision floating point values, use
  4413. * SDL_atanf for single-precision floats.
  4414. *
  4415. * To calculate the arc tangent of y / x, use SDL_atan2.
  4416. *
  4417. * This function may use a different approximation across different versions,
  4418. * platforms and configurations. i.e, it can return a different value given
  4419. * the same input on different machines or operating systems, or if SDL is
  4420. * updated.
  4421. *
  4422. * \param x floating point value.
  4423. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  4424. *
  4425. * \threadsafety It is safe to call this function from any thread.
  4426. *
  4427. * \since This function is available since SDL 3.2.0.
  4428. *
  4429. * \sa SDL_atanf
  4430. * \sa SDL_atan2
  4431. * \sa SDL_tan
  4432. */
  4433. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  4434. /**
  4435. * Compute the arc tangent of `x`.
  4436. *
  4437. * The definition of `y = atan(x)` is `x = tan(y)`.
  4438. *
  4439. * Domain: `-INF <= x <= INF`
  4440. *
  4441. * Range: `-Pi/2 <= y <= Pi/2`
  4442. *
  4443. * This function operates on single-precision floating point values, use
  4444. * SDL_atan for dboule-precision floats.
  4445. *
  4446. * To calculate the arc tangent of y / x, use SDL_atan2f.
  4447. *
  4448. * This function may use a different approximation across different versions,
  4449. * platforms and configurations. i.e, it can return a different value given
  4450. * the same input on different machines or operating systems, or if SDL is
  4451. * updated.
  4452. *
  4453. * \param x floating point value.
  4454. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  4455. *
  4456. * \threadsafety It is safe to call this function from any thread.
  4457. *
  4458. * \since This function is available since SDL 3.2.0.
  4459. *
  4460. * \sa SDL_atan
  4461. * \sa SDL_atan2f
  4462. * \sa SDL_tanf
  4463. */
  4464. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  4465. /**
  4466. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  4467. * the result's quadrant.
  4468. *
  4469. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  4470. * of z is determined based on the signs of x and y.
  4471. *
  4472. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  4473. *
  4474. * Range: `-Pi <= z <= Pi`
  4475. *
  4476. * This function operates on double-precision floating point values, use
  4477. * SDL_atan2f for single-precision floats.
  4478. *
  4479. * To calculate the arc tangent of a single value, use SDL_atan.
  4480. *
  4481. * This function may use a different approximation across different versions,
  4482. * platforms and configurations. i.e, it can return a different value given
  4483. * the same input on different machines or operating systems, or if SDL is
  4484. * updated.
  4485. *
  4486. * \param y floating point value of the numerator (y coordinate).
  4487. * \param x floating point value of the denominator (x coordinate).
  4488. * \returns arc tangent of `y / x` in radians, or, if `x = 0`, either `-Pi/2`,
  4489. * `0`, or `Pi/2`, depending on the value of `y`.
  4490. *
  4491. * \threadsafety It is safe to call this function from any thread.
  4492. *
  4493. * \since This function is available since SDL 3.2.0.
  4494. *
  4495. * \sa SDL_atan2f
  4496. * \sa SDL_atan
  4497. * \sa SDL_tan
  4498. */
  4499. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  4500. /**
  4501. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  4502. * the result's quadrant.
  4503. *
  4504. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  4505. * of z is determined based on the signs of x and y.
  4506. *
  4507. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  4508. *
  4509. * Range: `-Pi <= y <= Pi`
  4510. *
  4511. * This function operates on single-precision floating point values, use
  4512. * SDL_atan2 for double-precision floats.
  4513. *
  4514. * To calculate the arc tangent of a single value, use SDL_atanf.
  4515. *
  4516. * This function may use a different approximation across different versions,
  4517. * platforms and configurations. i.e, it can return a different value given
  4518. * the same input on different machines or operating systems, or if SDL is
  4519. * updated.
  4520. *
  4521. * \param y floating point value of the numerator (y coordinate).
  4522. * \param x floating point value of the denominator (x coordinate).
  4523. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  4524. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  4525. *
  4526. * \threadsafety It is safe to call this function from any thread.
  4527. *
  4528. * \since This function is available since SDL 3.2.0.
  4529. *
  4530. * \sa SDL_atan2
  4531. * \sa SDL_atan
  4532. * \sa SDL_tan
  4533. */
  4534. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  4535. /**
  4536. * Compute the ceiling of `x`.
  4537. *
  4538. * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
  4539. * rounded up to the nearest integer.
  4540. *
  4541. * Domain: `-INF <= x <= INF`
  4542. *
  4543. * Range: `-INF <= y <= INF`, y integer
  4544. *
  4545. * This function operates on double-precision floating point values, use
  4546. * SDL_ceilf for single-precision floats.
  4547. *
  4548. * \param x floating point value.
  4549. * \returns the ceiling of `x`.
  4550. *
  4551. * \threadsafety It is safe to call this function from any thread.
  4552. *
  4553. * \since This function is available since SDL 3.2.0.
  4554. *
  4555. * \sa SDL_ceilf
  4556. * \sa SDL_floor
  4557. * \sa SDL_trunc
  4558. * \sa SDL_round
  4559. * \sa SDL_lround
  4560. */
  4561. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  4562. /**
  4563. * Compute the ceiling of `x`.
  4564. *
  4565. * The ceiling of `x` is the smallest integer `y` such that `y >= x`, i.e `x`
  4566. * rounded up to the nearest integer.
  4567. *
  4568. * Domain: `-INF <= x <= INF`
  4569. *
  4570. * Range: `-INF <= y <= INF`, y integer
  4571. *
  4572. * This function operates on single-precision floating point values, use
  4573. * SDL_ceil for double-precision floats.
  4574. *
  4575. * \param x floating point value.
  4576. * \returns the ceiling of `x`.
  4577. *
  4578. * \threadsafety It is safe to call this function from any thread.
  4579. *
  4580. * \since This function is available since SDL 3.2.0.
  4581. *
  4582. * \sa SDL_ceil
  4583. * \sa SDL_floorf
  4584. * \sa SDL_truncf
  4585. * \sa SDL_roundf
  4586. * \sa SDL_lroundf
  4587. */
  4588. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  4589. /**
  4590. * Copy the sign of one floating-point value to another.
  4591. *
  4592. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  4593. *
  4594. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  4595. *
  4596. * Range: `-INF <= z <= INF`
  4597. *
  4598. * This function operates on double-precision floating point values, use
  4599. * SDL_copysignf for single-precision floats.
  4600. *
  4601. * \param x floating point value to use as the magnitude.
  4602. * \param y floating point value to use as the sign.
  4603. * \returns the floating point value with the sign of y and the magnitude of
  4604. * x.
  4605. *
  4606. * \threadsafety It is safe to call this function from any thread.
  4607. *
  4608. * \since This function is available since SDL 3.2.0.
  4609. *
  4610. * \sa SDL_copysignf
  4611. * \sa SDL_fabs
  4612. */
  4613. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  4614. /**
  4615. * Copy the sign of one floating-point value to another.
  4616. *
  4617. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  4618. *
  4619. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  4620. *
  4621. * Range: `-INF <= z <= INF`
  4622. *
  4623. * This function operates on single-precision floating point values, use
  4624. * SDL_copysign for double-precision floats.
  4625. *
  4626. * \param x floating point value to use as the magnitude.
  4627. * \param y floating point value to use as the sign.
  4628. * \returns the floating point value with the sign of y and the magnitude of
  4629. * x.
  4630. *
  4631. * \threadsafety It is safe to call this function from any thread.
  4632. *
  4633. * \since This function is available since SDL 3.2.0.
  4634. *
  4635. * \sa SDL_copysign
  4636. * \sa SDL_fabsf
  4637. */
  4638. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  4639. /**
  4640. * Compute the cosine of `x`.
  4641. *
  4642. * Domain: `-INF <= x <= INF`
  4643. *
  4644. * Range: `-1 <= y <= 1`
  4645. *
  4646. * This function operates on double-precision floating point values, use
  4647. * SDL_cosf for single-precision floats.
  4648. *
  4649. * This function may use a different approximation across different versions,
  4650. * platforms and configurations. i.e, it can return a different value given
  4651. * the same input on different machines or operating systems, or if SDL is
  4652. * updated.
  4653. *
  4654. * \param x floating point value, in radians.
  4655. * \returns cosine of `x`.
  4656. *
  4657. * \threadsafety It is safe to call this function from any thread.
  4658. *
  4659. * \since This function is available since SDL 3.2.0.
  4660. *
  4661. * \sa SDL_cosf
  4662. * \sa SDL_acos
  4663. * \sa SDL_sin
  4664. */
  4665. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  4666. /**
  4667. * Compute the cosine of `x`.
  4668. *
  4669. * Domain: `-INF <= x <= INF`
  4670. *
  4671. * Range: `-1 <= y <= 1`
  4672. *
  4673. * This function operates on single-precision floating point values, use
  4674. * SDL_cos for double-precision floats.
  4675. *
  4676. * This function may use a different approximation across different versions,
  4677. * platforms and configurations. i.e, it can return a different value given
  4678. * the same input on different machines or operating systems, or if SDL is
  4679. * updated.
  4680. *
  4681. * \param x floating point value, in radians.
  4682. * \returns cosine of `x`.
  4683. *
  4684. * \threadsafety It is safe to call this function from any thread.
  4685. *
  4686. * \since This function is available since SDL 3.2.0.
  4687. *
  4688. * \sa SDL_cos
  4689. * \sa SDL_acosf
  4690. * \sa SDL_sinf
  4691. */
  4692. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  4693. /**
  4694. * Compute the exponential of `x`.
  4695. *
  4696. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  4697. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  4698. *
  4699. * Domain: `-INF <= x <= INF`
  4700. *
  4701. * Range: `0 <= y <= INF`
  4702. *
  4703. * The output will overflow if `exp(x)` is too large to be represented.
  4704. *
  4705. * This function operates on double-precision floating point values, use
  4706. * SDL_expf for single-precision floats.
  4707. *
  4708. * This function may use a different approximation across different versions,
  4709. * platforms and configurations. i.e, it can return a different value given
  4710. * the same input on different machines or operating systems, or if SDL is
  4711. * updated.
  4712. *
  4713. * \param x floating point value.
  4714. * \returns value of `e^x`.
  4715. *
  4716. * \threadsafety It is safe to call this function from any thread.
  4717. *
  4718. * \since This function is available since SDL 3.2.0.
  4719. *
  4720. * \sa SDL_expf
  4721. * \sa SDL_log
  4722. */
  4723. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  4724. /**
  4725. * Compute the exponential of `x`.
  4726. *
  4727. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  4728. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  4729. *
  4730. * Domain: `-INF <= x <= INF`
  4731. *
  4732. * Range: `0 <= y <= INF`
  4733. *
  4734. * The output will overflow if `exp(x)` is too large to be represented.
  4735. *
  4736. * This function operates on single-precision floating point values, use
  4737. * SDL_exp for double-precision floats.
  4738. *
  4739. * This function may use a different approximation across different versions,
  4740. * platforms and configurations. i.e, it can return a different value given
  4741. * the same input on different machines or operating systems, or if SDL is
  4742. * updated.
  4743. *
  4744. * \param x floating point value.
  4745. * \returns value of `e^x`.
  4746. *
  4747. * \threadsafety It is safe to call this function from any thread.
  4748. *
  4749. * \since This function is available since SDL 3.2.0.
  4750. *
  4751. * \sa SDL_exp
  4752. * \sa SDL_logf
  4753. */
  4754. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  4755. /**
  4756. * Compute the absolute value of `x`
  4757. *
  4758. * Domain: `-INF <= x <= INF`
  4759. *
  4760. * Range: `0 <= y <= INF`
  4761. *
  4762. * This function operates on double-precision floating point values, use
  4763. * SDL_fabsf for single-precision floats.
  4764. *
  4765. * \param x floating point value to use as the magnitude.
  4766. * \returns the absolute value of `x`.
  4767. *
  4768. * \threadsafety It is safe to call this function from any thread.
  4769. *
  4770. * \since This function is available since SDL 3.2.0.
  4771. *
  4772. * \sa SDL_fabsf
  4773. */
  4774. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  4775. /**
  4776. * Compute the absolute value of `x`
  4777. *
  4778. * Domain: `-INF <= x <= INF`
  4779. *
  4780. * Range: `0 <= y <= INF`
  4781. *
  4782. * This function operates on single-precision floating point values, use
  4783. * SDL_fabs for double-precision floats.
  4784. *
  4785. * \param x floating point value to use as the magnitude.
  4786. * \returns the absolute value of `x`.
  4787. *
  4788. * \threadsafety It is safe to call this function from any thread.
  4789. *
  4790. * \since This function is available since SDL 3.2.0.
  4791. *
  4792. * \sa SDL_fabs
  4793. */
  4794. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  4795. /**
  4796. * Compute the floor of `x`.
  4797. *
  4798. * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
  4799. * rounded down to the nearest integer.
  4800. *
  4801. * Domain: `-INF <= x <= INF`
  4802. *
  4803. * Range: `-INF <= y <= INF`, y integer
  4804. *
  4805. * This function operates on double-precision floating point values, use
  4806. * SDL_floorf for single-precision floats.
  4807. *
  4808. * \param x floating point value.
  4809. * \returns the floor of `x`.
  4810. *
  4811. * \threadsafety It is safe to call this function from any thread.
  4812. *
  4813. * \since This function is available since SDL 3.2.0.
  4814. *
  4815. * \sa SDL_floorf
  4816. * \sa SDL_ceil
  4817. * \sa SDL_trunc
  4818. * \sa SDL_round
  4819. * \sa SDL_lround
  4820. */
  4821. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  4822. /**
  4823. * Compute the floor of `x`.
  4824. *
  4825. * The floor of `x` is the largest integer `y` such that `y <= x`, i.e `x`
  4826. * rounded down to the nearest integer.
  4827. *
  4828. * Domain: `-INF <= x <= INF`
  4829. *
  4830. * Range: `-INF <= y <= INF`, y integer
  4831. *
  4832. * This function operates on single-precision floating point values, use
  4833. * SDL_floor for double-precision floats.
  4834. *
  4835. * \param x floating point value.
  4836. * \returns the floor of `x`.
  4837. *
  4838. * \threadsafety It is safe to call this function from any thread.
  4839. *
  4840. * \since This function is available since SDL 3.2.0.
  4841. *
  4842. * \sa SDL_floor
  4843. * \sa SDL_ceilf
  4844. * \sa SDL_truncf
  4845. * \sa SDL_roundf
  4846. * \sa SDL_lroundf
  4847. */
  4848. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  4849. /**
  4850. * Truncate `x` to an integer.
  4851. *
  4852. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  4853. * the fractional part of `x`, leaving only the integer part.
  4854. *
  4855. * Domain: `-INF <= x <= INF`
  4856. *
  4857. * Range: `-INF <= y <= INF`, y integer
  4858. *
  4859. * This function operates on double-precision floating point values, use
  4860. * SDL_truncf for single-precision floats.
  4861. *
  4862. * \param x floating point value.
  4863. * \returns `x` truncated to an integer.
  4864. *
  4865. * \threadsafety It is safe to call this function from any thread.
  4866. *
  4867. * \since This function is available since SDL 3.2.0.
  4868. *
  4869. * \sa SDL_truncf
  4870. * \sa SDL_fmod
  4871. * \sa SDL_ceil
  4872. * \sa SDL_floor
  4873. * \sa SDL_round
  4874. * \sa SDL_lround
  4875. */
  4876. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  4877. /**
  4878. * Truncate `x` to an integer.
  4879. *
  4880. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  4881. * the fractional part of `x`, leaving only the integer part.
  4882. *
  4883. * Domain: `-INF <= x <= INF`
  4884. *
  4885. * Range: `-INF <= y <= INF`, y integer
  4886. *
  4887. * This function operates on single-precision floating point values, use
  4888. * SDL_trunc for double-precision floats.
  4889. *
  4890. * \param x floating point value.
  4891. * \returns `x` truncated to an integer.
  4892. *
  4893. * \threadsafety It is safe to call this function from any thread.
  4894. *
  4895. * \since This function is available since SDL 3.2.0.
  4896. *
  4897. * \sa SDL_trunc
  4898. * \sa SDL_fmodf
  4899. * \sa SDL_ceilf
  4900. * \sa SDL_floorf
  4901. * \sa SDL_roundf
  4902. * \sa SDL_lroundf
  4903. */
  4904. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  4905. /**
  4906. * Return the floating-point remainder of `x / y`
  4907. *
  4908. * Divides `x` by `y`, and returns the remainder.
  4909. *
  4910. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  4911. *
  4912. * Range: `-y <= z <= y`
  4913. *
  4914. * This function operates on double-precision floating point values, use
  4915. * SDL_fmodf for single-precision floats.
  4916. *
  4917. * \param x the numerator.
  4918. * \param y the denominator. Must not be 0.
  4919. * \returns the remainder of `x / y`.
  4920. *
  4921. * \threadsafety It is safe to call this function from any thread.
  4922. *
  4923. * \since This function is available since SDL 3.2.0.
  4924. *
  4925. * \sa SDL_fmodf
  4926. * \sa SDL_modf
  4927. * \sa SDL_trunc
  4928. * \sa SDL_ceil
  4929. * \sa SDL_floor
  4930. * \sa SDL_round
  4931. * \sa SDL_lround
  4932. */
  4933. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  4934. /**
  4935. * Return the floating-point remainder of `x / y`
  4936. *
  4937. * Divides `x` by `y`, and returns the remainder.
  4938. *
  4939. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  4940. *
  4941. * Range: `-y <= z <= y`
  4942. *
  4943. * This function operates on single-precision floating point values, use
  4944. * SDL_fmod for double-precision floats.
  4945. *
  4946. * \param x the numerator.
  4947. * \param y the denominator. Must not be 0.
  4948. * \returns the remainder of `x / y`.
  4949. *
  4950. * \threadsafety It is safe to call this function from any thread.
  4951. *
  4952. * \since This function is available since SDL 3.2.0.
  4953. *
  4954. * \sa SDL_fmod
  4955. * \sa SDL_truncf
  4956. * \sa SDL_modff
  4957. * \sa SDL_ceilf
  4958. * \sa SDL_floorf
  4959. * \sa SDL_roundf
  4960. * \sa SDL_lroundf
  4961. */
  4962. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  4963. /**
  4964. * Return whether the value is infinity.
  4965. *
  4966. * \param x double-precision floating point value.
  4967. * \returns non-zero if the value is infinity, 0 otherwise.
  4968. *
  4969. * \threadsafety It is safe to call this function from any thread.
  4970. *
  4971. * \since This function is available since SDL 3.2.0.
  4972. *
  4973. * \sa SDL_isinff
  4974. */
  4975. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  4976. /**
  4977. * Return whether the value is infinity.
  4978. *
  4979. * \param x floating point value.
  4980. * \returns non-zero if the value is infinity, 0 otherwise.
  4981. *
  4982. * \threadsafety It is safe to call this function from any thread.
  4983. *
  4984. * \since This function is available since SDL 3.2.0.
  4985. *
  4986. * \sa SDL_isinf
  4987. */
  4988. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  4989. /**
  4990. * Return whether the value is NaN.
  4991. *
  4992. * \param x double-precision floating point value.
  4993. * \returns non-zero if the value is NaN, 0 otherwise.
  4994. *
  4995. * \threadsafety It is safe to call this function from any thread.
  4996. *
  4997. * \since This function is available since SDL 3.2.0.
  4998. *
  4999. * \sa SDL_isnanf
  5000. */
  5001. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  5002. /**
  5003. * Return whether the value is NaN.
  5004. *
  5005. * \param x floating point value.
  5006. * \returns non-zero if the value is NaN, 0 otherwise.
  5007. *
  5008. * \threadsafety It is safe to call this function from any thread.
  5009. *
  5010. * \since This function is available since SDL 3.2.0.
  5011. *
  5012. * \sa SDL_isnan
  5013. */
  5014. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  5015. /**
  5016. * Compute the natural logarithm of `x`.
  5017. *
  5018. * Domain: `0 < x <= INF`
  5019. *
  5020. * Range: `-INF <= y <= INF`
  5021. *
  5022. * It is an error for `x` to be less than or equal to 0.
  5023. *
  5024. * This function operates on double-precision floating point values, use
  5025. * SDL_logf for single-precision floats.
  5026. *
  5027. * This function may use a different approximation across different versions,
  5028. * platforms and configurations. i.e, it can return a different value given
  5029. * the same input on different machines or operating systems, or if SDL is
  5030. * updated.
  5031. *
  5032. * \param x floating point value. Must be greater than 0.
  5033. * \returns the natural logarithm of `x`.
  5034. *
  5035. * \threadsafety It is safe to call this function from any thread.
  5036. *
  5037. * \since This function is available since SDL 3.2.0.
  5038. *
  5039. * \sa SDL_logf
  5040. * \sa SDL_log10
  5041. * \sa SDL_exp
  5042. */
  5043. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  5044. /**
  5045. * Compute the natural logarithm of `x`.
  5046. *
  5047. * Domain: `0 < x <= INF`
  5048. *
  5049. * Range: `-INF <= y <= INF`
  5050. *
  5051. * It is an error for `x` to be less than or equal to 0.
  5052. *
  5053. * This function operates on single-precision floating point values, use
  5054. * SDL_log for double-precision floats.
  5055. *
  5056. * This function may use a different approximation across different versions,
  5057. * platforms and configurations. i.e, it can return a different value given
  5058. * the same input on different machines or operating systems, or if SDL is
  5059. * updated.
  5060. *
  5061. * \param x floating point value. Must be greater than 0.
  5062. * \returns the natural logarithm of `x`.
  5063. *
  5064. * \threadsafety It is safe to call this function from any thread.
  5065. *
  5066. * \since This function is available since SDL 3.2.0.
  5067. *
  5068. * \sa SDL_log
  5069. * \sa SDL_expf
  5070. */
  5071. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  5072. /**
  5073. * Compute the base-10 logarithm of `x`.
  5074. *
  5075. * Domain: `0 < x <= INF`
  5076. *
  5077. * Range: `-INF <= y <= INF`
  5078. *
  5079. * It is an error for `x` to be less than or equal to 0.
  5080. *
  5081. * This function operates on double-precision floating point values, use
  5082. * SDL_log10f for single-precision floats.
  5083. *
  5084. * This function may use a different approximation across different versions,
  5085. * platforms and configurations. i.e, it can return a different value given
  5086. * the same input on different machines or operating systems, or if SDL is
  5087. * updated.
  5088. *
  5089. * \param x floating point value. Must be greater than 0.
  5090. * \returns the logarithm of `x`.
  5091. *
  5092. * \threadsafety It is safe to call this function from any thread.
  5093. *
  5094. * \since This function is available since SDL 3.2.0.
  5095. *
  5096. * \sa SDL_log10f
  5097. * \sa SDL_log
  5098. * \sa SDL_pow
  5099. */
  5100. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  5101. /**
  5102. * Compute the base-10 logarithm of `x`.
  5103. *
  5104. * Domain: `0 < x <= INF`
  5105. *
  5106. * Range: `-INF <= y <= INF`
  5107. *
  5108. * It is an error for `x` to be less than or equal to 0.
  5109. *
  5110. * This function operates on single-precision floating point values, use
  5111. * SDL_log10 for double-precision floats.
  5112. *
  5113. * This function may use a different approximation across different versions,
  5114. * platforms and configurations. i.e, it can return a different value given
  5115. * the same input on different machines or operating systems, or if SDL is
  5116. * updated.
  5117. *
  5118. * \param x floating point value. Must be greater than 0.
  5119. * \returns the logarithm of `x`.
  5120. *
  5121. * \threadsafety It is safe to call this function from any thread.
  5122. *
  5123. * \since This function is available since SDL 3.2.0.
  5124. *
  5125. * \sa SDL_log10
  5126. * \sa SDL_logf
  5127. * \sa SDL_powf
  5128. */
  5129. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  5130. /**
  5131. * Split `x` into integer and fractional parts
  5132. *
  5133. * This function operates on double-precision floating point values, use
  5134. * SDL_modff for single-precision floats.
  5135. *
  5136. * \param x floating point value.
  5137. * \param y output pointer to store the integer part of `x`.
  5138. * \returns the fractional part of `x`.
  5139. *
  5140. * \threadsafety It is safe to call this function from any thread.
  5141. *
  5142. * \since This function is available since SDL 3.2.0.
  5143. *
  5144. * \sa SDL_modff
  5145. * \sa SDL_trunc
  5146. * \sa SDL_fmod
  5147. */
  5148. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  5149. /**
  5150. * Split `x` into integer and fractional parts
  5151. *
  5152. * This function operates on single-precision floating point values, use
  5153. * SDL_modf for double-precision floats.
  5154. *
  5155. * \param x floating point value.
  5156. * \param y output pointer to store the integer part of `x`.
  5157. * \returns the fractional part of `x`.
  5158. *
  5159. * \threadsafety It is safe to call this function from any thread.
  5160. *
  5161. * \since This function is available since SDL 3.2.0.
  5162. *
  5163. * \sa SDL_modf
  5164. * \sa SDL_truncf
  5165. * \sa SDL_fmodf
  5166. */
  5167. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  5168. /**
  5169. * Raise `x` to the power `y`
  5170. *
  5171. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  5172. *
  5173. * Range: `-INF <= z <= INF`
  5174. *
  5175. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  5176. * instead.
  5177. *
  5178. * This function operates on double-precision floating point values, use
  5179. * SDL_powf for single-precision floats.
  5180. *
  5181. * This function may use a different approximation across different versions,
  5182. * platforms and configurations. i.e, it can return a different value given
  5183. * the same input on different machines or operating systems, or if SDL is
  5184. * updated.
  5185. *
  5186. * \param x the base.
  5187. * \param y the exponent.
  5188. * \returns `x` raised to the power `y`.
  5189. *
  5190. * \threadsafety It is safe to call this function from any thread.
  5191. *
  5192. * \since This function is available since SDL 3.2.0.
  5193. *
  5194. * \sa SDL_powf
  5195. * \sa SDL_exp
  5196. * \sa SDL_log
  5197. */
  5198. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  5199. /**
  5200. * Raise `x` to the power `y`
  5201. *
  5202. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  5203. *
  5204. * Range: `-INF <= z <= INF`
  5205. *
  5206. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  5207. * instead.
  5208. *
  5209. * This function operates on single-precision floating point values, use
  5210. * SDL_pow for double-precision floats.
  5211. *
  5212. * This function may use a different approximation across different versions,
  5213. * platforms and configurations. i.e, it can return a different value given
  5214. * the same input on different machines or operating systems, or if SDL is
  5215. * updated.
  5216. *
  5217. * \param x the base.
  5218. * \param y the exponent.
  5219. * \returns `x` raised to the power `y`.
  5220. *
  5221. * \threadsafety It is safe to call this function from any thread.
  5222. *
  5223. * \since This function is available since SDL 3.2.0.
  5224. *
  5225. * \sa SDL_pow
  5226. * \sa SDL_expf
  5227. * \sa SDL_logf
  5228. */
  5229. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  5230. /**
  5231. * Round `x` to the nearest integer.
  5232. *
  5233. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5234. * rounded away from zero.
  5235. *
  5236. * Domain: `-INF <= x <= INF`
  5237. *
  5238. * Range: `-INF <= y <= INF`, y integer
  5239. *
  5240. * This function operates on double-precision floating point values, use
  5241. * SDL_roundf for single-precision floats. To get the result as an integer
  5242. * type, use SDL_lround.
  5243. *
  5244. * \param x floating point value.
  5245. * \returns the nearest integer to `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_roundf
  5252. * \sa SDL_lround
  5253. * \sa SDL_floor
  5254. * \sa SDL_ceil
  5255. * \sa SDL_trunc
  5256. */
  5257. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  5258. /**
  5259. * Round `x` to the nearest integer.
  5260. *
  5261. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5262. * rounded away from zero.
  5263. *
  5264. * Domain: `-INF <= x <= INF`
  5265. *
  5266. * Range: `-INF <= y <= INF`, y integer
  5267. *
  5268. * This function operates on single-precision floating point values, use
  5269. * SDL_round for double-precision floats. To get the result as an integer
  5270. * type, use SDL_lroundf.
  5271. *
  5272. * \param x floating point value.
  5273. * \returns the nearest integer to `x`.
  5274. *
  5275. * \threadsafety It is safe to call this function from any thread.
  5276. *
  5277. * \since This function is available since SDL 3.2.0.
  5278. *
  5279. * \sa SDL_round
  5280. * \sa SDL_lroundf
  5281. * \sa SDL_floorf
  5282. * \sa SDL_ceilf
  5283. * \sa SDL_truncf
  5284. */
  5285. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  5286. /**
  5287. * Round `x` to the nearest integer representable as a long
  5288. *
  5289. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5290. * rounded away from zero.
  5291. *
  5292. * Domain: `-INF <= x <= INF`
  5293. *
  5294. * Range: `MIN_LONG <= y <= MAX_LONG`
  5295. *
  5296. * This function operates on double-precision floating point values, use
  5297. * SDL_lroundf for single-precision floats. To get the result as a
  5298. * floating-point type, use SDL_round.
  5299. *
  5300. * \param x floating point value.
  5301. * \returns the nearest integer to `x`.
  5302. *
  5303. * \threadsafety It is safe to call this function from any thread.
  5304. *
  5305. * \since This function is available since SDL 3.2.0.
  5306. *
  5307. * \sa SDL_lroundf
  5308. * \sa SDL_round
  5309. * \sa SDL_floor
  5310. * \sa SDL_ceil
  5311. * \sa SDL_trunc
  5312. */
  5313. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  5314. /**
  5315. * Round `x` to the nearest integer representable as a long
  5316. *
  5317. * Rounds `x` to the nearest integer. Values halfway between integers will be
  5318. * rounded away from zero.
  5319. *
  5320. * Domain: `-INF <= x <= INF`
  5321. *
  5322. * Range: `MIN_LONG <= y <= MAX_LONG`
  5323. *
  5324. * This function operates on single-precision floating point values, use
  5325. * SDL_lround for double-precision floats. To get the result as a
  5326. * floating-point type, use SDL_roundf.
  5327. *
  5328. * \param x floating point value.
  5329. * \returns the nearest integer to `x`.
  5330. *
  5331. * \threadsafety It is safe to call this function from any thread.
  5332. *
  5333. * \since This function is available since SDL 3.2.0.
  5334. *
  5335. * \sa SDL_lround
  5336. * \sa SDL_roundf
  5337. * \sa SDL_floorf
  5338. * \sa SDL_ceilf
  5339. * \sa SDL_truncf
  5340. */
  5341. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  5342. /**
  5343. * Scale `x` by an integer power of two.
  5344. *
  5345. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  5346. *
  5347. * Domain: `-INF <= x <= INF`, `n` integer
  5348. *
  5349. * Range: `-INF <= y <= INF`
  5350. *
  5351. * This function operates on double-precision floating point values, use
  5352. * SDL_scalbnf for single-precision floats.
  5353. *
  5354. * \param x floating point value to be scaled.
  5355. * \param n integer exponent.
  5356. * \returns `x * 2^n`.
  5357. *
  5358. * \threadsafety It is safe to call this function from any thread.
  5359. *
  5360. * \since This function is available since SDL 3.2.0.
  5361. *
  5362. * \sa SDL_scalbnf
  5363. * \sa SDL_pow
  5364. */
  5365. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  5366. /**
  5367. * Scale `x` by an integer power of two.
  5368. *
  5369. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  5370. *
  5371. * Domain: `-INF <= x <= INF`, `n` integer
  5372. *
  5373. * Range: `-INF <= y <= INF`
  5374. *
  5375. * This function operates on single-precision floating point values, use
  5376. * SDL_scalbn for double-precision floats.
  5377. *
  5378. * \param x floating point value to be scaled.
  5379. * \param n integer exponent.
  5380. * \returns `x * 2^n`.
  5381. *
  5382. * \threadsafety It is safe to call this function from any thread.
  5383. *
  5384. * \since This function is available since SDL 3.2.0.
  5385. *
  5386. * \sa SDL_scalbn
  5387. * \sa SDL_powf
  5388. */
  5389. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  5390. /**
  5391. * Compute the sine of `x`.
  5392. *
  5393. * Domain: `-INF <= x <= INF`
  5394. *
  5395. * Range: `-1 <= y <= 1`
  5396. *
  5397. * This function operates on double-precision floating point values, use
  5398. * SDL_sinf for single-precision floats.
  5399. *
  5400. * This function may use a different approximation across different versions,
  5401. * platforms and configurations. i.e, it can return a different value given
  5402. * the same input on different machines or operating systems, or if SDL is
  5403. * updated.
  5404. *
  5405. * \param x floating point value, in radians.
  5406. * \returns sine of `x`.
  5407. *
  5408. * \threadsafety It is safe to call this function from any thread.
  5409. *
  5410. * \since This function is available since SDL 3.2.0.
  5411. *
  5412. * \sa SDL_sinf
  5413. * \sa SDL_asin
  5414. * \sa SDL_cos
  5415. */
  5416. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  5417. /**
  5418. * Compute the sine of `x`.
  5419. *
  5420. * Domain: `-INF <= x <= INF`
  5421. *
  5422. * Range: `-1 <= y <= 1`
  5423. *
  5424. * This function operates on single-precision floating point values, use
  5425. * SDL_sin for double-precision floats.
  5426. *
  5427. * This function may use a different approximation across different versions,
  5428. * platforms and configurations. i.e, it can return a different value given
  5429. * the same input on different machines or operating systems, or if SDL is
  5430. * updated.
  5431. *
  5432. * \param x floating point value, in radians.
  5433. * \returns sine of `x`.
  5434. *
  5435. * \threadsafety It is safe to call this function from any thread.
  5436. *
  5437. * \since This function is available since SDL 3.2.0.
  5438. *
  5439. * \sa SDL_sin
  5440. * \sa SDL_asinf
  5441. * \sa SDL_cosf
  5442. */
  5443. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  5444. /**
  5445. * Compute the square root of `x`.
  5446. *
  5447. * Domain: `0 <= x <= INF`
  5448. *
  5449. * Range: `0 <= y <= INF`
  5450. *
  5451. * This function operates on double-precision floating point values, use
  5452. * SDL_sqrtf for single-precision floats.
  5453. *
  5454. * This function may use a different approximation across different versions,
  5455. * platforms and configurations. i.e, it can return a different value given
  5456. * the same input on different machines or operating systems, or if SDL is
  5457. * updated.
  5458. *
  5459. * \param x floating point value. Must be greater than or equal to 0.
  5460. * \returns square root of `x`.
  5461. *
  5462. * \threadsafety It is safe to call this function from any thread.
  5463. *
  5464. * \since This function is available since SDL 3.2.0.
  5465. *
  5466. * \sa SDL_sqrtf
  5467. */
  5468. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  5469. /**
  5470. * Compute the square root of `x`.
  5471. *
  5472. * Domain: `0 <= x <= INF`
  5473. *
  5474. * Range: `0 <= y <= INF`
  5475. *
  5476. * This function operates on single-precision floating point values, use
  5477. * SDL_sqrt for double-precision floats.
  5478. *
  5479. * This function may use a different approximation across different versions,
  5480. * platforms and configurations. i.e, it can return a different value given
  5481. * the same input on different machines or operating systems, or if SDL is
  5482. * updated.
  5483. *
  5484. * \param x floating point value. Must be greater than or equal to 0.
  5485. * \returns square root of `x`.
  5486. *
  5487. * \threadsafety It is safe to call this function from any thread.
  5488. *
  5489. * \since This function is available since SDL 3.2.0.
  5490. *
  5491. * \sa SDL_sqrt
  5492. */
  5493. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  5494. /**
  5495. * Compute the tangent of `x`.
  5496. *
  5497. * Domain: `-INF <= x <= INF`
  5498. *
  5499. * Range: `-INF <= y <= INF`
  5500. *
  5501. * This function operates on double-precision floating point values, use
  5502. * SDL_tanf for single-precision floats.
  5503. *
  5504. * This function may use a different approximation across different versions,
  5505. * platforms and configurations. i.e, it can return a different value given
  5506. * the same input on different machines or operating systems, or if SDL is
  5507. * updated.
  5508. *
  5509. * \param x floating point value, in radians.
  5510. * \returns tangent of `x`.
  5511. *
  5512. * \threadsafety It is safe to call this function from any thread.
  5513. *
  5514. * \since This function is available since SDL 3.2.0.
  5515. *
  5516. * \sa SDL_tanf
  5517. * \sa SDL_sin
  5518. * \sa SDL_cos
  5519. * \sa SDL_atan
  5520. * \sa SDL_atan2
  5521. */
  5522. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  5523. /**
  5524. * Compute the tangent of `x`.
  5525. *
  5526. * Domain: `-INF <= x <= INF`
  5527. *
  5528. * Range: `-INF <= y <= INF`
  5529. *
  5530. * This function operates on single-precision floating point values, use
  5531. * SDL_tan for double-precision floats.
  5532. *
  5533. * This function may use a different approximation across different versions,
  5534. * platforms and configurations. i.e, it can return a different value given
  5535. * the same input on different machines or operating systems, or if SDL is
  5536. * updated.
  5537. *
  5538. * \param x floating point value, in radians.
  5539. * \returns tangent of `x`.
  5540. *
  5541. * \threadsafety It is safe to call this function from any thread.
  5542. *
  5543. * \since This function is available since SDL 3.2.0.
  5544. *
  5545. * \sa SDL_tan
  5546. * \sa SDL_sinf
  5547. * \sa SDL_cosf
  5548. * \sa SDL_atanf
  5549. * \sa SDL_atan2f
  5550. */
  5551. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  5552. /**
  5553. * An opaque handle representing string encoding conversion state.
  5554. *
  5555. * \since This datatype is available since SDL 3.2.0.
  5556. *
  5557. * \sa SDL_iconv_open
  5558. */
  5559. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  5560. /**
  5561. * This function allocates a context for the specified character set
  5562. * conversion.
  5563. *
  5564. * \param tocode The target character encoding, must not be NULL.
  5565. * \param fromcode The source character encoding, must not be NULL.
  5566. * \returns a handle that must be freed with SDL_iconv_close, or
  5567. * SDL_ICONV_ERROR on failure.
  5568. *
  5569. * \threadsafety It is safe to call this function from any thread.
  5570. *
  5571. * \since This function is available since SDL 3.2.0.
  5572. *
  5573. * \sa SDL_iconv
  5574. * \sa SDL_iconv_close
  5575. * \sa SDL_iconv_string
  5576. */
  5577. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  5578. const char *fromcode);
  5579. /**
  5580. * This function frees a context used for character set conversion.
  5581. *
  5582. * \param cd The character set conversion handle.
  5583. * \returns 0 on success, or -1 on failure.
  5584. *
  5585. * \threadsafety It is safe to call this function from any thread.
  5586. *
  5587. * \since This function is available since SDL 3.2.0.
  5588. *
  5589. * \sa SDL_iconv
  5590. * \sa SDL_iconv_open
  5591. * \sa SDL_iconv_string
  5592. */
  5593. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  5594. /**
  5595. * This function converts text between encodings, reading from and writing to
  5596. * a buffer.
  5597. *
  5598. * It returns the number of successful conversions on success. On error,
  5599. * SDL_ICONV_E2BIG is returned when the output buffer is too small, or
  5600. * SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered,
  5601. * or SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  5602. * encountered.
  5603. *
  5604. * On exit:
  5605. *
  5606. * - inbuf will point to the beginning of the next multibyte sequence. On
  5607. * error, this is the location of the problematic input sequence. On
  5608. * success, this is the end of the input sequence.
  5609. * - inbytesleft will be set to the number of bytes left to convert, which
  5610. * will be 0 on success.
  5611. * - outbuf will point to the location where to store the next output byte.
  5612. * - outbytesleft will be set to the number of bytes left in the output
  5613. * buffer.
  5614. *
  5615. * \param cd The character set conversion context, created in
  5616. * SDL_iconv_open().
  5617. * \param inbuf Address of variable that points to the first character of the
  5618. * input sequence.
  5619. * \param inbytesleft The number of bytes in the input buffer.
  5620. * \param outbuf Address of variable that points to the output buffer.
  5621. * \param outbytesleft The number of bytes in the output buffer.
  5622. * \returns the number of conversions on success, or a negative error code.
  5623. *
  5624. * \threadsafety Do not use the same SDL_iconv_t from two threads at once.
  5625. *
  5626. * \since This function is available since SDL 3.2.0.
  5627. *
  5628. * \sa SDL_iconv_open
  5629. * \sa SDL_iconv_close
  5630. * \sa SDL_iconv_string
  5631. */
  5632. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  5633. size_t *inbytesleft, char **outbuf,
  5634. size_t *outbytesleft);
  5635. #define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
  5636. #define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
  5637. #define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
  5638. #define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
  5639. /**
  5640. * Helper function to convert a string's encoding in one call.
  5641. *
  5642. * This function converts a buffer or string between encodings in one pass.
  5643. *
  5644. * The string does not need to be NULL-terminated; this function operates on
  5645. * the number of bytes specified in `inbytesleft` whether there is a NULL
  5646. * character anywhere in the buffer.
  5647. *
  5648. * The returned string is owned by the caller, and should be passed to
  5649. * SDL_free when no longer needed.
  5650. *
  5651. * \param tocode the character encoding of the output string. Examples are
  5652. * "UTF-8", "UCS-4", etc.
  5653. * \param fromcode the character encoding of data in `inbuf`.
  5654. * \param inbuf the string to convert to a different encoding.
  5655. * \param inbytesleft the size of the input string _in bytes_.
  5656. * \returns a new string, converted to the new encoding, or NULL on error.
  5657. *
  5658. * \threadsafety It is safe to call this function from any thread.
  5659. *
  5660. * \since This function is available since SDL 3.2.0.
  5661. *
  5662. * \sa SDL_iconv_open
  5663. * \sa SDL_iconv_close
  5664. * \sa SDL_iconv
  5665. */
  5666. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  5667. const char *fromcode,
  5668. const char *inbuf,
  5669. size_t inbytesleft);
  5670. /* Some helper macros for common SDL_iconv_string cases... */
  5671. /**
  5672. * Convert a UTF-8 string to the current locale's character encoding.
  5673. *
  5674. * This is a helper macro that might be more clear than calling
  5675. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5676. * do not use an expression with side-effects here.
  5677. *
  5678. * \param S the string to convert.
  5679. * \returns a new string, converted to the new encoding, or NULL on error.
  5680. *
  5681. * \threadsafety It is safe to call this macro from any thread.
  5682. *
  5683. * \since This macro is available since SDL 3.2.0.
  5684. */
  5685. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  5686. /**
  5687. * Convert a UTF-8 string to UCS-2.
  5688. *
  5689. * This is a helper macro that might be more clear than calling
  5690. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5691. * do not use an expression with side-effects here.
  5692. *
  5693. * \param S the string to convert.
  5694. * \returns a new string, converted to the new encoding, or NULL on error.
  5695. *
  5696. * \threadsafety It is safe to call this macro from any thread.
  5697. *
  5698. * \since This macro is available since SDL 3.2.0.
  5699. */
  5700. #define SDL_iconv_utf8_ucs2(S) SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
  5701. /**
  5702. * Convert a UTF-8 string to UCS-4.
  5703. *
  5704. * This is a helper macro that might be more clear than calling
  5705. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5706. * do not use an expression with side-effects here.
  5707. *
  5708. * \param S the string to convert.
  5709. * \returns a new string, converted to the new encoding, or NULL on error.
  5710. *
  5711. * \threadsafety It is safe to call this macro from any thread.
  5712. *
  5713. * \since This macro is available since SDL 3.2.0.
  5714. */
  5715. #define SDL_iconv_utf8_ucs4(S) SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))
  5716. /**
  5717. * Convert a wchar_t string to UTF-8.
  5718. *
  5719. * This is a helper macro that might be more clear than calling
  5720. * SDL_iconv_string directly. However, it double-evaluates its parameter, so
  5721. * do not use an expression with side-effects here.
  5722. *
  5723. * \param S the string to convert.
  5724. * \returns a new string, converted to the new encoding, or NULL on error.
  5725. *
  5726. * \threadsafety It is safe to call this macro from any thread.
  5727. *
  5728. * \since This macro is available since SDL 3.2.0.
  5729. */
  5730. #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))
  5731. /* force builds using Clang's static analysis tools to use literal C runtime
  5732. here, since there are possibly tests that are ineffective otherwise. */
  5733. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  5734. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  5735. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  5736. size_t strlcpy(char *dst, const char *src, size_t size);
  5737. #endif
  5738. /* The analyzer knows about strlcat even when the system doesn't provide it */
  5739. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  5740. size_t strlcat(char *dst, const char *src, size_t size);
  5741. #endif
  5742. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  5743. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  5744. #endif
  5745. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  5746. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  5747. #endif
  5748. #if !defined(HAVE_STRTOK_R) && !defined(strtok_r)
  5749. char *strtok_r(char *str, const char *delim, char **saveptr);
  5750. #endif
  5751. #ifndef _WIN32
  5752. /* strdup is not ANSI but POSIX, and its prototype might be hidden... */
  5753. /* not for windows: might conflict with string.h where strdup may have
  5754. * dllimport attribute: https://github.com/libsdl-org/SDL/issues/12948 */
  5755. char *strdup(const char *str);
  5756. #endif
  5757. /* Starting LLVM 16, the analyser errors out if these functions do not have
  5758. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  5759. #include <stdio.h>
  5760. #include <stdlib.h>
  5761. #define SDL_malloc malloc
  5762. #define SDL_calloc calloc
  5763. #define SDL_realloc realloc
  5764. #define SDL_free free
  5765. #ifndef SDL_memcpy
  5766. #define SDL_memcpy memcpy
  5767. #endif
  5768. #ifndef SDL_memmove
  5769. #define SDL_memmove memmove
  5770. #endif
  5771. #ifndef SDL_memset
  5772. #define SDL_memset memset
  5773. #endif
  5774. #define SDL_memcmp memcmp
  5775. #define SDL_strlcpy strlcpy
  5776. #define SDL_strlcat strlcat
  5777. #define SDL_strlen strlen
  5778. #define SDL_wcslen wcslen
  5779. #define SDL_wcslcpy wcslcpy
  5780. #define SDL_wcslcat wcslcat
  5781. #define SDL_strdup strdup
  5782. #define SDL_wcsdup wcsdup
  5783. #define SDL_strchr strchr
  5784. #define SDL_strrchr strrchr
  5785. #define SDL_strstr strstr
  5786. #define SDL_wcsstr wcsstr
  5787. #define SDL_strtok_r strtok_r
  5788. #define SDL_strcmp strcmp
  5789. #define SDL_wcscmp wcscmp
  5790. #define SDL_strncmp strncmp
  5791. #define SDL_wcsncmp wcsncmp
  5792. #define SDL_strcasecmp strcasecmp
  5793. #define SDL_strncasecmp strncasecmp
  5794. #define SDL_strpbrk strpbrk
  5795. #define SDL_sscanf sscanf
  5796. #define SDL_vsscanf vsscanf
  5797. #define SDL_snprintf snprintf
  5798. #define SDL_vsnprintf vsnprintf
  5799. #endif
  5800. /**
  5801. * Multiply two integers, checking for overflow.
  5802. *
  5803. * If `a * b` would overflow, return false.
  5804. *
  5805. * Otherwise store `a * b` via ret and return true.
  5806. *
  5807. * \param a the multiplicand.
  5808. * \param b the multiplier.
  5809. * \param ret on non-overflow output, stores the multiplication result, may
  5810. * not be NULL.
  5811. * \returns false on overflow, true if result is multiplied without overflow.
  5812. *
  5813. * \threadsafety It is safe to call this function from any thread.
  5814. *
  5815. * \since This function is available since SDL 3.2.0.
  5816. */
  5817. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  5818. {
  5819. if (a != 0 && b > SDL_SIZE_MAX / a) {
  5820. return false;
  5821. }
  5822. *ret = a * b;
  5823. return true;
  5824. }
  5825. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  5826. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  5827. /* This needs to be wrapped in an inline rather than being a direct #define,
  5828. * because __builtin_mul_overflow() is type-generic, but we want to be
  5829. * consistent about interpreting a and b as size_t. */
  5830. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  5831. {
  5832. return (__builtin_mul_overflow(a, b, ret) == 0);
  5833. }
  5834. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  5835. #endif
  5836. #endif
  5837. /**
  5838. * Add two integers, checking for overflow.
  5839. *
  5840. * If `a + b` would overflow, return false.
  5841. *
  5842. * Otherwise store `a + b` via ret and return true.
  5843. *
  5844. * \param a the first addend.
  5845. * \param b the second addend.
  5846. * \param ret on non-overflow output, stores the addition result, may not be
  5847. * NULL.
  5848. * \returns false on overflow, true if result is added without overflow.
  5849. *
  5850. * \threadsafety It is safe to call this function from any thread.
  5851. *
  5852. * \since This function is available since SDL 3.2.0.
  5853. */
  5854. SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  5855. {
  5856. if (b > SDL_SIZE_MAX - a) {
  5857. return false;
  5858. }
  5859. *ret = a + b;
  5860. return true;
  5861. }
  5862. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  5863. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  5864. /* This needs to be wrapped in an inline rather than being a direct #define,
  5865. * the same as the call to __builtin_mul_overflow() above. */
  5866. SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  5867. {
  5868. return (__builtin_add_overflow(a, b, ret) == 0);
  5869. }
  5870. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  5871. #endif
  5872. #endif
  5873. /* This is a generic function pointer which should be cast to the type you expect */
  5874. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  5875. /**
  5876. * A generic function pointer.
  5877. *
  5878. * In theory, generic function pointers should use this, instead of `void *`,
  5879. * since some platforms could treat code addresses differently than data
  5880. * addresses. Although in current times no popular platforms make this
  5881. * distinction, it is more correct and portable to use the correct type for a
  5882. * generic pointer.
  5883. *
  5884. * If for some reason you need to force this typedef to be an actual `void *`,
  5885. * perhaps to work around a compiler or existing code, you can define
  5886. * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
  5887. *
  5888. * \since This datatype is available since SDL 3.2.0.
  5889. */
  5890. typedef void (*SDL_FunctionPointer)(void);
  5891. #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
  5892. typedef void *SDL_FunctionPointer;
  5893. #else
  5894. typedef void (*SDL_FunctionPointer)(void);
  5895. #endif
  5896. /* Ends C function definitions when using C++ */
  5897. #ifdef __cplusplus
  5898. }
  5899. #endif
  5900. #include <SDL3/SDL_close_code.h>
  5901. #endif /* SDL_stdinc_h_ */