SDL_stdinc.h 198 KB

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