SDL_stdinc.h 173 KB

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