1
0

SDL_stdinc.h 173 KB

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