1
0

SDL_stdinc.h 199 KB

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