SDL_stdinc.h 208 KB

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