SDL_stdinc.h 173 KB

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