SDL_stdinc.h 206 KB

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