SDL_stdinc.h 202 KB

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