SDL_stdinc.h 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127
  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. /* Most everything except Visual Studio 2013 and earlier has stdbool.h now */
  31. #if defined(_MSC_VER) && (_MSC_VER < 1910)
  32. #define SDL_DEFINE_STDBOOL
  33. #endif
  34. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  35. #include <inttypes.h>
  36. #endif
  37. #include <stdarg.h>
  38. #ifndef __cplusplus
  39. #ifdef SDL_DEFINE_STDBOOL
  40. #ifndef __bool_true_false_are_defined
  41. #define __bool_true_false_are_defined 1
  42. #define bool int8_t
  43. #define false 0
  44. #define true 1
  45. #endif
  46. #else
  47. #include <stdbool.h>
  48. #endif
  49. #endif
  50. #include <stdint.h>
  51. #include <string.h>
  52. #include <wchar.h>
  53. #ifndef SDL_DISABLE_ALLOCA
  54. # ifndef alloca
  55. # ifdef HAVE_ALLOCA_H
  56. # include <alloca.h>
  57. # elif defined(SDL_PLATFORM_NETBSD)
  58. # if defined(__STRICT_ANSI__)
  59. # define SDL_DISABLE_ALLOCA
  60. # else
  61. # include <stdlib.h>
  62. # endif
  63. # elif defined(__GNUC__)
  64. # define alloca __builtin_alloca
  65. # elif defined(_MSC_VER)
  66. # include <malloc.h>
  67. # define alloca _alloca
  68. # elif defined(__WATCOMC__)
  69. # include <malloc.h>
  70. # elif defined(__BORLANDC__)
  71. # include <malloc.h>
  72. # elif defined(__DMC__)
  73. # include <stdlib.h>
  74. # elif defined(SDL_PLATFORM_AIX)
  75. # pragma alloca
  76. # elif defined(__MRC__)
  77. void *alloca(unsigned);
  78. # else
  79. void *alloca(size_t);
  80. # endif
  81. # endif
  82. #endif
  83. #ifdef SIZE_MAX
  84. # define SDL_SIZE_MAX SIZE_MAX
  85. #else
  86. # define SDL_SIZE_MAX ((size_t) -1)
  87. #endif
  88. /**
  89. * Check if the compiler supports a given builtin.
  90. * Supported by virtually all clang versions and recent gcc. Use this
  91. * instead of checking the clang version if possible.
  92. */
  93. #ifdef __has_builtin
  94. #define SDL_HAS_BUILTIN(x) __has_builtin(x)
  95. #else
  96. #define SDL_HAS_BUILTIN(x) 0
  97. #endif
  98. /**
  99. * The number of elements in an array.
  100. *
  101. * This macro looks like it double-evaluates the argument, but it does so
  102. * inside of `sizeof`, so there are no side-effects here, as expressions do
  103. * not actually run any code in these cases.
  104. *
  105. * \since This macro is available since SDL 3.0.0.
  106. */
  107. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  108. /**
  109. * Macro useful for building other macros with strings in them.
  110. *
  111. * For example:
  112. *
  113. * ```c
  114. * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
  115. * ```
  116. *
  117. * \since This macro is available since SDL 3.0.0.
  118. */
  119. #define SDL_STRINGIFY_ARG(arg) #arg
  120. /**
  121. * \name Cast operators
  122. *
  123. * Use proper C++ casts when compiled as C++ to be compatible with the option
  124. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  125. */
  126. /* @{ */
  127. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  128. /**
  129. * Handle a Reinterpret Cast properly whether using C or C++.
  130. *
  131. * If compiled as C++, this macro offers a proper C++ reinterpret_cast<>.
  132. *
  133. * If compiled as C, this macro does a normal C-style cast.
  134. *
  135. * This is helpful to avoid compiler warnings in C++.
  136. *
  137. * \param type the type to cast the expression to.
  138. * \param expression the expression to cast to a different type.
  139. * \returns `expression`, cast to `type`.
  140. *
  141. * \threadsafety It is safe to call this macro from any thread.
  142. *
  143. * \since This macro is available since SDL 3.0.0.
  144. *
  145. * \sa SDL_static_cast
  146. * \sa SDL_const_cast
  147. */
  148. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) /* or `((type)(expression))` in C */
  149. /**
  150. * Handle a Static Cast properly whether using C or C++.
  151. *
  152. * If compiled as C++, this macro offers a proper C++ static_cast<>.
  153. *
  154. * If compiled as C, this macro does a normal C-style cast.
  155. *
  156. * This is helpful to avoid compiler warnings in C++.
  157. *
  158. * \param type the type to cast the expression to.
  159. * \param expression the expression to cast to a different type.
  160. * \returns `expression`, cast to `type`.
  161. *
  162. * \threadsafety It is safe to call this macro from any thread.
  163. *
  164. * \since This macro is available since SDL 3.0.0.
  165. *
  166. * \sa SDL_reinterpret_cast
  167. * \sa SDL_const_cast
  168. */
  169. #define SDL_static_cast(type, expression) static_cast<type>(expression) /* or `((type)(expression))` in C */
  170. /**
  171. * Handle a Const Cast properly whether using C or C++.
  172. *
  173. * If compiled as C++, this macro offers a proper C++ const_cast<>.
  174. *
  175. * If compiled as C, this macro does a normal C-style cast.
  176. *
  177. * This is helpful to avoid compiler warnings in C++.
  178. *
  179. * \param type the type to cast the expression to.
  180. * \param expression the expression to cast to a different type.
  181. * \returns `expression`, cast to `type`.
  182. *
  183. * \threadsafety It is safe to call this macro from any thread.
  184. *
  185. * \since This macro is available since SDL 3.0.0.
  186. *
  187. * \sa SDL_reinterpret_cast
  188. * \sa SDL_static_cast
  189. */
  190. #define SDL_const_cast(type, expression) const_cast<type>(expression) /* or `((type)(expression))` in C */
  191. #elif defined(__cplusplus)
  192. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  193. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  194. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  195. #else
  196. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  197. #define SDL_static_cast(type, expression) ((type)(expression))
  198. #define SDL_const_cast(type, expression) ((type)(expression))
  199. #endif
  200. /* @} *//* Cast operators */
  201. /**
  202. * Define a four character code as a Uint32.
  203. *
  204. * \param A the first ASCII character.
  205. * \param B the second ASCII character.
  206. * \param C the third ASCII character.
  207. * \param D the fourth ASCII character.
  208. * \returns the four characters converted into a Uint32, one character
  209. * per-byte.
  210. *
  211. * \threadsafety It is safe to call this macro from any thread.
  212. *
  213. * \since This macro is available since SDL 3.0.0.
  214. */
  215. #define SDL_FOURCC(A, B, C, D) \
  216. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  217. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  218. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  219. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  220. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  221. /**
  222. * Append the 64 bit integer suffix to a signed integer literal.
  223. *
  224. * This helps compilers that might believe a integer literal larger than
  225. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_SINT64_C(0xFFFFFFFF1)`
  226. * instead of `0xFFFFFFFF1` by itself.
  227. *
  228. * \since This macro is available since SDL 3.0.0.
  229. *
  230. * \sa SDL_UINT64_C
  231. */
  232. #define SDL_SINT64_C(c) c ## LL /* or whatever the current compiler uses. */
  233. /**
  234. * Append the 64 bit integer suffix to an unsigned integer literal.
  235. *
  236. * This helps compilers that might believe a integer literal larger than
  237. * 0xFFFFFFFF is overflowing a 32-bit value. Use `SDL_UINT64_C(0xFFFFFFFF1)`
  238. * instead of `0xFFFFFFFF1` by itself.
  239. *
  240. * \since This macro is available since SDL 3.0.0.
  241. *
  242. * \sa SDL_SINT64_C
  243. */
  244. #define SDL_UINT64_C(c) c ## ULL /* or whatever the current compiler uses. */
  245. #elif defined(INT64_C)
  246. #define SDL_SINT64_C(c) INT64_C(c)
  247. #define SDL_UINT64_C(c) UINT64_C(c)
  248. #elif defined(_MSC_VER)
  249. #define SDL_SINT64_C(c) c ## i64
  250. #define SDL_UINT64_C(c) c ## ui64
  251. #elif defined(__LP64__) || defined(_LP64)
  252. #define SDL_SINT64_C(c) c ## L
  253. #define SDL_UINT64_C(c) c ## UL
  254. #else
  255. #define SDL_SINT64_C(c) c ## LL
  256. #define SDL_UINT64_C(c) c ## ULL
  257. #endif
  258. /**
  259. * \name Basic data types
  260. */
  261. /* @{ */
  262. /**
  263. * A signed 8-bit integer type.
  264. *
  265. * \since This macro is available since SDL 3.0.0.
  266. */
  267. typedef int8_t Sint8;
  268. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  269. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  270. /**
  271. * An unsigned 8-bit integer type.
  272. *
  273. * \since This macro is available since SDL 3.0.0.
  274. */
  275. typedef uint8_t Uint8;
  276. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  277. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  278. /**
  279. * A signed 16-bit integer type.
  280. *
  281. * \since This macro is available since SDL 3.0.0.
  282. */
  283. typedef int16_t Sint16;
  284. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  285. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  286. /**
  287. * An unsigned 16-bit integer type.
  288. *
  289. * \since This macro is available since SDL 3.0.0.
  290. */
  291. typedef uint16_t Uint16;
  292. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  293. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  294. /**
  295. * A signed 32-bit integer type.
  296. *
  297. * \since This macro is available since SDL 3.0.0.
  298. */
  299. typedef int32_t Sint32;
  300. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  301. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  302. /**
  303. * An unsigned 32-bit integer type.
  304. *
  305. * \since This macro is available since SDL 3.0.0.
  306. */
  307. typedef uint32_t Uint32;
  308. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  309. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  310. /**
  311. * A signed 64-bit integer type.
  312. *
  313. * \since This macro is available since SDL 3.0.0.
  314. *
  315. * \sa SDL_SINT64_C
  316. */
  317. typedef int64_t Sint64;
  318. #define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
  319. #define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
  320. /**
  321. * An unsigned 64-bit integer type.
  322. *
  323. * \since This macro is available since SDL 3.0.0.
  324. *
  325. * \sa SDL_UINT64_C
  326. */
  327. typedef uint64_t Uint64;
  328. #define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
  329. #define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
  330. /**
  331. * SDL times are signed, 64-bit integers representing nanoseconds since the
  332. * Unix epoch (Jan 1, 1970).
  333. *
  334. * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
  335. * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
  336. * SDL_TimeToWindows() and SDL_TimeFromWindows().
  337. *
  338. * \since This macro is available since SDL 3.0.0.
  339. *
  340. * \sa SDL_MAX_SINT64
  341. * \sa SDL_MIN_SINT64
  342. */
  343. typedef Sint64 SDL_Time;
  344. #define SDL_MAX_TIME SDL_MAX_SINT64
  345. #define SDL_MIN_TIME SDL_MIN_SINT64
  346. /* @} *//* Basic data types */
  347. /**
  348. * \name Floating-point constants
  349. */
  350. /* @{ */
  351. #ifdef FLT_EPSILON
  352. #define SDL_FLT_EPSILON FLT_EPSILON
  353. #else
  354. /**
  355. * Epsilon constant, used for comparing floating-point numbers.
  356. *
  357. * Equals by default to platform-defined `FLT_EPSILON`, or
  358. * `1.1920928955078125e-07F` if that's not available.
  359. *
  360. * \since This macro is available since SDL 3.0.0.
  361. */
  362. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  363. #endif
  364. /* @} *//* Floating-point constants */
  365. /* Make sure we have macros for printing width-based integers.
  366. * <stdint.h> should define these but this is not true all platforms.
  367. * (for example win32) */
  368. #ifndef SDL_PRIs64
  369. #if defined(SDL_PLATFORM_WINDOWS)
  370. #define SDL_PRIs64 "I64d"
  371. #elif defined(PRIs64)
  372. #define SDL_PRIs64 PRIs64
  373. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  374. #define SDL_PRIs64 "ld"
  375. #else
  376. #define SDL_PRIs64 "lld"
  377. #endif
  378. #endif
  379. #ifndef SDL_PRIu64
  380. #if defined(SDL_PLATFORM_WINDOWS)
  381. #define SDL_PRIu64 "I64u"
  382. #elif defined(PRIu64)
  383. #define SDL_PRIu64 PRIu64
  384. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  385. #define SDL_PRIu64 "lu"
  386. #else
  387. #define SDL_PRIu64 "llu"
  388. #endif
  389. #endif
  390. #ifndef SDL_PRIx64
  391. #if defined(SDL_PLATFORM_WINDOWS)
  392. #define SDL_PRIx64 "I64x"
  393. #elif defined(PRIx64)
  394. #define SDL_PRIx64 PRIx64
  395. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  396. #define SDL_PRIx64 "lx"
  397. #else
  398. #define SDL_PRIx64 "llx"
  399. #endif
  400. #endif
  401. #ifndef SDL_PRIX64
  402. #if defined(SDL_PLATFORM_WINDOWS)
  403. #define SDL_PRIX64 "I64X"
  404. #elif defined(PRIX64)
  405. #define SDL_PRIX64 PRIX64
  406. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  407. #define SDL_PRIX64 "lX"
  408. #else
  409. #define SDL_PRIX64 "llX"
  410. #endif
  411. #endif
  412. #ifndef SDL_PRIs32
  413. #ifdef PRId32
  414. #define SDL_PRIs32 PRId32
  415. #else
  416. #define SDL_PRIs32 "d"
  417. #endif
  418. #endif
  419. #ifndef SDL_PRIu32
  420. #ifdef PRIu32
  421. #define SDL_PRIu32 PRIu32
  422. #else
  423. #define SDL_PRIu32 "u"
  424. #endif
  425. #endif
  426. #ifndef SDL_PRIx32
  427. #ifdef PRIx32
  428. #define SDL_PRIx32 PRIx32
  429. #else
  430. #define SDL_PRIx32 "x"
  431. #endif
  432. #endif
  433. #ifndef SDL_PRIX32
  434. #ifdef PRIX32
  435. #define SDL_PRIX32 PRIX32
  436. #else
  437. #define SDL_PRIX32 "X"
  438. #endif
  439. #endif
  440. /* Annotations to help code analysis tools */
  441. #ifdef SDL_DISABLE_ANALYZE_MACROS
  442. #define SDL_IN_BYTECAP(x)
  443. #define SDL_INOUT_Z_CAP(x)
  444. #define SDL_OUT_Z_CAP(x)
  445. #define SDL_OUT_CAP(x)
  446. #define SDL_OUT_BYTECAP(x)
  447. #define SDL_OUT_Z_BYTECAP(x)
  448. #define SDL_PRINTF_FORMAT_STRING
  449. #define SDL_SCANF_FORMAT_STRING
  450. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  451. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  452. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  453. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  454. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  455. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
  456. #else
  457. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  458. #include <sal.h>
  459. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  460. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  461. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  462. #define SDL_OUT_CAP(x) _Out_cap_(x)
  463. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  464. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  465. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  466. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  467. #else
  468. #define SDL_IN_BYTECAP(x)
  469. #define SDL_INOUT_Z_CAP(x)
  470. #define SDL_OUT_Z_CAP(x)
  471. #define SDL_OUT_CAP(x)
  472. #define SDL_OUT_BYTECAP(x)
  473. #define SDL_OUT_Z_BYTECAP(x)
  474. #define SDL_PRINTF_FORMAT_STRING
  475. #define SDL_SCANF_FORMAT_STRING
  476. #endif
  477. #ifdef __GNUC__
  478. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  479. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
  480. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  481. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
  482. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
  483. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, 0 ))) */
  484. #else
  485. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  486. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  487. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  488. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  489. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  490. #define SDL_WPRINTF_VARARG_FUNCV( fmtargnumber )
  491. #endif
  492. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  493. #ifndef SDL_COMPILE_TIME_ASSERT
  494. #if defined(__cplusplus)
  495. /* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */
  496. #if (__cplusplus >= 201103L)
  497. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  498. #endif
  499. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
  500. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  501. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  502. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  503. #endif
  504. #endif /* !SDL_COMPILE_TIME_ASSERT */
  505. #ifndef SDL_COMPILE_TIME_ASSERT
  506. /* universal, but may trigger -Wunused-local-typedefs */
  507. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  508. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  509. #endif
  510. /** \cond */
  511. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  512. SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);
  513. SDL_COMPILE_TIME_ASSERT(uint8_size, sizeof(Uint8) == 1);
  514. SDL_COMPILE_TIME_ASSERT(sint8_size, sizeof(Sint8) == 1);
  515. SDL_COMPILE_TIME_ASSERT(uint16_size, sizeof(Uint16) == 2);
  516. SDL_COMPILE_TIME_ASSERT(sint16_size, sizeof(Sint16) == 2);
  517. SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4);
  518. SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4);
  519. SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8);
  520. SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8);
  521. SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long));
  522. SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long));
  523. typedef struct SDL_alignment_test
  524. {
  525. Uint8 a;
  526. void *b;
  527. } SDL_alignment_test;
  528. SDL_COMPILE_TIME_ASSERT(struct_alignment, sizeof(SDL_alignment_test) == (2 * sizeof(void *)));
  529. SDL_COMPILE_TIME_ASSERT(two_s_complement, (int)~(int)0 == (int)(-1));
  530. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  531. /** \endcond */
  532. /* Check to make sure enums are the size of ints, for structure packing.
  533. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  534. enums having the size of an int must be enabled.
  535. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  536. */
  537. /** \cond */
  538. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  539. #if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
  540. /* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
  541. typedef enum SDL_DUMMY_ENUM
  542. {
  543. DUMMY_ENUM_VALUE
  544. } SDL_DUMMY_ENUM;
  545. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  546. #endif
  547. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  548. /** \endcond */
  549. #include <SDL3/SDL_begin_code.h>
  550. /* Set up for C function definitions, even when using C++ */
  551. #ifdef __cplusplus
  552. extern "C" {
  553. #endif
  554. /**
  555. * A macro to initialize an SDL interface.
  556. *
  557. * This macro will initialize an SDL interface structure and should be called
  558. * before you fill out the fields with your implementation.
  559. *
  560. * You can use it like this:
  561. *
  562. * ```c
  563. * SDL_IOStreamInterface iface;
  564. *
  565. * SDL_INIT_INTERFACE(&iface);
  566. *
  567. * // Fill in the interface function pointers with your implementation
  568. * iface.seek = ...
  569. *
  570. * stream = SDL_OpenIO(&iface, NULL);
  571. * ```
  572. *
  573. * If you are using designated initializers, you can use the size of the
  574. * interface as the version, e.g.
  575. *
  576. * ```c
  577. * SDL_IOStreamInterface iface = {
  578. * .version = sizeof(iface),
  579. * .seek = ...
  580. * };
  581. * stream = SDL_OpenIO(&iface, NULL);
  582. * ```
  583. *
  584. * \threadsafety It is safe to call this macro from any thread.
  585. *
  586. * \since This macro is available since SDL 3.0.0.
  587. *
  588. * \sa SDL_IOStreamInterface
  589. * \sa SDL_StorageInterface
  590. * \sa SDL_VirtualJoystickDesc
  591. */
  592. #define SDL_INIT_INTERFACE(iface) \
  593. do { \
  594. SDL_zerop(iface); \
  595. (iface)->version = sizeof(*(iface)); \
  596. } while (0)
  597. #ifndef SDL_DISABLE_ALLOCA
  598. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  599. #define SDL_stack_free(data)
  600. #else
  601. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  602. #define SDL_stack_free(data) SDL_free(data)
  603. #endif
  604. /**
  605. * Allocate uninitialized memory.
  606. *
  607. * The allocated memory returned by this function must be freed with
  608. * SDL_free().
  609. *
  610. * If `size` is 0, it will be set to 1.
  611. *
  612. * If you want to allocate memory aligned to a specific alignment, consider
  613. * using SDL_aligned_alloc().
  614. *
  615. * \param size the size to allocate.
  616. * \returns a pointer to the allocated memory, or NULL if allocation failed.
  617. *
  618. * \threadsafety It is safe to call this function from any thread.
  619. *
  620. * \since This function is available since SDL 3.0.0.
  621. *
  622. * \sa SDL_free
  623. * \sa SDL_calloc
  624. * \sa SDL_realloc
  625. * \sa SDL_aligned_alloc
  626. */
  627. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
  628. /**
  629. * Allocate a zero-initialized array.
  630. *
  631. * The memory returned by this function must be freed with SDL_free().
  632. *
  633. * If either of `nmemb` or `size` is 0, they will both be set to 1.
  634. *
  635. * \param nmemb the number of elements in the array.
  636. * \param size the size of each element of the array.
  637. * \returns a pointer to the allocated array, or NULL if allocation failed.
  638. *
  639. * \threadsafety It is safe to call this function from any thread.
  640. *
  641. * \since This function is available since SDL 3.0.0.
  642. *
  643. * \sa SDL_free
  644. * \sa SDL_malloc
  645. * \sa SDL_realloc
  646. */
  647. extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
  648. /**
  649. * Change the size of allocated memory.
  650. *
  651. * The memory returned by this function must be freed with SDL_free().
  652. *
  653. * If `size` is 0, it will be set to 1. Note that this is unlike some other C
  654. * runtime `realloc` implementations, which may treat `realloc(mem, 0)` the
  655. * same way as `free(mem)`.
  656. *
  657. * If `mem` is NULL, the behavior of this function is equivalent to
  658. * SDL_malloc(). Otherwise, the function can have one of three possible
  659. * outcomes:
  660. *
  661. * - If it returns the same pointer as `mem`, it means that `mem` was resized
  662. * in place without freeing.
  663. * - If it returns a different non-NULL pointer, it means that `mem` was freed
  664. * and cannot be dereferenced anymore.
  665. * - If it returns NULL (indicating failure), then `mem` will remain valid and
  666. * must still be freed with SDL_free().
  667. *
  668. * \param mem a pointer to allocated memory to reallocate, or NULL.
  669. * \param size the new size of the memory.
  670. * \returns a pointer to the newly allocated memory, or NULL if allocation
  671. * failed.
  672. *
  673. * \threadsafety It is safe to call this function from any thread.
  674. *
  675. * \since This function is available since SDL 3.0.0.
  676. *
  677. * \sa SDL_free
  678. * \sa SDL_malloc
  679. * \sa SDL_calloc
  680. */
  681. extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
  682. /**
  683. * Free allocated memory.
  684. *
  685. * The pointer is no longer valid after this call and cannot be dereferenced
  686. * anymore.
  687. *
  688. * If `mem` is NULL, this function does nothing.
  689. *
  690. * \param mem a pointer to allocated memory, or NULL.
  691. *
  692. * \threadsafety It is safe to call this function from any thread.
  693. *
  694. * \since This function is available since SDL 3.0.0.
  695. *
  696. * \sa SDL_malloc
  697. * \sa SDL_calloc
  698. * \sa SDL_realloc
  699. */
  700. extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
  701. /**
  702. * A callback used to implement SDL_malloc().
  703. *
  704. * SDL will always ensure that the passed `size` is greater than 0.
  705. *
  706. * \param size the size to allocate.
  707. * \returns a pointer to the allocated memory, or NULL if allocation failed.
  708. *
  709. * \threadsafety It should be safe to call this callback from any thread.
  710. *
  711. * \since This datatype is available since SDL 3.0.0.
  712. *
  713. * \sa SDL_malloc
  714. * \sa SDL_GetOriginalMemoryFunctions
  715. * \sa SDL_GetMemoryFunctions
  716. * \sa SDL_SetMemoryFunctions
  717. */
  718. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  719. /**
  720. * A callback used to implement SDL_calloc().
  721. *
  722. * SDL will always ensure that the passed `nmemb` and `size` are both greater
  723. * than 0.
  724. *
  725. * \param nmemb the number of elements in the array.
  726. * \param size the size of each element of the array.
  727. * \returns a pointer to the allocated array, or NULL if allocation failed.
  728. *
  729. * \threadsafety It should be safe to call this callback from any thread.
  730. *
  731. * \since This datatype is available since SDL 3.0.0.
  732. *
  733. * \sa SDL_calloc
  734. * \sa SDL_GetOriginalMemoryFunctions
  735. * \sa SDL_GetMemoryFunctions
  736. * \sa SDL_SetMemoryFunctions
  737. */
  738. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  739. /**
  740. * A callback used to implement SDL_realloc().
  741. *
  742. * SDL will always ensure that the passed `size` is greater than 0.
  743. *
  744. * \param mem a pointer to allocated memory to reallocate, or NULL.
  745. * \param size the new size of the memory.
  746. * \returns a pointer to the newly allocated memory, or NULL if allocation
  747. * failed.
  748. *
  749. * \threadsafety It should be safe to call this callback from any thread.
  750. *
  751. * \since This datatype is available since SDL 3.0.0.
  752. *
  753. * \sa SDL_realloc
  754. * \sa SDL_GetOriginalMemoryFunctions
  755. * \sa SDL_GetMemoryFunctions
  756. * \sa SDL_SetMemoryFunctions
  757. */
  758. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  759. /**
  760. * A callback used to implement SDL_free().
  761. *
  762. * SDL will always ensure that the passed `mem` is a non-NULL pointer.
  763. *
  764. * \param mem a pointer to allocated memory.
  765. *
  766. * \threadsafety It should be safe to call this callback from any thread.
  767. *
  768. * \since This datatype is available since SDL 3.0.0.
  769. *
  770. * \sa SDL_free
  771. * \sa SDL_GetOriginalMemoryFunctions
  772. * \sa SDL_GetMemoryFunctions
  773. * \sa SDL_SetMemoryFunctions
  774. */
  775. typedef void (SDLCALL *SDL_free_func)(void *mem);
  776. /**
  777. * Get the original set of SDL memory functions.
  778. *
  779. * This is what SDL_malloc and friends will use by default, if there has been
  780. * no call to SDL_SetMemoryFunctions. This is not necessarily using the C
  781. * runtime's `malloc` functions behind the scenes! Different platforms and
  782. * build configurations might do any number of unexpected things.
  783. *
  784. * \param malloc_func filled with malloc function.
  785. * \param calloc_func filled with calloc function.
  786. * \param realloc_func filled with realloc function.
  787. * \param free_func filled with free function.
  788. *
  789. * \threadsafety It is safe to call this function from any thread.
  790. *
  791. * \since This function is available since SDL 3.0.0.
  792. */
  793. extern SDL_DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
  794. SDL_calloc_func *calloc_func,
  795. SDL_realloc_func *realloc_func,
  796. SDL_free_func *free_func);
  797. /**
  798. * Get the current set of SDL memory functions.
  799. *
  800. * \param malloc_func filled with malloc function.
  801. * \param calloc_func filled with calloc function.
  802. * \param realloc_func filled with realloc function.
  803. * \param free_func filled with free function.
  804. *
  805. * \threadsafety This does not hold a lock, so do not call this in the
  806. * unlikely event of a background thread calling
  807. * SDL_SetMemoryFunctions simultaneously.
  808. *
  809. * \since This function is available since SDL 3.0.0.
  810. *
  811. * \sa SDL_SetMemoryFunctions
  812. * \sa SDL_GetOriginalMemoryFunctions
  813. */
  814. extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  815. SDL_calloc_func *calloc_func,
  816. SDL_realloc_func *realloc_func,
  817. SDL_free_func *free_func);
  818. /**
  819. * Replace SDL's memory allocation functions with a custom set.
  820. *
  821. * It is not safe to call this function once any allocations have been made,
  822. * as future calls to SDL_free will use the new allocator, even if they came
  823. * from an SDL_malloc made with the old one!
  824. *
  825. * If used, usually this needs to be the first call made into the SDL library,
  826. * if not the very first thing done at program startup time.
  827. *
  828. * \param malloc_func custom malloc function.
  829. * \param calloc_func custom calloc function.
  830. * \param realloc_func custom realloc function.
  831. * \param free_func custom free function.
  832. * \returns true on success or false on failure; call SDL_GetError() for more
  833. * information.
  834. *
  835. * \threadsafety It is safe to call this function from any thread, but one
  836. * should not replace the memory functions once any allocations
  837. * are made!
  838. *
  839. * \since This function is available since SDL 3.0.0.
  840. *
  841. * \sa SDL_GetMemoryFunctions
  842. * \sa SDL_GetOriginalMemoryFunctions
  843. */
  844. extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  845. SDL_calloc_func calloc_func,
  846. SDL_realloc_func realloc_func,
  847. SDL_free_func free_func);
  848. /**
  849. * Allocate memory aligned to a specific alignment.
  850. *
  851. * The memory returned by this function must be freed with SDL_aligned_free(),
  852. * _not_ SDL_free().
  853. *
  854. * If `alignment` is less than the size of `void *`, it will be increased to
  855. * match that.
  856. *
  857. * The returned memory address will be a multiple of the alignment value, and
  858. * the size of the memory allocated will be a multiple of the alignment value.
  859. *
  860. * \param alignment the alignment of the memory.
  861. * \param size the size to allocate.
  862. * \returns a pointer to the aligned memory, or NULL if allocation failed.
  863. *
  864. * \threadsafety It is safe to call this function from any thread.
  865. *
  866. * \since This function is available since SDL 3.0.0.
  867. *
  868. * \sa SDL_aligned_free
  869. */
  870. extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  871. /**
  872. * Free memory allocated by SDL_aligned_alloc().
  873. *
  874. * The pointer is no longer valid after this call and cannot be dereferenced
  875. * anymore.
  876. *
  877. * If `mem` is NULL, this function does nothing.
  878. *
  879. * \param mem a pointer previously returned by SDL_aligned_alloc(), or NULL.
  880. *
  881. * \threadsafety It is safe to call this function from any thread.
  882. *
  883. * \since This function is available since SDL 3.0.0.
  884. *
  885. * \sa SDL_aligned_alloc
  886. */
  887. extern SDL_DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  888. /**
  889. * Get the number of outstanding (unfreed) allocations.
  890. *
  891. * \returns the number of allocations.
  892. *
  893. * \threadsafety It is safe to call this function from any thread.
  894. *
  895. * \since This function is available since SDL 3.0.0.
  896. */
  897. extern SDL_DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  898. /**
  899. * A thread-safe set of environment variables
  900. *
  901. * \since This struct is available since SDL 3.0.0.
  902. *
  903. * \sa SDL_GetEnvironment
  904. * \sa SDL_CreateEnvironment
  905. * \sa SDL_GetEnvironmentVariable
  906. * \sa SDL_GetEnvironmentVariables
  907. * \sa SDL_SetEnvironmentVariable
  908. * \sa SDL_UnsetEnvironmentVariable
  909. * \sa SDL_DestroyEnvironment
  910. */
  911. typedef struct SDL_Environment SDL_Environment;
  912. /**
  913. * Get the process environment.
  914. *
  915. * This is initialized at application start and is not affected by setenv()
  916. * and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
  917. * SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
  918. * SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
  919. * in the C runtime environment after SDL_Quit().
  920. *
  921. * \returns a pointer to the environment for the process or NULL on failure;
  922. * call SDL_GetError() for more information.
  923. *
  924. * \threadsafety It is safe to call this function from any thread.
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_GetEnvironmentVariable
  929. * \sa SDL_GetEnvironmentVariables
  930. * \sa SDL_SetEnvironmentVariable
  931. * \sa SDL_UnsetEnvironmentVariable
  932. */
  933. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_GetEnvironment(void);
  934. /**
  935. * Create a set of environment variables
  936. *
  937. * \param populated true to initialize it from the C runtime environment,
  938. * false to create an empty environment.
  939. * \returns a pointer to the new environment or NULL on failure; call
  940. * SDL_GetError() for more information.
  941. *
  942. * \threadsafety If `populated` is false, it is safe to call this function
  943. * from any thread, otherwise it is safe if no other threads are
  944. * calling setenv() or unsetenv()
  945. *
  946. * \since This function is available since SDL 3.0.0.
  947. *
  948. * \sa SDL_GetEnvironmentVariable
  949. * \sa SDL_GetEnvironmentVariables
  950. * \sa SDL_SetEnvironmentVariable
  951. * \sa SDL_UnsetEnvironmentVariable
  952. * \sa SDL_DestroyEnvironment
  953. */
  954. extern SDL_DECLSPEC SDL_Environment * SDLCALL SDL_CreateEnvironment(bool populated);
  955. /**
  956. * Get the value of a variable in the environment.
  957. *
  958. * \param env the environment to query.
  959. * \param name the name of the variable to get.
  960. * \returns a pointer to the value of the variable or NULL if it can't be
  961. * found.
  962. *
  963. * \threadsafety It is safe to call this function from any thread.
  964. *
  965. * \since This function is available since SDL 3.0.0.
  966. *
  967. * \sa SDL_GetEnvironment
  968. * \sa SDL_CreateEnvironment
  969. * \sa SDL_GetEnvironmentVariables
  970. * \sa SDL_SetEnvironmentVariable
  971. * \sa SDL_UnsetEnvironmentVariable
  972. */
  973. extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name);
  974. /**
  975. * Get all variables in the environment.
  976. *
  977. * \param env the environment to query.
  978. * \returns a NULL terminated array of pointers to environment variables in
  979. * the form "variable=value" or NULL on failure; call SDL_GetError()
  980. * for more information. This is a single allocation that should be
  981. * freed with SDL_free() when it is no longer needed.
  982. *
  983. * \threadsafety It is safe to call this function from any thread.
  984. *
  985. * \since This function is available since SDL 3.0.0.
  986. *
  987. * \sa SDL_GetEnvironment
  988. * \sa SDL_CreateEnvironment
  989. * \sa SDL_GetEnvironmentVariables
  990. * \sa SDL_SetEnvironmentVariable
  991. * \sa SDL_UnsetEnvironmentVariable
  992. */
  993. extern SDL_DECLSPEC char ** SDLCALL SDL_GetEnvironmentVariables(SDL_Environment *env);
  994. /**
  995. * Set the value of a variable in the environment.
  996. *
  997. * \param env the environment to modify.
  998. * \param name the name of the variable to set.
  999. * \param value the value of the variable to set.
  1000. * \param overwrite true to overwrite the variable if it exists, false to
  1001. * return success without setting the variable if it already
  1002. * exists.
  1003. * \returns true on success or false on failure; call SDL_GetError() for more
  1004. * information.
  1005. *
  1006. * \threadsafety It is safe to call this function from any thread.
  1007. *
  1008. * \since This function is available since SDL 3.0.0.
  1009. *
  1010. * \sa SDL_GetEnvironment
  1011. * \sa SDL_CreateEnvironment
  1012. * \sa SDL_GetEnvironmentVariable
  1013. * \sa SDL_GetEnvironmentVariables
  1014. * \sa SDL_UnsetEnvironmentVariable
  1015. */
  1016. extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite);
  1017. /**
  1018. * Clear a variable from the environment.
  1019. *
  1020. * \param env the environment to modify.
  1021. * \param name the name of the variable to unset.
  1022. * \returns true on success or false on failure; call SDL_GetError() for more
  1023. * information.
  1024. *
  1025. * \threadsafety It is safe to call this function from any thread.
  1026. *
  1027. * \since This function is available since SDL 3.0.0.
  1028. *
  1029. * \sa SDL_GetEnvironment
  1030. * \sa SDL_CreateEnvironment
  1031. * \sa SDL_GetEnvironmentVariable
  1032. * \sa SDL_GetEnvironmentVariables
  1033. * \sa SDL_SetEnvironmentVariable
  1034. * \sa SDL_UnsetEnvironmentVariable
  1035. */
  1036. extern SDL_DECLSPEC bool SDLCALL SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name);
  1037. /**
  1038. * Destroy a set of environment variables.
  1039. *
  1040. * \param env the environment to destroy.
  1041. *
  1042. * \threadsafety It is safe to call this function from any thread, as long as
  1043. * the environment is no longer in use.
  1044. *
  1045. * \since This function is available since SDL 3.0.0.
  1046. *
  1047. * \sa SDL_CreateEnvironment
  1048. */
  1049. extern SDL_DECLSPEC void SDLCALL SDL_DestroyEnvironment(SDL_Environment *env);
  1050. /**
  1051. * Get the value of a variable in the environment.
  1052. *
  1053. * This function uses SDL's cached copy of the environment and is thread-safe.
  1054. *
  1055. * \param name the name of the variable to get.
  1056. * \returns a pointer to the value of the variable or NULL if it can't be
  1057. * found.
  1058. *
  1059. * \threadsafety It is safe to call this function from any thread.
  1060. *
  1061. * \since This function is available since SDL 3.0.0.
  1062. */
  1063. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv(const char *name);
  1064. /**
  1065. * Get the value of a variable in the environment.
  1066. *
  1067. * This function bypasses SDL's cached copy of the environment and is not
  1068. * thread-safe.
  1069. *
  1070. * \param name the name of the variable to get.
  1071. * \returns a pointer to the value of the variable or NULL if it can't be
  1072. * found.
  1073. *
  1074. * \threadsafety This function is not thread safe, consider using SDL_getenv()
  1075. * instead.
  1076. *
  1077. * \since This function is available since SDL 3.0.0.
  1078. *
  1079. * \sa SDL_getenv
  1080. */
  1081. extern SDL_DECLSPEC const char * SDLCALL SDL_getenv_unsafe(const char *name);
  1082. /**
  1083. * Set the value of a variable in the environment.
  1084. *
  1085. * \param name the name of the variable to set.
  1086. * \param value the value of the variable to set.
  1087. * \param overwrite 1 to overwrite the variable if it exists, 0 to return
  1088. * success without setting the variable if it already exists.
  1089. * \returns 0 on success, -1 on error.
  1090. *
  1091. * \threadsafety This function is not thread safe, consider using
  1092. * SDL_SetEnvironmentVariable() instead.
  1093. *
  1094. * \since This function is available since SDL 3.0.0.
  1095. *
  1096. * \sa SDL_SetEnvironmentVariable
  1097. */
  1098. extern SDL_DECLSPEC int SDLCALL SDL_setenv_unsafe(const char *name, const char *value, int overwrite);
  1099. /**
  1100. * Clear a variable from the environment.
  1101. *
  1102. * \param name the name of the variable to unset.
  1103. * \returns 0 on success, -1 on error.
  1104. *
  1105. * \threadsafety This function is not thread safe, consider using
  1106. * SDL_UnsetEnvironmentVariable() instead.
  1107. *
  1108. * \since This function is available since SDL 3.0.0.
  1109. *
  1110. * \sa SDL_UnsetEnvironmentVariable
  1111. */
  1112. extern SDL_DECLSPEC int SDLCALL SDL_unsetenv_unsafe(const char *name);
  1113. typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);
  1114. extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1115. extern SDL_DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);
  1116. typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
  1117. extern SDL_DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata);
  1118. 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);
  1119. extern SDL_DECLSPEC int SDLCALL SDL_abs(int x);
  1120. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  1121. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  1122. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  1123. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  1124. /**
  1125. * Query if a character is alphabetic (a letter).
  1126. *
  1127. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1128. * for English 'a-z' and 'A-Z' as true.
  1129. *
  1130. * \param x character value to check.
  1131. * \returns non-zero if x falls within the character class, zero otherwise.
  1132. *
  1133. * \threadsafety It is safe to call this function from any thread.
  1134. *
  1135. * \since This function is available since SDL 3.0.0.
  1136. */
  1137. extern SDL_DECLSPEC int SDLCALL SDL_isalpha(int x);
  1138. /**
  1139. * Query if a character is alphabetic (a letter) or a number.
  1140. *
  1141. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1142. * for English 'a-z', 'A-Z', and '0-9' as true.
  1143. *
  1144. * \param x character value to check.
  1145. * \returns non-zero if x falls within the character class, zero otherwise.
  1146. *
  1147. * \threadsafety It is safe to call this function from any thread.
  1148. *
  1149. * \since This function is available since SDL 3.0.0.
  1150. */
  1151. extern SDL_DECLSPEC int SDLCALL SDL_isalnum(int x);
  1152. /**
  1153. * Report if a character is blank (a space or tab).
  1154. *
  1155. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1156. * 0x20 (space) or 0x9 (tab) as true.
  1157. *
  1158. * \param x character value to check.
  1159. * \returns non-zero if x falls within the character class, zero otherwise.
  1160. *
  1161. * \threadsafety It is safe to call this function from any thread.
  1162. *
  1163. * \since This function is available since SDL 3.0.0.
  1164. */
  1165. extern SDL_DECLSPEC int SDLCALL SDL_isblank(int x);
  1166. /**
  1167. * Report if a character is a control character.
  1168. *
  1169. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1170. * 0 through 0x1F, and 0x7F, as true.
  1171. *
  1172. * \param x character value to check.
  1173. * \returns non-zero if x falls within the character class, zero otherwise.
  1174. *
  1175. * \threadsafety It is safe to call this function from any thread.
  1176. *
  1177. * \since This function is available since SDL 3.0.0.
  1178. */
  1179. extern SDL_DECLSPEC int SDLCALL SDL_iscntrl(int x);
  1180. /**
  1181. * Report if a character is a numeric digit.
  1182. *
  1183. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1184. * '0' (0x30) through '9' (0x39), as true.
  1185. *
  1186. * \param x character value to check.
  1187. * \returns non-zero if x falls within the character class, zero otherwise.
  1188. *
  1189. * \threadsafety It is safe to call this function from any thread.
  1190. *
  1191. * \since This function is available since SDL 3.0.0.
  1192. */
  1193. extern SDL_DECLSPEC int SDLCALL SDL_isdigit(int x);
  1194. /**
  1195. * Report if a character is a hexadecimal digit.
  1196. *
  1197. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1198. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  1199. *
  1200. * \param x character value to check.
  1201. * \returns non-zero if x falls within the character class, zero otherwise.
  1202. *
  1203. * \threadsafety It is safe to call this function from any thread.
  1204. *
  1205. * \since This function is available since SDL 3.0.0.
  1206. */
  1207. extern SDL_DECLSPEC int SDLCALL SDL_isxdigit(int x);
  1208. /**
  1209. * Report if a character is a punctuation mark.
  1210. *
  1211. * **WARNING**: Regardless of system locale, this is equivalent to
  1212. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  1213. *
  1214. * \param x character value to check.
  1215. * \returns non-zero if x falls within the character class, zero otherwise.
  1216. *
  1217. * \threadsafety It is safe to call this function from any thread.
  1218. *
  1219. * \since This function is available since SDL 3.0.0.
  1220. *
  1221. * \sa SDL_isgraph
  1222. * \sa SDL_isalnum
  1223. */
  1224. extern SDL_DECLSPEC int SDLCALL SDL_ispunct(int x);
  1225. /**
  1226. * Report if a character is whitespace.
  1227. *
  1228. * **WARNING**: Regardless of system locale, this will only treat the
  1229. * following ASCII values as true:
  1230. *
  1231. * - space (0x20)
  1232. * - tab (0x09)
  1233. * - newline (0x0A)
  1234. * - vertical tab (0x0B)
  1235. * - form feed (0x0C)
  1236. * - return (0x0D)
  1237. *
  1238. * \param x character value to check.
  1239. * \returns non-zero if x falls within the character class, zero otherwise.
  1240. *
  1241. * \threadsafety It is safe to call this function from any thread.
  1242. *
  1243. * \since This function is available since SDL 3.0.0.
  1244. */
  1245. extern SDL_DECLSPEC int SDLCALL SDL_isspace(int x);
  1246. /**
  1247. * Report if a character is upper case.
  1248. *
  1249. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1250. * 'A' through 'Z' as true.
  1251. *
  1252. * \param x character value to check.
  1253. * \returns non-zero if x falls within the character class, zero otherwise.
  1254. *
  1255. * \threadsafety It is safe to call this function from any thread.
  1256. *
  1257. * \since This function is available since SDL 3.0.0.
  1258. */
  1259. extern SDL_DECLSPEC int SDLCALL SDL_isupper(int x);
  1260. /**
  1261. * Report if a character is lower case.
  1262. *
  1263. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1264. * 'a' through 'z' as true.
  1265. *
  1266. * \param x character value to check.
  1267. * \returns non-zero if x falls within the character class, zero otherwise.
  1268. *
  1269. * \threadsafety It is safe to call this function from any thread.
  1270. *
  1271. * \since This function is available since SDL 3.0.0.
  1272. */
  1273. extern SDL_DECLSPEC int SDLCALL SDL_islower(int x);
  1274. /**
  1275. * Report if a character is "printable".
  1276. *
  1277. * Be advised that "printable" has a definition that goes back to text
  1278. * terminals from the dawn of computing, making this a sort of special case
  1279. * function that is not suitable for Unicode (or most any) text management.
  1280. *
  1281. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  1282. * ' ' (0x20) through '~' (0x7E) as true.
  1283. *
  1284. * \param x character value to check.
  1285. * \returns non-zero if x falls within the character class, zero otherwise.
  1286. *
  1287. * \threadsafety It is safe to call this function from any thread.
  1288. *
  1289. * \since This function is available since SDL 3.0.0.
  1290. */
  1291. extern SDL_DECLSPEC int SDLCALL SDL_isprint(int x);
  1292. /**
  1293. * Report if a character is any "printable" except space.
  1294. *
  1295. * Be advised that "printable" has a definition that goes back to text
  1296. * terminals from the dawn of computing, making this a sort of special case
  1297. * function that is not suitable for Unicode (or most any) text management.
  1298. *
  1299. * **WARNING**: Regardless of system locale, this is equivalent to
  1300. * `(SDL_isprint(x)) && ((x) != ' ')`.
  1301. *
  1302. * \param x character value to check.
  1303. * \returns non-zero if x falls within the character class, zero otherwise.
  1304. *
  1305. * \threadsafety It is safe to call this function from any thread.
  1306. *
  1307. * \since This function is available since SDL 3.0.0.
  1308. *
  1309. * \sa SDL_isprint
  1310. */
  1311. extern SDL_DECLSPEC int SDLCALL SDL_isgraph(int x);
  1312. /**
  1313. * Convert low-ASCII English letters to uppercase.
  1314. *
  1315. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1316. * values 'a' through 'z' to uppercase.
  1317. *
  1318. * This function returns the uppercase equivalent of `x`. If a character
  1319. * cannot be converted, or is already uppercase, this function returns `x`.
  1320. *
  1321. * \param x character value to check.
  1322. * \returns capitalized version of x, or x if no conversion available.
  1323. *
  1324. * \threadsafety It is safe to call this function from any thread.
  1325. *
  1326. * \since This function is available since SDL 3.0.0.
  1327. */
  1328. extern SDL_DECLSPEC int SDLCALL SDL_toupper(int x);
  1329. /**
  1330. * Convert low-ASCII English letters to lowercase.
  1331. *
  1332. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1333. * values 'A' through 'Z' to lowercase.
  1334. *
  1335. * This function returns the lowercase equivalent of `x`. If a character
  1336. * cannot be converted, or is already lowercase, this function returns `x`.
  1337. *
  1338. * \param x character value to check.
  1339. * \returns lowercase version of x, or x if no conversion available.
  1340. *
  1341. * \threadsafety It is safe to call this function from any thread.
  1342. *
  1343. * \since This function is available since SDL 3.0.0.
  1344. */
  1345. extern SDL_DECLSPEC int SDLCALL SDL_tolower(int x);
  1346. extern SDL_DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  1347. extern SDL_DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  1348. /**
  1349. * Copy non-overlapping memory.
  1350. *
  1351. * The memory regions must not overlap. If they do, use SDL_memmove() instead.
  1352. *
  1353. * \param dst The destination memory region. Must not be NULL, and must not
  1354. * overlap with `src`.
  1355. * \param src The source memory region. Must not be NULL, and must not overlap
  1356. * with `dst`.
  1357. * \param len The length in bytes of both `dst` and `src`.
  1358. * \returns `dst`.
  1359. *
  1360. * \threadsafety It is safe to call this function from any thread.
  1361. *
  1362. * \since This function is available since SDL 3.0.0.
  1363. *
  1364. * \sa SDL_memmove
  1365. */
  1366. extern SDL_DECLSPEC void * SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  1367. /* Take advantage of compiler optimizations for memcpy */
  1368. #ifndef SDL_SLOW_MEMCPY
  1369. #ifdef SDL_memcpy
  1370. #undef SDL_memcpy
  1371. #endif
  1372. #define SDL_memcpy memcpy
  1373. #endif
  1374. #define SDL_copyp(dst, src) \
  1375. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  1376. SDL_memcpy((dst), (src), sizeof(*(src)))
  1377. /**
  1378. * Copy memory.
  1379. *
  1380. * It is okay for the memory regions to overlap. If you are confident that the
  1381. * regions never overlap, using SDL_memcpy() may improve performance.
  1382. *
  1383. * \param dst The destination memory region. Must not be NULL.
  1384. * \param src The source memory region. Must not be NULL.
  1385. * \param len The length in bytes of both `dst` and `src`.
  1386. * \returns `dst`.
  1387. *
  1388. * \threadsafety It is safe to call this function from any thread.
  1389. *
  1390. * \since This function is available since SDL 3.0.0.
  1391. *
  1392. * \sa SDL_memcpy
  1393. */
  1394. extern SDL_DECLSPEC void * SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  1395. /* Take advantage of compiler optimizations for memmove */
  1396. #ifndef SDL_SLOW_MEMMOVE
  1397. #ifdef SDL_memmove
  1398. #undef SDL_memmove
  1399. #endif
  1400. #define SDL_memmove memmove
  1401. #endif
  1402. extern SDL_DECLSPEC void * SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  1403. extern SDL_DECLSPEC void * SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  1404. /* Take advantage of compiler optimizations for memset */
  1405. #ifndef SDL_SLOW_MEMSET
  1406. #ifdef SDL_memset
  1407. #undef SDL_memset
  1408. #endif
  1409. #define SDL_memset memset
  1410. #endif
  1411. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  1412. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  1413. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  1414. extern SDL_DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  1415. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  1416. extern SDL_DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  1417. /**
  1418. * Copy a wide string.
  1419. *
  1420. * This function copies `maxlen` - 1 wide characters from `src` to `dst`, then
  1421. * appends a null terminator.
  1422. *
  1423. * `src` and `dst` must not overlap.
  1424. *
  1425. * If `maxlen` is 0, no wide characters are copied and no null terminator is
  1426. * written.
  1427. *
  1428. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1429. * with `src`.
  1430. * \param src The null-terminated wide string to copy. Must not be NULL, and
  1431. * must not overlap with `dst`.
  1432. * \param maxlen The length (in wide characters) of the destination buffer.
  1433. * \returns The length (in wide characters, excluding the null terminator) of
  1434. * `src`.
  1435. *
  1436. * \threadsafety It is safe to call this function from any thread.
  1437. *
  1438. * \since This function is available since SDL 3.0.0.
  1439. *
  1440. * \sa SDL_wcslcat
  1441. */
  1442. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1443. /**
  1444. * Concatenate wide strings.
  1445. *
  1446. * This function appends up to `maxlen` - SDL_wcslen(dst) - 1 wide characters
  1447. * from `src` to the end of the wide string in `dst`, then appends a null
  1448. * terminator.
  1449. *
  1450. * `src` and `dst` must not overlap.
  1451. *
  1452. * If `maxlen` - SDL_wcslen(dst) - 1 is less than or equal to 0, then `dst` is
  1453. * unmodified.
  1454. *
  1455. * \param dst The destination buffer already containing the first
  1456. * null-terminated wide string. Must not be NULL and must not
  1457. * overlap with `src`.
  1458. * \param src The second null-terminated wide string. Must not be NULL, and
  1459. * must not overlap with `dst`.
  1460. * \param maxlen The length (in wide characters) of the destination buffer.
  1461. * \returns The length (in wide characters, excluding the null terminator) of
  1462. * the string in `dst` plus the length of `src`.
  1463. *
  1464. * \threadsafety It is safe to call this function from any thread.
  1465. *
  1466. * \since This function is available since SDL 3.0.0.
  1467. *
  1468. * \sa SDL_wcslcpy
  1469. */
  1470. extern SDL_DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  1471. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsdup(const wchar_t *wstr);
  1472. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  1473. extern SDL_DECLSPEC wchar_t * SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  1474. /**
  1475. * Compare two null-terminated wide strings.
  1476. *
  1477. * This only compares wchar_t values until it hits a null-terminating
  1478. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  1479. * depending on your platform's wchar_t size), or uses valid Unicode values.
  1480. *
  1481. * \param str1 the first string to compare. NULL is not permitted!
  1482. * \param str2 the second string to compare. NULL is not permitted!
  1483. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1484. * str1 is "greater than" str2, and zero if the strings match
  1485. * exactly.
  1486. *
  1487. * \threadsafety It is safe to call this function from any thread.
  1488. *
  1489. * \since This function is available since SDL 3.0.0.
  1490. */
  1491. extern SDL_DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  1492. /**
  1493. * Compare two wide strings up to a number of wchar_t values.
  1494. *
  1495. * This only compares wchar_t values; it does not care if the string is
  1496. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  1497. * or uses valid Unicode values.
  1498. *
  1499. * Note that while this function is intended to be used with UTF-16 (or
  1500. * UTF-32, depending on your platform's definition of wchar_t), it is
  1501. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  1502. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  1503. * sequence, it will only compare a portion of the final character.
  1504. *
  1505. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  1506. * match to this number of wide chars (or both have matched to a
  1507. * null-terminator character before this count), they will be considered
  1508. * equal.
  1509. *
  1510. * \param str1 the first string to compare. NULL is not permitted!
  1511. * \param str2 the second string to compare. NULL is not permitted!
  1512. * \param maxlen the maximum number of wchar_t to compare.
  1513. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1514. * str1 is "greater than" str2, and zero if the strings match
  1515. * exactly.
  1516. *
  1517. * \threadsafety It is safe to call this function from any thread.
  1518. *
  1519. * \since This function is available since SDL 3.0.0.
  1520. */
  1521. extern SDL_DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1522. /**
  1523. * Compare two null-terminated wide strings, case-insensitively.
  1524. *
  1525. * This will work with Unicode strings, using a technique called
  1526. * "case-folding" to handle the vast majority of case-sensitive human
  1527. * languages regardless of system locale. It can deal with expanding values: a
  1528. * German Eszett character can compare against two ASCII 's' chars and be
  1529. * considered a match, for example. A notable exception: it does not handle
  1530. * the Turkish 'i' character; human language is complicated!
  1531. *
  1532. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1533. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1534. * handles Unicode, it expects the string to be well-formed and not a
  1535. * null-terminated string of arbitrary bytes. Characters that are not valid
  1536. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1537. * CHARACTER), which is to say two strings of random bits may turn out to
  1538. * match if they convert to the same amount of replacement characters.
  1539. *
  1540. * \param str1 the first string to compare. NULL is not permitted!
  1541. * \param str2 the second string to compare. NULL is not permitted!
  1542. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1543. * str1 is "greater than" str2, and zero if the strings match
  1544. * exactly.
  1545. *
  1546. * \threadsafety It is safe to call this function from any thread.
  1547. *
  1548. * \since This function is available since SDL 3.0.0.
  1549. */
  1550. extern SDL_DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  1551. /**
  1552. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  1553. *
  1554. * This will work with Unicode strings, using a technique called
  1555. * "case-folding" to handle the vast majority of case-sensitive human
  1556. * languages regardless of system locale. It can deal with expanding values: a
  1557. * German Eszett character can compare against two ASCII 's' chars and be
  1558. * considered a match, for example. A notable exception: it does not handle
  1559. * the Turkish 'i' character; human language is complicated!
  1560. *
  1561. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  1562. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  1563. * handles Unicode, it expects the string to be well-formed and not a
  1564. * null-terminated string of arbitrary bytes. Characters that are not valid
  1565. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  1566. * CHARACTER), which is to say two strings of random bits may turn out to
  1567. * match if they convert to the same amount of replacement characters.
  1568. *
  1569. * Note that while this function might deal with variable-sized characters,
  1570. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  1571. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  1572. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  1573. * to overflow a buffer.
  1574. *
  1575. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  1576. * strings match to this number of wchar_t (or both have matched to a
  1577. * null-terminator character before this number of bytes), they will be
  1578. * considered equal.
  1579. *
  1580. * \param str1 the first string to compare. NULL is not permitted!
  1581. * \param str2 the second string to compare. NULL is not permitted!
  1582. * \param maxlen the maximum number of wchar_t values to compare.
  1583. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1584. * str1 is "greater than" str2, and zero if the strings match
  1585. * exactly.
  1586. *
  1587. * \threadsafety It is safe to call this function from any thread.
  1588. *
  1589. * \since This function is available since SDL 3.0.0.
  1590. */
  1591. extern SDL_DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  1592. /**
  1593. * Parse a `long` from a wide string.
  1594. *
  1595. * If `str` starts with whitespace, then those whitespace characters are
  1596. * skipped before attempting to parse the number.
  1597. *
  1598. * If the parsed number does not fit inside a `long`, the result is clamped to
  1599. * the minimum and maximum representable `long` values.
  1600. *
  1601. * \param str The null-terminated wide string to read. Must not be NULL.
  1602. * \param endp If not NULL, the address of the first invalid wide character
  1603. * (i.e. the next character after the parsed number) will be
  1604. * written to this pointer.
  1605. * \param base The base of the integer to read. Supported values are 0 and 2
  1606. * to 36 inclusive. If 0, the base will be inferred from the
  1607. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1608. * otherwise).
  1609. * \returns The parsed `long`, or 0 if no number could be parsed.
  1610. *
  1611. * \threadsafety It is safe to call this function from any thread.
  1612. *
  1613. * \since This function is available since SDL 3.0.0.
  1614. *
  1615. * \sa SDL_strtol
  1616. */
  1617. extern SDL_DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  1618. extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  1619. extern SDL_DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  1620. /**
  1621. * Copy a string.
  1622. *
  1623. * This function copies up to `maxlen` - 1 characters from `src` to `dst`,
  1624. * then appends a null terminator.
  1625. *
  1626. * If `maxlen` is 0, no characters are copied and no null terminator is
  1627. * written.
  1628. *
  1629. * If you want to copy an UTF-8 string but need to ensure that multi-byte
  1630. * sequences are not truncated, consider using SDL_utf8strlcpy().
  1631. *
  1632. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1633. * with `src`.
  1634. * \param src The null-terminated string to copy. Must not be NULL, and must
  1635. * not overlap with `dst`.
  1636. * \param maxlen The length (in characters) of the destination buffer.
  1637. * \returns The length (in characters, excluding the null terminator) of
  1638. * `src`.
  1639. *
  1640. * \threadsafety It is safe to call this function from any thread.
  1641. *
  1642. * \since This function is available since SDL 3.0.0.
  1643. *
  1644. * \sa SDL_strlcat
  1645. * \sa SDL_utf8strlcpy
  1646. */
  1647. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1648. /**
  1649. * Copy an UTF-8 string.
  1650. *
  1651. * This function copies up to `dst_bytes` - 1 bytes from `src` to `dst` while
  1652. * also ensuring that the string written to `dst` does not end in a truncated
  1653. * multi-byte sequence. Finally, it appends a null terminator.
  1654. *
  1655. * `src` and `dst` must not overlap.
  1656. *
  1657. * Note that unlike SDL_strlcpy(), this function returns the number of bytes
  1658. * written, not the length of `src`.
  1659. *
  1660. * \param dst The destination buffer. Must not be NULL, and must not overlap
  1661. * with `src`.
  1662. * \param src The null-terminated UTF-8 string to copy. Must not be NULL, and
  1663. * must not overlap with `dst`.
  1664. * \param dst_bytes The length (in bytes) of the destination buffer. Must not
  1665. * be 0.
  1666. * \returns The number of bytes written, excluding the null terminator.
  1667. *
  1668. * \threadsafety It is safe to call this function from any thread.
  1669. *
  1670. * \since This function is available since SDL 3.0.0.
  1671. *
  1672. * \sa SDL_strlcpy
  1673. */
  1674. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  1675. /**
  1676. * Concatenate strings.
  1677. *
  1678. * This function appends up to `maxlen` - SDL_strlen(dst) - 1 characters from
  1679. * `src` to the end of the string in `dst`, then appends a null terminator.
  1680. *
  1681. * `src` and `dst` must not overlap.
  1682. *
  1683. * If `maxlen` - SDL_strlen(dst) - 1 is less than or equal to 0, then `dst` is
  1684. * unmodified.
  1685. *
  1686. * \param dst The destination buffer already containing the first
  1687. * null-terminated string. Must not be NULL and must not overlap
  1688. * with `src`.
  1689. * \param src The second null-terminated string. Must not be NULL, and must
  1690. * not overlap with `dst`.
  1691. * \param maxlen The length (in characters) of the destination buffer.
  1692. * \returns The length (in characters, excluding the null terminator) of the
  1693. * string in `dst` plus the length of `src`.
  1694. *
  1695. * \threadsafety It is safe to call this function from any thread.
  1696. *
  1697. * \since This function is available since SDL 3.0.0.
  1698. *
  1699. * \sa SDL_strlcpy
  1700. */
  1701. extern SDL_DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  1702. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str);
  1703. extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen);
  1704. extern SDL_DECLSPEC char * SDLCALL SDL_strrev(char *str);
  1705. /**
  1706. * Convert a string to uppercase.
  1707. *
  1708. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1709. * values 'A' through 'Z' to uppercase.
  1710. *
  1711. * This function operates on a null-terminated string of bytes--even if it is
  1712. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  1713. * uppercase equivalents in-place, returning the original `str` pointer.
  1714. *
  1715. * \param str the string to convert in-place. Can not be NULL.
  1716. * \returns the `str` pointer passed into this function.
  1717. *
  1718. * \threadsafety It is safe to call this function from any thread.
  1719. *
  1720. * \since This function is available since SDL 3.0.0.
  1721. *
  1722. * \sa SDL_strlwr
  1723. */
  1724. extern SDL_DECLSPEC char * SDLCALL SDL_strupr(char *str);
  1725. /**
  1726. * Convert a string to lowercase.
  1727. *
  1728. * **WARNING**: Regardless of system locale, this will only convert ASCII
  1729. * values 'A' through 'Z' to lowercase.
  1730. *
  1731. * This function operates on a null-terminated string of bytes--even if it is
  1732. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  1733. * lowercase equivalents in-place, returning the original `str` pointer.
  1734. *
  1735. * \param str the string to convert in-place. Can not be NULL.
  1736. * \returns the `str` pointer passed into this function.
  1737. *
  1738. * \threadsafety It is safe to call this function from any thread.
  1739. *
  1740. * \since This function is available since SDL 3.0.0.
  1741. *
  1742. * \sa SDL_strupr
  1743. */
  1744. extern SDL_DECLSPEC char * SDLCALL SDL_strlwr(char *str);
  1745. extern SDL_DECLSPEC char * SDLCALL SDL_strchr(const char *str, int c);
  1746. extern SDL_DECLSPEC char * SDLCALL SDL_strrchr(const char *str, int c);
  1747. extern SDL_DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
  1748. extern SDL_DECLSPEC char * SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  1749. extern SDL_DECLSPEC char * SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  1750. extern SDL_DECLSPEC char * SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
  1751. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  1752. extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  1753. extern SDL_DECLSPEC char * SDLCALL SDL_itoa(int value, char *str, int radix);
  1754. extern SDL_DECLSPEC char * SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  1755. extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix);
  1756. extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  1757. extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int radix);
  1758. extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix);
  1759. /**
  1760. * Parse an `int` from a string.
  1761. *
  1762. * The result of calling `SDL_atoi(str)` is equivalent to
  1763. * `(int)SDL_strtol(str, NULL, 10)`.
  1764. *
  1765. * \param str The null-terminated string to read. Must not be NULL.
  1766. * \returns The parsed `int`.
  1767. *
  1768. * \threadsafety It is safe to call this function from any thread.
  1769. *
  1770. * \since This function is available since SDL 3.0.0.
  1771. *
  1772. * \sa SDL_atof
  1773. * \sa SDL_strtol
  1774. * \sa SDL_strtoul
  1775. * \sa SDL_strtoll
  1776. * \sa SDL_strtoull
  1777. * \sa SDL_strtod
  1778. * \sa SDL_itoa
  1779. */
  1780. extern SDL_DECLSPEC int SDLCALL SDL_atoi(const char *str);
  1781. /**
  1782. * Parse a `double` from a string.
  1783. *
  1784. * The result of calling `SDL_atof(str)` is equivalent to `SDL_strtod(str,
  1785. * NULL)`.
  1786. *
  1787. * \param str The null-terminated string to read. Must not be NULL.
  1788. * \returns The parsed `double`.
  1789. *
  1790. * \threadsafety It is safe to call this function from any thread.
  1791. *
  1792. * \since This function is available since SDL 3.0.0.
  1793. *
  1794. * \sa SDL_atoi
  1795. * \sa SDL_strtol
  1796. * \sa SDL_strtoul
  1797. * \sa SDL_strtoll
  1798. * \sa SDL_strtoull
  1799. * \sa SDL_strtod
  1800. */
  1801. extern SDL_DECLSPEC double SDLCALL SDL_atof(const char *str);
  1802. /**
  1803. * Parse a `long` from a string.
  1804. *
  1805. * If `str` starts with whitespace, then those whitespace characters are
  1806. * skipped before attempting to parse the number.
  1807. *
  1808. * If the parsed number does not fit inside a `long`, the result is clamped to
  1809. * the minimum and maximum representable `long` values.
  1810. *
  1811. * \param str The null-terminated string to read. Must not be NULL.
  1812. * \param endp If not NULL, the address of the first invalid character (i.e.
  1813. * the next character after the parsed number) will be written to
  1814. * this pointer.
  1815. * \param base The base of the integer to read. Supported values are 0 and 2
  1816. * to 36 inclusive. If 0, the base will be inferred from the
  1817. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1818. * otherwise).
  1819. * \returns The parsed `long`, or 0 if no number could be parsed.
  1820. *
  1821. * \threadsafety It is safe to call this function from any thread.
  1822. *
  1823. * \since This function is available since SDL 3.0.0.
  1824. *
  1825. * \sa SDL_atoi
  1826. * \sa SDL_atof
  1827. * \sa SDL_strtoul
  1828. * \sa SDL_strtoll
  1829. * \sa SDL_strtoull
  1830. * \sa SDL_strtod
  1831. * \sa SDL_ltoa
  1832. * \sa SDL_wcstol
  1833. */
  1834. extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  1835. /**
  1836. * Parse an `unsigned long` from a string.
  1837. *
  1838. * If `str` starts with whitespace, then those whitespace characters are
  1839. * skipped before attempting to parse the number.
  1840. *
  1841. * If the parsed number does not fit inside an `unsigned long`, the result is
  1842. * clamped to the maximum representable `unsigned long` value.
  1843. *
  1844. * \param str The null-terminated string to read. Must not be NULL.
  1845. * \param endp If not NULL, the address of the first invalid character (i.e.
  1846. * the next character after the parsed number) will be written to
  1847. * this pointer.
  1848. * \param base The base of the integer to read. Supported values are 0 and 2
  1849. * to 36 inclusive. If 0, the base will be inferred from the
  1850. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1851. * otherwise).
  1852. * \returns The parsed `unsigned long`, or 0 if no number could be parsed.
  1853. *
  1854. * \threadsafety It is safe to call this function from any thread.
  1855. *
  1856. * \since This function is available since SDL 3.0.0.
  1857. *
  1858. * \sa SDL_atoi
  1859. * \sa SDL_atof
  1860. * \sa SDL_strtol
  1861. * \sa SDL_strtoll
  1862. * \sa SDL_strtoull
  1863. * \sa SDL_strtod
  1864. * \sa SDL_ultoa
  1865. */
  1866. extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  1867. /**
  1868. * Parse a `long long` from a string.
  1869. *
  1870. * If `str` starts with whitespace, then those whitespace characters are
  1871. * skipped before attempting to parse the number.
  1872. *
  1873. * If the parsed number does not fit inside a `long long`, the result is
  1874. * clamped to the minimum and maximum representable `long long` values.
  1875. *
  1876. * \param str The null-terminated string to read. Must not be NULL.
  1877. * \param endp If not NULL, the address of the first invalid character (i.e.
  1878. * the next character after the parsed number) will be written to
  1879. * this pointer.
  1880. * \param base The base of the integer to read. Supported values are 0 and 2
  1881. * to 36 inclusive. If 0, the base will be inferred from the
  1882. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1883. * otherwise).
  1884. * \returns The parsed `long long`, or 0 if no number could be parsed.
  1885. *
  1886. * \threadsafety It is safe to call this function from any thread.
  1887. *
  1888. * \since This function is available since SDL 3.0.0.
  1889. *
  1890. * \sa SDL_atoi
  1891. * \sa SDL_atof
  1892. * \sa SDL_strtol
  1893. * \sa SDL_strtoul
  1894. * \sa SDL_strtoull
  1895. * \sa SDL_strtod
  1896. * \sa SDL_lltoa
  1897. */
  1898. extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  1899. /**
  1900. * Parse an `unsigned long long` from a string.
  1901. *
  1902. * If `str` starts with whitespace, then those whitespace characters are
  1903. * skipped before attempting to parse the number.
  1904. *
  1905. * If the parsed number does not fit inside an `unsigned long long`, the
  1906. * result is clamped to the maximum representable `unsigned long long` value.
  1907. *
  1908. * \param str The null-terminated string to read. Must not be NULL.
  1909. * \param endp If not NULL, the address of the first invalid character (i.e.
  1910. * the next character after the parsed number) will be written to
  1911. * this pointer.
  1912. * \param base The base of the integer to read. Supported values are 0 and 2
  1913. * to 36 inclusive. If 0, the base will be inferred from the
  1914. * number's prefix (0x for hexadecimal, 0 for octal, decimal
  1915. * otherwise).
  1916. * \returns The parsed `unsigned long long`, or 0 if no number could be
  1917. * parsed.
  1918. *
  1919. * \threadsafety It is safe to call this function from any thread.
  1920. *
  1921. * \since This function is available since SDL 3.0.0.
  1922. *
  1923. * \sa SDL_atoi
  1924. * \sa SDL_atof
  1925. * \sa SDL_strtol
  1926. * \sa SDL_strtoll
  1927. * \sa SDL_strtoul
  1928. * \sa SDL_strtod
  1929. * \sa SDL_ulltoa
  1930. */
  1931. extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  1932. /**
  1933. * Parse a `double` from a string.
  1934. *
  1935. * This function makes fewer guarantees than the C runtime `strtod`:
  1936. *
  1937. * - Only decimal notation is guaranteed to be supported. The handling of
  1938. * scientific and hexadecimal notation is unspecified.
  1939. * - Whether or not INF and NAN can be parsed is unspecified.
  1940. * - The precision of the result is unspecified.
  1941. *
  1942. * \param str The null-terminated string to read. Must not be NULL.
  1943. * \param endp If not NULL, the address of the first invalid character (i.e.
  1944. * the next character after the parsed number) will be written to
  1945. * this pointer.
  1946. * \returns The parsed `double`, or 0 if no number could be parsed.
  1947. *
  1948. * \threadsafety It is safe to call this function from any thread.
  1949. *
  1950. * \since This function is available since SDL 3.0.0.
  1951. *
  1952. * \sa SDL_atoi
  1953. * \sa SDL_atof
  1954. * \sa SDL_strtol
  1955. * \sa SDL_strtoll
  1956. * \sa SDL_strtoul
  1957. * \sa SDL_strtoull
  1958. */
  1959. extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  1960. /**
  1961. * Compare two null-terminated UTF-8 strings.
  1962. *
  1963. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  1964. * since effectively this function just compares bytes until it hits a
  1965. * null-terminating character. Also due to the nature of UTF-8, this can be
  1966. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  1967. *
  1968. * \param str1 the first string to compare. NULL is not permitted!
  1969. * \param str2 the second string to compare. NULL is not permitted!
  1970. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1971. * str1 is "greater than" str2, and zero if the strings match
  1972. * exactly.
  1973. *
  1974. * \threadsafety It is safe to call this function from any thread.
  1975. *
  1976. * \since This function is available since SDL 3.0.0.
  1977. */
  1978. extern SDL_DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  1979. /**
  1980. * Compare two UTF-8 strings up to a number of bytes.
  1981. *
  1982. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  1983. * since effectively this function just compares bytes until it hits a
  1984. * null-terminating character. Also due to the nature of UTF-8, this can be
  1985. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  1986. *
  1987. * Note that while this function is intended to be used with UTF-8, it is
  1988. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  1989. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  1990. * compare a portion of the final character.
  1991. *
  1992. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  1993. * match to this number of bytes (or both have matched to a null-terminator
  1994. * character before this number of bytes), they will be considered equal.
  1995. *
  1996. * \param str1 the first string to compare. NULL is not permitted!
  1997. * \param str2 the second string to compare. NULL is not permitted!
  1998. * \param maxlen the maximum number of _bytes_ to compare.
  1999. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2000. * str1 is "greater than" str2, and zero if the strings match
  2001. * exactly.
  2002. *
  2003. * \threadsafety It is safe to call this function from any thread.
  2004. *
  2005. * \since This function is available since SDL 3.0.0.
  2006. */
  2007. extern SDL_DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  2008. /**
  2009. * Compare two null-terminated UTF-8 strings, case-insensitively.
  2010. *
  2011. * This will work with Unicode strings, using a technique called
  2012. * "case-folding" to handle the vast majority of case-sensitive human
  2013. * languages regardless of system locale. It can deal with expanding values: a
  2014. * German Eszett character can compare against two ASCII 's' chars and be
  2015. * considered a match, for example. A notable exception: it does not handle
  2016. * the Turkish 'i' character; human language is complicated!
  2017. *
  2018. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  2019. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  2020. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  2021. * CHARACTER), which is to say two strings of random bits may turn out to
  2022. * match if they convert to the same amount of replacement characters.
  2023. *
  2024. * \param str1 the first string to compare. NULL is not permitted!
  2025. * \param str2 the second string to compare. NULL is not permitted!
  2026. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2027. * str1 is "greater than" str2, and zero if the strings match
  2028. * exactly.
  2029. *
  2030. * \threadsafety It is safe to call this function from any thread.
  2031. *
  2032. * \since This function is available since SDL 3.0.0.
  2033. */
  2034. extern SDL_DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  2035. /**
  2036. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  2037. *
  2038. * This will work with Unicode strings, using a technique called
  2039. * "case-folding" to handle the vast majority of case-sensitive human
  2040. * languages regardless of system locale. It can deal with expanding values: a
  2041. * German Eszett character can compare against two ASCII 's' chars and be
  2042. * considered a match, for example. A notable exception: it does not handle
  2043. * the Turkish 'i' character; human language is complicated!
  2044. *
  2045. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  2046. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  2047. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  2048. * CHARACTER), which is to say two strings of random bits may turn out to
  2049. * match if they convert to the same amount of replacement characters.
  2050. *
  2051. * Note that while this function is intended to be used with UTF-8, `maxlen`
  2052. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  2053. * UTF-8 sequence, it may convert a portion of the final character to one or
  2054. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  2055. * a buffer.
  2056. *
  2057. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  2058. * match to this number of bytes (or both have matched to a null-terminator
  2059. * character before this number of bytes), they will be considered equal.
  2060. *
  2061. * \param str1 the first string to compare. NULL is not permitted!
  2062. * \param str2 the second string to compare. NULL is not permitted!
  2063. * \param maxlen the maximum number of bytes to compare.
  2064. * \returns less than zero if str1 is "less than" str2, greater than zero if
  2065. * str1 is "greater than" str2, and zero if the strings match
  2066. * exactly.
  2067. *
  2068. * \threadsafety It is safe to call this function from any thread.
  2069. *
  2070. * \since This function is available since SDL 3.0.0.
  2071. */
  2072. extern SDL_DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  2073. /**
  2074. * Searches a string for the first occurence of any character contained in a
  2075. * breakset, and returns a pointer from the string to that character.
  2076. *
  2077. * \param str The null-terminated string to be searched. Must not be NULL, and
  2078. * must not overlap with `breakset`.
  2079. * \param breakset A null-terminated string containing the list of characters
  2080. * to look for. Must not be NULL, and must not overlap with
  2081. * `str`.
  2082. * \returns A pointer to the location, in str, of the first occurence of a
  2083. * character present in the breakset, or NULL if none is found.
  2084. *
  2085. * \threadsafety It is safe to call this function from any thread.
  2086. *
  2087. * \since This function is available since SDL 3.0.0.
  2088. */
  2089. extern SDL_DECLSPEC char * SDLCALL SDL_strpbrk(const char *str, const char *breakset);
  2090. /**
  2091. * The Unicode REPLACEMENT CHARACTER codepoint.
  2092. *
  2093. * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string
  2094. * with encoding errors.
  2095. *
  2096. * This tends to render as something like a question mark in most places.
  2097. *
  2098. * \since This macro is available since SDL 3.0.0.
  2099. *
  2100. * \sa SDL_StepUTF8
  2101. */
  2102. #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
  2103. /**
  2104. * Decode a UTF-8 string, one Unicode codepoint at a time.
  2105. *
  2106. * This will return the first Unicode codepoint in the UTF-8 encoded string in
  2107. * `*pstr`, and then advance `*pstr` past any consumed bytes before returning.
  2108. *
  2109. * It will not access more than `*pslen` bytes from the string. `*pslen` will
  2110. * be adjusted, as well, subtracting the number of bytes consumed.
  2111. *
  2112. * `pslen` is allowed to be NULL, in which case the string _must_ be
  2113. * NULL-terminated, as the function will blindly read until it sees the NULL
  2114. * char.
  2115. *
  2116. * if `*pslen` is zero, it assumes the end of string is reached and returns a
  2117. * zero codepoint regardless of the contents of the string buffer.
  2118. *
  2119. * If the resulting codepoint is zero (a NULL terminator), or `*pslen` is
  2120. * zero, it will not advance `*pstr` or `*pslen` at all.
  2121. *
  2122. * Generally this function is called in a loop until it returns zero,
  2123. * adjusting its parameters each iteration.
  2124. *
  2125. * If an invalid UTF-8 sequence is encountered, this function returns
  2126. * SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte
  2127. * (which is to say, a multibyte sequence might produce several
  2128. * SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid
  2129. * UTF-8 sequence).
  2130. *
  2131. * Several things can generate invalid UTF-8 sequences, including overlong
  2132. * encodings, the use of UTF-16 surrogate values, and truncated data. Please
  2133. * refer to
  2134. * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt)
  2135. * for details.
  2136. *
  2137. * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted.
  2138. * \param pslen a pointer to the number of bytes in the string, to be read and
  2139. * adjusted. NULL is allowed.
  2140. * \returns the first Unicode codepoint in the string.
  2141. *
  2142. * \threadsafety It is safe to call this function from any thread.
  2143. *
  2144. * \since This function is available since SDL 3.0.0.
  2145. */
  2146. extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen);
  2147. /**
  2148. * Convert a single Unicode codepoint to UTF-8.
  2149. *
  2150. * The buffer pointed to by `dst` must be at least 4 bytes long, as this
  2151. * function may generate between 1 and 4 bytes of output.
  2152. *
  2153. * This function returns the first byte _after_ the newly-written UTF-8
  2154. * sequence, which is useful for encoding multiple codepoints in a loop, or
  2155. * knowing where to write a NULL-terminator character to end the string (in
  2156. * either case, plan to have a buffer of _more_ than 4 bytes!).
  2157. *
  2158. * If `codepoint` is an invalid value (outside the Unicode range, or a UTF-16
  2159. * surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the
  2160. * codepoint instead, and not set an error.
  2161. *
  2162. * If `dst` is NULL, this returns NULL immediately without writing to the
  2163. * pointer and without setting an error.
  2164. *
  2165. * \param codepoint a Unicode codepoint to convert to UTF-8.
  2166. * \param dst the location to write the encoded UTF-8. Must point to at least
  2167. * 4 bytes!
  2168. * \returns the first byte past the newly-written UTF-8 sequence.
  2169. *
  2170. * \threadsafety It is safe to call this function from any thread.
  2171. *
  2172. * \since This function is available since SDL 3.0.0.
  2173. */
  2174. extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
  2175. extern SDL_DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  2176. 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);
  2177. 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);
  2178. 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);
  2179. 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);
  2180. 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);
  2181. extern SDL_DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  2182. extern SDL_DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  2183. /**
  2184. * Seeds the pseudo-random number generator.
  2185. *
  2186. * Reusing the seed number will cause SDL_rand_*() to repeat the same stream
  2187. * of 'random' numbers.
  2188. *
  2189. * \param seed the value to use as a random number seed, or 0 to use
  2190. * SDL_GetPerformanceCounter().
  2191. *
  2192. * \threadsafety This should be called on the same thread that calls
  2193. * SDL_rand*()
  2194. *
  2195. * \since This function is available since SDL 3.0.0.
  2196. *
  2197. * \sa SDL_rand
  2198. * \sa SDL_rand_bits
  2199. * \sa SDL_randf
  2200. */
  2201. extern SDL_DECLSPEC void SDLCALL SDL_srand(Uint64 seed);
  2202. /**
  2203. * Generate a pseudo-random number less than n for positive n
  2204. *
  2205. * The method used is faster and of better quality than `rand() % n`. Odds are
  2206. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  2207. * much worse as n gets bigger.
  2208. *
  2209. * Example: to simulate a d6 use `SDL_rand(6) + 1` The +1 converts 0..5 to
  2210. * 1..6
  2211. *
  2212. * If you want to generate a pseudo-random number in the full range of Sint32,
  2213. * you should use: (Sint32)SDL_rand_bits()
  2214. *
  2215. * If you want reproducible output, be sure to initialize with SDL_srand()
  2216. * first.
  2217. *
  2218. * There are no guarantees as to the quality of the random sequence produced,
  2219. * and this should not be used for security (cryptography, passwords) or where
  2220. * money is on the line (loot-boxes, casinos). There are many random number
  2221. * libraries available with different characteristics and you should pick one
  2222. * of those to meet any serious needs.
  2223. *
  2224. * \param n the number of possible outcomes. n must be positive.
  2225. * \returns a random value in the range of [0 .. n-1].
  2226. *
  2227. * \threadsafety All calls should be made from a single thread
  2228. *
  2229. * \since This function is available since SDL 3.0.0.
  2230. *
  2231. * \sa SDL_srand
  2232. * \sa SDL_randf
  2233. */
  2234. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand(Sint32 n);
  2235. /**
  2236. * Generate a uniform pseudo-random floating point number less than 1.0
  2237. *
  2238. * If you want reproducible output, be sure to initialize with SDL_srand()
  2239. * first.
  2240. *
  2241. * There are no guarantees as to the quality of the random sequence produced,
  2242. * and this should not be used for security (cryptography, passwords) or where
  2243. * money is on the line (loot-boxes, casinos). There are many random number
  2244. * libraries available with different characteristics and you should pick one
  2245. * of those to meet any serious needs.
  2246. *
  2247. * \returns a random value in the range of [0.0, 1.0).
  2248. *
  2249. * \threadsafety All calls should be made from a single thread
  2250. *
  2251. * \since This function is available since SDL 3.0.0.
  2252. *
  2253. * \sa SDL_srand
  2254. * \sa SDL_rand
  2255. */
  2256. extern SDL_DECLSPEC float SDLCALL SDL_randf(void);
  2257. /**
  2258. * Generate 32 pseudo-random bits.
  2259. *
  2260. * You likely want to use SDL_rand() to get a psuedo-random number instead.
  2261. *
  2262. * There are no guarantees as to the quality of the random sequence produced,
  2263. * and this should not be used for security (cryptography, passwords) or where
  2264. * money is on the line (loot-boxes, casinos). There are many random number
  2265. * libraries available with different characteristics and you should pick one
  2266. * of those to meet any serious needs.
  2267. *
  2268. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  2269. *
  2270. * \threadsafety All calls should be made from a single thread
  2271. *
  2272. * \since This function is available since SDL 3.0.0.
  2273. *
  2274. * \sa SDL_rand
  2275. * \sa SDL_randf
  2276. * \sa SDL_srand
  2277. */
  2278. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits(void);
  2279. /**
  2280. * Generate a pseudo-random number less than n for positive n
  2281. *
  2282. * The method used is faster and of better quality than `rand() % n`. Odds are
  2283. * roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and
  2284. * much worse as n gets bigger.
  2285. *
  2286. * Example: to simulate a d6 use `SDL_rand_r(state, 6) + 1` The +1 converts
  2287. * 0..5 to 1..6
  2288. *
  2289. * If you want to generate a pseudo-random number in the full range of Sint32,
  2290. * you should use: (Sint32)SDL_rand_bits_r(state)
  2291. *
  2292. * There are no guarantees as to the quality of the random sequence produced,
  2293. * and this should not be used for security (cryptography, passwords) or where
  2294. * money is on the line (loot-boxes, casinos). There are many random number
  2295. * libraries available with different characteristics and you should pick one
  2296. * of those to meet any serious needs.
  2297. *
  2298. * \param state a pointer to the current random number state, this may not be
  2299. * NULL.
  2300. * \param n the number of possible outcomes. n must be positive.
  2301. * \returns a random value in the range of [0 .. n-1].
  2302. *
  2303. * \threadsafety This function is thread-safe, as long as the state pointer
  2304. * isn't shared between threads.
  2305. *
  2306. * \since This function is available since SDL 3.0.0.
  2307. *
  2308. * \sa SDL_rand
  2309. * \sa SDL_rand_bits_r
  2310. * \sa SDL_randf_r
  2311. */
  2312. extern SDL_DECLSPEC Sint32 SDLCALL SDL_rand_r(Uint64 *state, Sint32 n);
  2313. /**
  2314. * Generate a uniform pseudo-random floating point number less than 1.0
  2315. *
  2316. * If you want reproducible output, be sure to initialize with SDL_srand()
  2317. * first.
  2318. *
  2319. * There are no guarantees as to the quality of the random sequence produced,
  2320. * and this should not be used for security (cryptography, passwords) or where
  2321. * money is on the line (loot-boxes, casinos). There are many random number
  2322. * libraries available with different characteristics and you should pick one
  2323. * of those to meet any serious needs.
  2324. *
  2325. * \param state a pointer to the current random number state, this may not be
  2326. * NULL.
  2327. * \returns a random value in the range of [0.0, 1.0).
  2328. *
  2329. * \threadsafety This function is thread-safe, as long as the state pointer
  2330. * isn't shared between threads.
  2331. *
  2332. * \since This function is available since SDL 3.0.0.
  2333. *
  2334. * \sa SDL_rand_bits_r
  2335. * \sa SDL_rand_r
  2336. * \sa SDL_randf
  2337. */
  2338. extern SDL_DECLSPEC float SDLCALL SDL_randf_r(Uint64 *state);
  2339. /**
  2340. * Generate 32 pseudo-random bits.
  2341. *
  2342. * You likely want to use SDL_rand_r() to get a psuedo-random number instead.
  2343. *
  2344. * There are no guarantees as to the quality of the random sequence produced,
  2345. * and this should not be used for security (cryptography, passwords) or where
  2346. * money is on the line (loot-boxes, casinos). There are many random number
  2347. * libraries available with different characteristics and you should pick one
  2348. * of those to meet any serious needs.
  2349. *
  2350. * \param state a pointer to the current random number state, this may not be
  2351. * NULL.
  2352. * \returns a random value in the range of [0-SDL_MAX_UINT32].
  2353. *
  2354. * \threadsafety This function is thread-safe, as long as the state pointer
  2355. * isn't shared between threads.
  2356. *
  2357. * \since This function is available since SDL 3.0.0.
  2358. *
  2359. * \sa SDL_rand_r
  2360. * \sa SDL_randf_r
  2361. */
  2362. extern SDL_DECLSPEC Uint32 SDLCALL SDL_rand_bits_r(Uint64 *state);
  2363. #ifndef SDL_PI_D
  2364. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  2365. #endif
  2366. #ifndef SDL_PI_F
  2367. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  2368. #endif
  2369. /**
  2370. * Compute the arc cosine of `x`.
  2371. *
  2372. * The definition of `y = acos(x)` is `x = cos(y)`.
  2373. *
  2374. * Domain: `-1 <= x <= 1`
  2375. *
  2376. * Range: `0 <= y <= Pi`
  2377. *
  2378. * This function operates on double-precision floating point values, use
  2379. * SDL_acosf for single-precision floats.
  2380. *
  2381. * This function may use a different approximation across different versions,
  2382. * platforms and configurations. i.e, it can return a different value given
  2383. * the same input on different machines or operating systems, or if SDL is
  2384. * updated.
  2385. *
  2386. * \param x floating point value.
  2387. * \returns arc cosine of `x`, in radians.
  2388. *
  2389. * \threadsafety It is safe to call this function from any thread.
  2390. *
  2391. * \since This function is available since SDL 3.0.0.
  2392. *
  2393. * \sa SDL_acosf
  2394. * \sa SDL_asin
  2395. * \sa SDL_cos
  2396. */
  2397. extern SDL_DECLSPEC double SDLCALL SDL_acos(double x);
  2398. /**
  2399. * Compute the arc cosine of `x`.
  2400. *
  2401. * The definition of `y = acos(x)` is `x = cos(y)`.
  2402. *
  2403. * Domain: `-1 <= x <= 1`
  2404. *
  2405. * Range: `0 <= y <= Pi`
  2406. *
  2407. * This function operates on single-precision floating point values, use
  2408. * SDL_acos for double-precision floats.
  2409. *
  2410. * This function may use a different approximation across different versions,
  2411. * platforms and configurations. i.e, it can return a different value given
  2412. * the same input on different machines or operating systems, or if SDL is
  2413. * updated.
  2414. *
  2415. * \param x floating point value.
  2416. * \returns arc cosine of `x`, in radians.
  2417. *
  2418. * \threadsafety It is safe to call this function from any thread.
  2419. *
  2420. * \since This function is available since SDL 3.0.0.
  2421. *
  2422. * \sa SDL_acos
  2423. * \sa SDL_asinf
  2424. * \sa SDL_cosf
  2425. */
  2426. extern SDL_DECLSPEC float SDLCALL SDL_acosf(float x);
  2427. /**
  2428. * Compute the arc sine of `x`.
  2429. *
  2430. * The definition of `y = asin(x)` is `x = sin(y)`.
  2431. *
  2432. * Domain: `-1 <= x <= 1`
  2433. *
  2434. * Range: `-Pi/2 <= y <= Pi/2`
  2435. *
  2436. * This function operates on double-precision floating point values, use
  2437. * SDL_asinf for single-precision floats.
  2438. *
  2439. * This function may use a different approximation across different versions,
  2440. * platforms and configurations. i.e, it can return a different value given
  2441. * the same input on different machines or operating systems, or if SDL is
  2442. * updated.
  2443. *
  2444. * \param x floating point value.
  2445. * \returns arc sine of `x`, in radians.
  2446. *
  2447. * \threadsafety It is safe to call this function from any thread.
  2448. *
  2449. * \since This function is available since SDL 3.0.0.
  2450. *
  2451. * \sa SDL_asinf
  2452. * \sa SDL_acos
  2453. * \sa SDL_sin
  2454. */
  2455. extern SDL_DECLSPEC double SDLCALL SDL_asin(double x);
  2456. /**
  2457. * Compute the arc sine of `x`.
  2458. *
  2459. * The definition of `y = asin(x)` is `x = sin(y)`.
  2460. *
  2461. * Domain: `-1 <= x <= 1`
  2462. *
  2463. * Range: `-Pi/2 <= y <= Pi/2`
  2464. *
  2465. * This function operates on single-precision floating point values, use
  2466. * SDL_asin for double-precision floats.
  2467. *
  2468. * This function may use a different approximation across different versions,
  2469. * platforms and configurations. i.e, it can return a different value given
  2470. * the same input on different machines or operating systems, or if SDL is
  2471. * updated.
  2472. *
  2473. * \param x floating point value.
  2474. * \returns arc sine of `x`, in radians.
  2475. *
  2476. * \threadsafety It is safe to call this function from any thread.
  2477. *
  2478. * \since This function is available since SDL 3.0.0.
  2479. *
  2480. * \sa SDL_asin
  2481. * \sa SDL_acosf
  2482. * \sa SDL_sinf
  2483. */
  2484. extern SDL_DECLSPEC float SDLCALL SDL_asinf(float x);
  2485. /**
  2486. * Compute the arc tangent of `x`.
  2487. *
  2488. * The definition of `y = atan(x)` is `x = tan(y)`.
  2489. *
  2490. * Domain: `-INF <= x <= INF`
  2491. *
  2492. * Range: `-Pi/2 <= y <= Pi/2`
  2493. *
  2494. * This function operates on double-precision floating point values, use
  2495. * SDL_atanf for single-precision floats.
  2496. *
  2497. * To calculate the arc tangent of y / x, use SDL_atan2.
  2498. *
  2499. * This function may use a different approximation across different versions,
  2500. * platforms and configurations. i.e, it can return a different value given
  2501. * the same input on different machines or operating systems, or if SDL is
  2502. * updated.
  2503. *
  2504. * \param x floating point value.
  2505. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  2506. *
  2507. * \threadsafety It is safe to call this function from any thread.
  2508. *
  2509. * \since This function is available since SDL 3.0.0.
  2510. *
  2511. * \sa SDL_atanf
  2512. * \sa SDL_atan2
  2513. * \sa SDL_tan
  2514. */
  2515. extern SDL_DECLSPEC double SDLCALL SDL_atan(double x);
  2516. /**
  2517. * Compute the arc tangent of `x`.
  2518. *
  2519. * The definition of `y = atan(x)` is `x = tan(y)`.
  2520. *
  2521. * Domain: `-INF <= x <= INF`
  2522. *
  2523. * Range: `-Pi/2 <= y <= Pi/2`
  2524. *
  2525. * This function operates on single-precision floating point values, use
  2526. * SDL_atan for dboule-precision floats.
  2527. *
  2528. * To calculate the arc tangent of y / x, use SDL_atan2f.
  2529. *
  2530. * This function may use a different approximation across different versions,
  2531. * platforms and configurations. i.e, it can return a different value given
  2532. * the same input on different machines or operating systems, or if SDL is
  2533. * updated.
  2534. *
  2535. * \param x floating point value.
  2536. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  2537. *
  2538. * \threadsafety It is safe to call this function from any thread.
  2539. *
  2540. * \since This function is available since SDL 3.0.0.
  2541. *
  2542. * \sa SDL_atan
  2543. * \sa SDL_atan2f
  2544. * \sa SDL_tanf
  2545. */
  2546. extern SDL_DECLSPEC float SDLCALL SDL_atanf(float x);
  2547. /**
  2548. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  2549. * the result's quadrant.
  2550. *
  2551. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  2552. * of z is determined based on the signs of x and y.
  2553. *
  2554. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2555. *
  2556. * Range: `-Pi/2 <= y <= Pi/2`
  2557. *
  2558. * This function operates on double-precision floating point values, use
  2559. * SDL_atan2f for single-precision floats.
  2560. *
  2561. * To calculate the arc tangent of a single value, use SDL_atan.
  2562. *
  2563. * This function may use a different approximation across different versions,
  2564. * platforms and configurations. i.e, it can return a different value given
  2565. * the same input on different machines or operating systems, or if SDL is
  2566. * updated.
  2567. *
  2568. * \param y floating point value of the numerator (y coordinate).
  2569. * \param x floating point value of the denominator (x coordinate).
  2570. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  2571. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  2572. *
  2573. * \threadsafety It is safe to call this function from any thread.
  2574. *
  2575. * \since This function is available since SDL 3.0.0.
  2576. *
  2577. * \sa SDL_atan2f
  2578. * \sa SDL_atan
  2579. * \sa SDL_tan
  2580. */
  2581. extern SDL_DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  2582. /**
  2583. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  2584. * the result's quadrant.
  2585. *
  2586. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  2587. * of z is determined based on the signs of x and y.
  2588. *
  2589. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  2590. *
  2591. * Range: `-Pi/2 <= y <= Pi/2`
  2592. *
  2593. * This function operates on single-precision floating point values, use
  2594. * SDL_atan2 for double-precision floats.
  2595. *
  2596. * To calculate the arc tangent of a single value, use SDL_atanf.
  2597. *
  2598. * This function may use a different approximation across different versions,
  2599. * platforms and configurations. i.e, it can return a different value given
  2600. * the same input on different machines or operating systems, or if SDL is
  2601. * updated.
  2602. *
  2603. * \param y floating point value of the numerator (y coordinate).
  2604. * \param x floating point value of the denominator (x coordinate).
  2605. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  2606. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  2607. *
  2608. * \threadsafety It is safe to call this function from any thread.
  2609. *
  2610. * \since This function is available since SDL 3.0.0.
  2611. *
  2612. * \sa SDL_atan2f
  2613. * \sa SDL_atan
  2614. * \sa SDL_tan
  2615. */
  2616. extern SDL_DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  2617. /**
  2618. * Compute the ceiling of `x`.
  2619. *
  2620. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  2621. * rounded up to the nearest integer.
  2622. *
  2623. * Domain: `-INF <= x <= INF`
  2624. *
  2625. * Range: `-INF <= y <= INF`, y integer
  2626. *
  2627. * This function operates on double-precision floating point values, use
  2628. * SDL_ceilf for single-precision floats.
  2629. *
  2630. * \param x floating point value.
  2631. * \returns the ceiling of `x`.
  2632. *
  2633. * \threadsafety It is safe to call this function from any thread.
  2634. *
  2635. * \since This function is available since SDL 3.0.0.
  2636. *
  2637. * \sa SDL_ceilf
  2638. * \sa SDL_floor
  2639. * \sa SDL_trunc
  2640. * \sa SDL_round
  2641. * \sa SDL_lround
  2642. */
  2643. extern SDL_DECLSPEC double SDLCALL SDL_ceil(double x);
  2644. /**
  2645. * Compute the ceiling of `x`.
  2646. *
  2647. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  2648. * rounded up to the nearest integer.
  2649. *
  2650. * Domain: `-INF <= x <= INF`
  2651. *
  2652. * Range: `-INF <= y <= INF`, y integer
  2653. *
  2654. * This function operates on single-precision floating point values, use
  2655. * SDL_ceil for double-precision floats.
  2656. *
  2657. * \param x floating point value.
  2658. * \returns the ceiling of `x`.
  2659. *
  2660. * \threadsafety It is safe to call this function from any thread.
  2661. *
  2662. * \since This function is available since SDL 3.0.0.
  2663. *
  2664. * \sa SDL_ceil
  2665. * \sa SDL_floorf
  2666. * \sa SDL_truncf
  2667. * \sa SDL_roundf
  2668. * \sa SDL_lroundf
  2669. */
  2670. extern SDL_DECLSPEC float SDLCALL SDL_ceilf(float x);
  2671. /**
  2672. * Copy the sign of one floating-point value to another.
  2673. *
  2674. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  2675. *
  2676. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  2677. *
  2678. * Range: `-INF <= z <= INF`
  2679. *
  2680. * This function operates on double-precision floating point values, use
  2681. * SDL_copysignf for single-precision floats.
  2682. *
  2683. * \param x floating point value to use as the magnitude.
  2684. * \param y floating point value to use as the sign.
  2685. * \returns the floating point value with the sign of y and the magnitude of
  2686. * x.
  2687. *
  2688. * \threadsafety It is safe to call this function from any thread.
  2689. *
  2690. * \since This function is available since SDL 3.0.0.
  2691. *
  2692. * \sa SDL_copysignf
  2693. * \sa SDL_fabs
  2694. */
  2695. extern SDL_DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  2696. /**
  2697. * Copy the sign of one floating-point value to another.
  2698. *
  2699. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  2700. *
  2701. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  2702. *
  2703. * Range: `-INF <= z <= INF`
  2704. *
  2705. * This function operates on single-precision floating point values, use
  2706. * SDL_copysign for double-precision floats.
  2707. *
  2708. * \param x floating point value to use as the magnitude.
  2709. * \param y floating point value to use as the sign.
  2710. * \returns the floating point value with the sign of y and the magnitude of
  2711. * x.
  2712. *
  2713. * \threadsafety It is safe to call this function from any thread.
  2714. *
  2715. * \since This function is available since SDL 3.0.0.
  2716. *
  2717. * \sa SDL_copysignf
  2718. * \sa SDL_fabsf
  2719. */
  2720. extern SDL_DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  2721. /**
  2722. * Compute the cosine of `x`.
  2723. *
  2724. * Domain: `-INF <= x <= INF`
  2725. *
  2726. * Range: `-1 <= y <= 1`
  2727. *
  2728. * This function operates on double-precision floating point values, use
  2729. * SDL_cosf for single-precision floats.
  2730. *
  2731. * This function may use a different approximation across different versions,
  2732. * platforms and configurations. i.e, it can return a different value given
  2733. * the same input on different machines or operating systems, or if SDL is
  2734. * updated.
  2735. *
  2736. * \param x floating point value, in radians.
  2737. * \returns cosine of `x`.
  2738. *
  2739. * \threadsafety It is safe to call this function from any thread.
  2740. *
  2741. * \since This function is available since SDL 3.0.0.
  2742. *
  2743. * \sa SDL_cosf
  2744. * \sa SDL_acos
  2745. * \sa SDL_sin
  2746. */
  2747. extern SDL_DECLSPEC double SDLCALL SDL_cos(double x);
  2748. /**
  2749. * Compute the cosine of `x`.
  2750. *
  2751. * Domain: `-INF <= x <= INF`
  2752. *
  2753. * Range: `-1 <= y <= 1`
  2754. *
  2755. * This function operates on single-precision floating point values, use
  2756. * SDL_cos for double-precision floats.
  2757. *
  2758. * This function may use a different approximation across different versions,
  2759. * platforms and configurations. i.e, it can return a different value given
  2760. * the same input on different machines or operating systems, or if SDL is
  2761. * updated.
  2762. *
  2763. * \param x floating point value, in radians.
  2764. * \returns cosine of `x`.
  2765. *
  2766. * \threadsafety It is safe to call this function from any thread.
  2767. *
  2768. * \since This function is available since SDL 3.0.0.
  2769. *
  2770. * \sa SDL_cos
  2771. * \sa SDL_acosf
  2772. * \sa SDL_sinf
  2773. */
  2774. extern SDL_DECLSPEC float SDLCALL SDL_cosf(float x);
  2775. /**
  2776. * Compute the exponential of `x`.
  2777. *
  2778. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2779. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  2780. *
  2781. * Domain: `-INF <= x <= INF`
  2782. *
  2783. * Range: `0 <= y <= INF`
  2784. *
  2785. * The output will overflow if `exp(x)` is too large to be represented.
  2786. *
  2787. * This function operates on double-precision floating point values, use
  2788. * SDL_expf for single-precision floats.
  2789. *
  2790. * This function may use a different approximation across different versions,
  2791. * platforms and configurations. i.e, it can return a different value given
  2792. * the same input on different machines or operating systems, or if SDL is
  2793. * updated.
  2794. *
  2795. * \param x floating point value.
  2796. * \returns value of `e^x`.
  2797. *
  2798. * \threadsafety It is safe to call this function from any thread.
  2799. *
  2800. * \since This function is available since SDL 3.0.0.
  2801. *
  2802. * \sa SDL_expf
  2803. * \sa SDL_log
  2804. */
  2805. extern SDL_DECLSPEC double SDLCALL SDL_exp(double x);
  2806. /**
  2807. * Compute the exponential of `x`.
  2808. *
  2809. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  2810. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  2811. *
  2812. * Domain: `-INF <= x <= INF`
  2813. *
  2814. * Range: `0 <= y <= INF`
  2815. *
  2816. * The output will overflow if `exp(x)` is too large to be represented.
  2817. *
  2818. * This function operates on single-precision floating point values, use
  2819. * SDL_exp for double-precision floats.
  2820. *
  2821. * This function may use a different approximation across different versions,
  2822. * platforms and configurations. i.e, it can return a different value given
  2823. * the same input on different machines or operating systems, or if SDL is
  2824. * updated.
  2825. *
  2826. * \param x floating point value.
  2827. * \returns value of `e^x`.
  2828. *
  2829. * \threadsafety It is safe to call this function from any thread.
  2830. *
  2831. * \since This function is available since SDL 3.0.0.
  2832. *
  2833. * \sa SDL_exp
  2834. * \sa SDL_logf
  2835. */
  2836. extern SDL_DECLSPEC float SDLCALL SDL_expf(float x);
  2837. /**
  2838. * Compute the absolute value of `x`
  2839. *
  2840. * Domain: `-INF <= x <= INF`
  2841. *
  2842. * Range: `0 <= y <= INF`
  2843. *
  2844. * This function operates on double-precision floating point values, use
  2845. * SDL_copysignf for single-precision floats.
  2846. *
  2847. * \param x floating point value to use as the magnitude.
  2848. * \returns the absolute value of `x`.
  2849. *
  2850. * \threadsafety It is safe to call this function from any thread.
  2851. *
  2852. * \since This function is available since SDL 3.0.0.
  2853. *
  2854. * \sa SDL_fabsf
  2855. */
  2856. extern SDL_DECLSPEC double SDLCALL SDL_fabs(double x);
  2857. /**
  2858. * Compute the absolute value of `x`
  2859. *
  2860. * Domain: `-INF <= x <= INF`
  2861. *
  2862. * Range: `0 <= y <= INF`
  2863. *
  2864. * This function operates on single-precision floating point values, use
  2865. * SDL_copysignf for double-precision floats.
  2866. *
  2867. * \param x floating point value to use as the magnitude.
  2868. * \returns the absolute value of `x`.
  2869. *
  2870. * \threadsafety It is safe to call this function from any thread.
  2871. *
  2872. * \since This function is available since SDL 3.0.0.
  2873. *
  2874. * \sa SDL_fabs
  2875. */
  2876. extern SDL_DECLSPEC float SDLCALL SDL_fabsf(float x);
  2877. /**
  2878. * Compute the floor of `x`.
  2879. *
  2880. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2881. * rounded down to the nearest integer.
  2882. *
  2883. * Domain: `-INF <= x <= INF`
  2884. *
  2885. * Range: `-INF <= y <= INF`, y integer
  2886. *
  2887. * This function operates on double-precision floating point values, use
  2888. * SDL_floorf for single-precision floats.
  2889. *
  2890. * \param x floating point value.
  2891. * \returns the floor of `x`.
  2892. *
  2893. * \threadsafety It is safe to call this function from any thread.
  2894. *
  2895. * \since This function is available since SDL 3.0.0.
  2896. *
  2897. * \sa SDL_floorf
  2898. * \sa SDL_ceil
  2899. * \sa SDL_trunc
  2900. * \sa SDL_round
  2901. * \sa SDL_lround
  2902. */
  2903. extern SDL_DECLSPEC double SDLCALL SDL_floor(double x);
  2904. /**
  2905. * Compute the floor of `x`.
  2906. *
  2907. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  2908. * rounded down to the nearest integer.
  2909. *
  2910. * Domain: `-INF <= x <= INF`
  2911. *
  2912. * Range: `-INF <= y <= INF`, y integer
  2913. *
  2914. * This function operates on single-precision floating point values, use
  2915. * SDL_floorf for double-precision floats.
  2916. *
  2917. * \param x floating point value.
  2918. * \returns the floor of `x`.
  2919. *
  2920. * \threadsafety It is safe to call this function from any thread.
  2921. *
  2922. * \since This function is available since SDL 3.0.0.
  2923. *
  2924. * \sa SDL_floor
  2925. * \sa SDL_ceilf
  2926. * \sa SDL_truncf
  2927. * \sa SDL_roundf
  2928. * \sa SDL_lroundf
  2929. */
  2930. extern SDL_DECLSPEC float SDLCALL SDL_floorf(float x);
  2931. /**
  2932. * Truncate `x` to an integer.
  2933. *
  2934. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2935. * the fractional part of `x`, leaving only the integer part.
  2936. *
  2937. * Domain: `-INF <= x <= INF`
  2938. *
  2939. * Range: `-INF <= y <= INF`, y integer
  2940. *
  2941. * This function operates on double-precision floating point values, use
  2942. * SDL_truncf for single-precision floats.
  2943. *
  2944. * \param x floating point value.
  2945. * \returns `x` truncated to an integer.
  2946. *
  2947. * \threadsafety It is safe to call this function from any thread.
  2948. *
  2949. * \since This function is available since SDL 3.0.0.
  2950. *
  2951. * \sa SDL_truncf
  2952. * \sa SDL_fmod
  2953. * \sa SDL_ceil
  2954. * \sa SDL_floor
  2955. * \sa SDL_round
  2956. * \sa SDL_lround
  2957. */
  2958. extern SDL_DECLSPEC double SDLCALL SDL_trunc(double x);
  2959. /**
  2960. * Truncate `x` to an integer.
  2961. *
  2962. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  2963. * the fractional part of `x`, leaving only the integer part.
  2964. *
  2965. * Domain: `-INF <= x <= INF`
  2966. *
  2967. * Range: `-INF <= y <= INF`, y integer
  2968. *
  2969. * This function operates on single-precision floating point values, use
  2970. * SDL_truncf for double-precision floats.
  2971. *
  2972. * \param x floating point value.
  2973. * \returns `x` truncated to an integer.
  2974. *
  2975. * \threadsafety It is safe to call this function from any thread.
  2976. *
  2977. * \since This function is available since SDL 3.0.0.
  2978. *
  2979. * \sa SDL_trunc
  2980. * \sa SDL_fmodf
  2981. * \sa SDL_ceilf
  2982. * \sa SDL_floorf
  2983. * \sa SDL_roundf
  2984. * \sa SDL_lroundf
  2985. */
  2986. extern SDL_DECLSPEC float SDLCALL SDL_truncf(float x);
  2987. /**
  2988. * Return the floating-point remainder of `x / y`
  2989. *
  2990. * Divides `x` by `y`, and returns the remainder.
  2991. *
  2992. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  2993. *
  2994. * Range: `-y <= z <= y`
  2995. *
  2996. * This function operates on double-precision floating point values, use
  2997. * SDL_fmodf for single-precision floats.
  2998. *
  2999. * \param x the numerator.
  3000. * \param y the denominator. Must not be 0.
  3001. * \returns the remainder of `x / y`.
  3002. *
  3003. * \threadsafety It is safe to call this function from any thread.
  3004. *
  3005. * \since This function is available since SDL 3.0.0.
  3006. *
  3007. * \sa SDL_fmodf
  3008. * \sa SDL_modf
  3009. * \sa SDL_trunc
  3010. * \sa SDL_ceil
  3011. * \sa SDL_floor
  3012. * \sa SDL_round
  3013. * \sa SDL_lround
  3014. */
  3015. extern SDL_DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  3016. /**
  3017. * Return the floating-point remainder of `x / y`
  3018. *
  3019. * Divides `x` by `y`, and returns the remainder.
  3020. *
  3021. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  3022. *
  3023. * Range: `-y <= z <= y`
  3024. *
  3025. * This function operates on single-precision floating point values, use
  3026. * SDL_fmod for single-precision floats.
  3027. *
  3028. * \param x the numerator.
  3029. * \param y the denominator. Must not be 0.
  3030. * \returns the remainder of `x / y`.
  3031. *
  3032. * \threadsafety It is safe to call this function from any thread.
  3033. *
  3034. * \since This function is available since SDL 3.0.0.
  3035. *
  3036. * \sa SDL_fmod
  3037. * \sa SDL_truncf
  3038. * \sa SDL_modff
  3039. * \sa SDL_ceilf
  3040. * \sa SDL_floorf
  3041. * \sa SDL_roundf
  3042. * \sa SDL_lroundf
  3043. */
  3044. extern SDL_DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  3045. /**
  3046. * Return whether the value is infinity.
  3047. *
  3048. * \param x double-precision floating point value.
  3049. * \returns non-zero if the value is infinity, 0 otherwise.
  3050. *
  3051. * \threadsafety It is safe to call this function from any thread.
  3052. *
  3053. * \since This function is available since SDL 3.0.0.
  3054. *
  3055. * \sa SDL_isinff
  3056. */
  3057. extern SDL_DECLSPEC int SDLCALL SDL_isinf(double x);
  3058. /**
  3059. * Return whether the value is infinity.
  3060. *
  3061. * \param x floating point value.
  3062. * \returns non-zero if the value is infinity, 0 otherwise.
  3063. *
  3064. * \threadsafety It is safe to call this function from any thread.
  3065. *
  3066. * \since This function is available since SDL 3.0.0.
  3067. *
  3068. * \sa SDL_isinf
  3069. */
  3070. extern SDL_DECLSPEC int SDLCALL SDL_isinff(float x);
  3071. /**
  3072. * Return whether the value is NaN.
  3073. *
  3074. * \param x double-precision floating point value.
  3075. * \returns non-zero if the value is NaN, 0 otherwise.
  3076. *
  3077. * \threadsafety It is safe to call this function from any thread.
  3078. *
  3079. * \since This function is available since SDL 3.0.0.
  3080. *
  3081. * \sa SDL_isnanf
  3082. */
  3083. extern SDL_DECLSPEC int SDLCALL SDL_isnan(double x);
  3084. /**
  3085. * Return whether the value is NaN.
  3086. *
  3087. * \param x floating point value.
  3088. * \returns non-zero if the value is NaN, 0 otherwise.
  3089. *
  3090. * \threadsafety It is safe to call this function from any thread.
  3091. *
  3092. * \since This function is available since SDL 3.0.0.
  3093. *
  3094. * \sa SDL_isnan
  3095. */
  3096. extern SDL_DECLSPEC int SDLCALL SDL_isnanf(float x);
  3097. /**
  3098. * Compute the natural logarithm of `x`.
  3099. *
  3100. * Domain: `0 < x <= INF`
  3101. *
  3102. * Range: `-INF <= y <= INF`
  3103. *
  3104. * It is an error for `x` to be less than or equal to 0.
  3105. *
  3106. * This function operates on double-precision floating point values, use
  3107. * SDL_logf for single-precision floats.
  3108. *
  3109. * This function may use a different approximation across different versions,
  3110. * platforms and configurations. i.e, it can return a different value given
  3111. * the same input on different machines or operating systems, or if SDL is
  3112. * updated.
  3113. *
  3114. * \param x floating point value. Must be greater than 0.
  3115. * \returns the natural logarithm of `x`.
  3116. *
  3117. * \threadsafety It is safe to call this function from any thread.
  3118. *
  3119. * \since This function is available since SDL 3.0.0.
  3120. *
  3121. * \sa SDL_logf
  3122. * \sa SDL_log10
  3123. * \sa SDL_exp
  3124. */
  3125. extern SDL_DECLSPEC double SDLCALL SDL_log(double x);
  3126. /**
  3127. * Compute the natural logarithm of `x`.
  3128. *
  3129. * Domain: `0 < x <= INF`
  3130. *
  3131. * Range: `-INF <= y <= INF`
  3132. *
  3133. * It is an error for `x` to be less than or equal to 0.
  3134. *
  3135. * This function operates on single-precision floating point values, use
  3136. * SDL_log for double-precision floats.
  3137. *
  3138. * This function may use a different approximation across different versions,
  3139. * platforms and configurations. i.e, it can return a different value given
  3140. * the same input on different machines or operating systems, or if SDL is
  3141. * updated.
  3142. *
  3143. * \param x floating point value. Must be greater than 0.
  3144. * \returns the natural logarithm of `x`.
  3145. *
  3146. * \threadsafety It is safe to call this function from any thread.
  3147. *
  3148. * \since This function is available since SDL 3.0.0.
  3149. *
  3150. * \sa SDL_log
  3151. * \sa SDL_expf
  3152. */
  3153. extern SDL_DECLSPEC float SDLCALL SDL_logf(float x);
  3154. /**
  3155. * Compute the base-10 logarithm of `x`.
  3156. *
  3157. * Domain: `0 < x <= INF`
  3158. *
  3159. * Range: `-INF <= y <= INF`
  3160. *
  3161. * It is an error for `x` to be less than or equal to 0.
  3162. *
  3163. * This function operates on double-precision floating point values, use
  3164. * SDL_log10f for single-precision floats.
  3165. *
  3166. * This function may use a different approximation across different versions,
  3167. * platforms and configurations. i.e, it can return a different value given
  3168. * the same input on different machines or operating systems, or if SDL is
  3169. * updated.
  3170. *
  3171. * \param x floating point value. Must be greater than 0.
  3172. * \returns the logarithm of `x`.
  3173. *
  3174. * \threadsafety It is safe to call this function from any thread.
  3175. *
  3176. * \since This function is available since SDL 3.0.0.
  3177. *
  3178. * \sa SDL_log10f
  3179. * \sa SDL_log
  3180. * \sa SDL_pow
  3181. */
  3182. extern SDL_DECLSPEC double SDLCALL SDL_log10(double x);
  3183. /**
  3184. * Compute the base-10 logarithm of `x`.
  3185. *
  3186. * Domain: `0 < x <= INF`
  3187. *
  3188. * Range: `-INF <= y <= INF`
  3189. *
  3190. * It is an error for `x` to be less than or equal to 0.
  3191. *
  3192. * This function operates on single-precision floating point values, use
  3193. * SDL_log10 for double-precision floats.
  3194. *
  3195. * This function may use a different approximation across different versions,
  3196. * platforms and configurations. i.e, it can return a different value given
  3197. * the same input on different machines or operating systems, or if SDL is
  3198. * updated.
  3199. *
  3200. * \param x floating point value. Must be greater than 0.
  3201. * \returns the logarithm of `x`.
  3202. *
  3203. * \threadsafety It is safe to call this function from any thread.
  3204. *
  3205. * \since This function is available since SDL 3.0.0.
  3206. *
  3207. * \sa SDL_log10
  3208. * \sa SDL_logf
  3209. * \sa SDL_powf
  3210. */
  3211. extern SDL_DECLSPEC float SDLCALL SDL_log10f(float x);
  3212. /**
  3213. * Split `x` into integer and fractional parts
  3214. *
  3215. * This function operates on double-precision floating point values, use
  3216. * SDL_modff for single-precision floats.
  3217. *
  3218. * \param x floating point value.
  3219. * \param y output pointer to store the integer part of `x`.
  3220. * \returns the fractional part of `x`.
  3221. *
  3222. * \threadsafety It is safe to call this function from any thread.
  3223. *
  3224. * \since This function is available since SDL 3.0.0.
  3225. *
  3226. * \sa SDL_modff
  3227. * \sa SDL_trunc
  3228. * \sa SDL_fmod
  3229. */
  3230. extern SDL_DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  3231. /**
  3232. * Split `x` into integer and fractional parts
  3233. *
  3234. * This function operates on single-precision floating point values, use
  3235. * SDL_modf for double-precision floats.
  3236. *
  3237. * \param x floating point value.
  3238. * \param y output pointer to store the integer part of `x`.
  3239. * \returns the fractional part of `x`.
  3240. *
  3241. * \threadsafety It is safe to call this function from any thread.
  3242. *
  3243. * \since This function is available since SDL 3.0.0.
  3244. *
  3245. * \sa SDL_modf
  3246. * \sa SDL_truncf
  3247. * \sa SDL_fmodf
  3248. */
  3249. extern SDL_DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  3250. /**
  3251. * Raise `x` to the power `y`
  3252. *
  3253. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  3254. *
  3255. * Range: `-INF <= z <= INF`
  3256. *
  3257. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  3258. * instead.
  3259. *
  3260. * This function operates on double-precision floating point values, use
  3261. * SDL_powf for single-precision floats.
  3262. *
  3263. * This function may use a different approximation across different versions,
  3264. * platforms and configurations. i.e, it can return a different value given
  3265. * the same input on different machines or operating systems, or if SDL is
  3266. * updated.
  3267. *
  3268. * \param x the base.
  3269. * \param y the exponent.
  3270. * \returns `x` raised to the power `y`.
  3271. *
  3272. * \threadsafety It is safe to call this function from any thread.
  3273. *
  3274. * \since This function is available since SDL 3.0.0.
  3275. *
  3276. * \sa SDL_powf
  3277. * \sa SDL_exp
  3278. * \sa SDL_log
  3279. */
  3280. extern SDL_DECLSPEC double SDLCALL SDL_pow(double x, double y);
  3281. /**
  3282. * Raise `x` to the power `y`
  3283. *
  3284. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  3285. *
  3286. * Range: `-INF <= z <= INF`
  3287. *
  3288. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  3289. * instead.
  3290. *
  3291. * This function operates on single-precision floating point values, use
  3292. * SDL_powf for double-precision floats.
  3293. *
  3294. * This function may use a different approximation across different versions,
  3295. * platforms and configurations. i.e, it can return a different value given
  3296. * the same input on different machines or operating systems, or if SDL is
  3297. * updated.
  3298. *
  3299. * \param x the base.
  3300. * \param y the exponent.
  3301. * \returns `x` raised to the power `y`.
  3302. *
  3303. * \threadsafety It is safe to call this function from any thread.
  3304. *
  3305. * \since This function is available since SDL 3.0.0.
  3306. *
  3307. * \sa SDL_pow
  3308. * \sa SDL_expf
  3309. * \sa SDL_logf
  3310. */
  3311. extern SDL_DECLSPEC float SDLCALL SDL_powf(float x, float y);
  3312. /**
  3313. * Round `x` to the nearest integer.
  3314. *
  3315. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3316. * rounded away from zero.
  3317. *
  3318. * Domain: `-INF <= x <= INF`
  3319. *
  3320. * Range: `-INF <= y <= INF`, y integer
  3321. *
  3322. * This function operates on double-precision floating point values, use
  3323. * SDL_roundf for single-precision floats. To get the result as an integer
  3324. * type, use SDL_lround.
  3325. *
  3326. * \param x floating point value.
  3327. * \returns the nearest integer to `x`.
  3328. *
  3329. * \threadsafety It is safe to call this function from any thread.
  3330. *
  3331. * \since This function is available since SDL 3.0.0.
  3332. *
  3333. * \sa SDL_roundf
  3334. * \sa SDL_lround
  3335. * \sa SDL_floor
  3336. * \sa SDL_ceil
  3337. * \sa SDL_trunc
  3338. */
  3339. extern SDL_DECLSPEC double SDLCALL SDL_round(double x);
  3340. /**
  3341. * Round `x` to the nearest integer.
  3342. *
  3343. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3344. * rounded away from zero.
  3345. *
  3346. * Domain: `-INF <= x <= INF`
  3347. *
  3348. * Range: `-INF <= y <= INF`, y integer
  3349. *
  3350. * This function operates on double-precision floating point values, use
  3351. * SDL_roundf for single-precision floats. To get the result as an integer
  3352. * type, use SDL_lroundf.
  3353. *
  3354. * \param x floating point value.
  3355. * \returns the nearest integer to `x`.
  3356. *
  3357. * \threadsafety It is safe to call this function from any thread.
  3358. *
  3359. * \since This function is available since SDL 3.0.0.
  3360. *
  3361. * \sa SDL_round
  3362. * \sa SDL_lroundf
  3363. * \sa SDL_floorf
  3364. * \sa SDL_ceilf
  3365. * \sa SDL_truncf
  3366. */
  3367. extern SDL_DECLSPEC float SDLCALL SDL_roundf(float x);
  3368. /**
  3369. * Round `x` to the nearest integer representable as a long
  3370. *
  3371. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3372. * rounded away from zero.
  3373. *
  3374. * Domain: `-INF <= x <= INF`
  3375. *
  3376. * Range: `MIN_LONG <= y <= MAX_LONG`
  3377. *
  3378. * This function operates on double-precision floating point values, use
  3379. * SDL_lround for single-precision floats. To get the result as a
  3380. * floating-point type, use SDL_round.
  3381. *
  3382. * \param x floating point value.
  3383. * \returns the nearest integer to `x`.
  3384. *
  3385. * \threadsafety It is safe to call this function from any thread.
  3386. *
  3387. * \since This function is available since SDL 3.0.0.
  3388. *
  3389. * \sa SDL_lroundf
  3390. * \sa SDL_round
  3391. * \sa SDL_floor
  3392. * \sa SDL_ceil
  3393. * \sa SDL_trunc
  3394. */
  3395. extern SDL_DECLSPEC long SDLCALL SDL_lround(double x);
  3396. /**
  3397. * Round `x` to the nearest integer representable as a long
  3398. *
  3399. * Rounds `x` to the nearest integer. Values halfway between integers will be
  3400. * rounded away from zero.
  3401. *
  3402. * Domain: `-INF <= x <= INF`
  3403. *
  3404. * Range: `MIN_LONG <= y <= MAX_LONG`
  3405. *
  3406. * This function operates on single-precision floating point values, use
  3407. * SDL_lroundf for double-precision floats. To get the result as a
  3408. * floating-point type, use SDL_roundf,
  3409. *
  3410. * \param x floating point value.
  3411. * \returns the nearest integer to `x`.
  3412. *
  3413. * \threadsafety It is safe to call this function from any thread.
  3414. *
  3415. * \since This function is available since SDL 3.0.0.
  3416. *
  3417. * \sa SDL_lround
  3418. * \sa SDL_roundf
  3419. * \sa SDL_floorf
  3420. * \sa SDL_ceilf
  3421. * \sa SDL_truncf
  3422. */
  3423. extern SDL_DECLSPEC long SDLCALL SDL_lroundf(float x);
  3424. /**
  3425. * Scale `x` by an integer power of two.
  3426. *
  3427. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  3428. *
  3429. * Domain: `-INF <= x <= INF`, `n` integer
  3430. *
  3431. * Range: `-INF <= y <= INF`
  3432. *
  3433. * This function operates on double-precision floating point values, use
  3434. * SDL_scalbnf for single-precision floats.
  3435. *
  3436. * \param x floating point value to be scaled.
  3437. * \param n integer exponent.
  3438. * \returns `x * 2^n`.
  3439. *
  3440. * \threadsafety It is safe to call this function from any thread.
  3441. *
  3442. * \since This function is available since SDL 3.0.0.
  3443. *
  3444. * \sa SDL_scalbnf
  3445. * \sa SDL_pow
  3446. */
  3447. extern SDL_DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  3448. /**
  3449. * Scale `x` by an integer power of two.
  3450. *
  3451. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  3452. *
  3453. * Domain: `-INF <= x <= INF`, `n` integer
  3454. *
  3455. * Range: `-INF <= y <= INF`
  3456. *
  3457. * This function operates on single-precision floating point values, use
  3458. * SDL_scalbn for double-precision floats.
  3459. *
  3460. * \param x floating point value to be scaled.
  3461. * \param n integer exponent.
  3462. * \returns `x * 2^n`.
  3463. *
  3464. * \threadsafety It is safe to call this function from any thread.
  3465. *
  3466. * \since This function is available since SDL 3.0.0.
  3467. *
  3468. * \sa SDL_scalbn
  3469. * \sa SDL_powf
  3470. */
  3471. extern SDL_DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  3472. /**
  3473. * Compute the sine of `x`.
  3474. *
  3475. * Domain: `-INF <= x <= INF`
  3476. *
  3477. * Range: `-1 <= y <= 1`
  3478. *
  3479. * This function operates on double-precision floating point values, use
  3480. * SDL_sinf for single-precision floats.
  3481. *
  3482. * This function may use a different approximation across different versions,
  3483. * platforms and configurations. i.e, it can return a different value given
  3484. * the same input on different machines or operating systems, or if SDL is
  3485. * updated.
  3486. *
  3487. * \param x floating point value, in radians.
  3488. * \returns sine of `x`.
  3489. *
  3490. * \threadsafety It is safe to call this function from any thread.
  3491. *
  3492. * \since This function is available since SDL 3.0.0.
  3493. *
  3494. * \sa SDL_sinf
  3495. * \sa SDL_asin
  3496. * \sa SDL_cos
  3497. */
  3498. extern SDL_DECLSPEC double SDLCALL SDL_sin(double x);
  3499. /**
  3500. * Compute the sine of `x`.
  3501. *
  3502. * Domain: `-INF <= x <= INF`
  3503. *
  3504. * Range: `-1 <= y <= 1`
  3505. *
  3506. * This function operates on single-precision floating point values, use
  3507. * SDL_sinf for double-precision floats.
  3508. *
  3509. * This function may use a different approximation across different versions,
  3510. * platforms and configurations. i.e, it can return a different value given
  3511. * the same input on different machines or operating systems, or if SDL is
  3512. * updated.
  3513. *
  3514. * \param x floating point value, in radians.
  3515. * \returns sine of `x`.
  3516. *
  3517. * \threadsafety It is safe to call this function from any thread.
  3518. *
  3519. * \since This function is available since SDL 3.0.0.
  3520. *
  3521. * \sa SDL_sin
  3522. * \sa SDL_asinf
  3523. * \sa SDL_cosf
  3524. */
  3525. extern SDL_DECLSPEC float SDLCALL SDL_sinf(float x);
  3526. /**
  3527. * Compute the square root of `x`.
  3528. *
  3529. * Domain: `0 <= x <= INF`
  3530. *
  3531. * Range: `0 <= y <= INF`
  3532. *
  3533. * This function operates on double-precision floating point values, use
  3534. * SDL_sqrtf for single-precision floats.
  3535. *
  3536. * This function may use a different approximation across different versions,
  3537. * platforms and configurations. i.e, it can return a different value given
  3538. * the same input on different machines or operating systems, or if SDL is
  3539. * updated.
  3540. *
  3541. * \param x floating point value. Must be greater than or equal to 0.
  3542. * \returns square root of `x`.
  3543. *
  3544. * \threadsafety It is safe to call this function from any thread.
  3545. *
  3546. * \since This function is available since SDL 3.0.0.
  3547. *
  3548. * \sa SDL_sqrtf
  3549. */
  3550. extern SDL_DECLSPEC double SDLCALL SDL_sqrt(double x);
  3551. /**
  3552. * Compute the square root of `x`.
  3553. *
  3554. * Domain: `0 <= x <= INF`
  3555. *
  3556. * Range: `0 <= y <= INF`
  3557. *
  3558. * This function operates on single-precision floating point values, use
  3559. * SDL_sqrt for double-precision floats.
  3560. *
  3561. * This function may use a different approximation across different versions,
  3562. * platforms and configurations. i.e, it can return a different value given
  3563. * the same input on different machines or operating systems, or if SDL is
  3564. * updated.
  3565. *
  3566. * \param x floating point value. Must be greater than or equal to 0.
  3567. * \returns square root of `x`.
  3568. *
  3569. * \threadsafety It is safe to call this function from any thread.
  3570. *
  3571. * \since This function is available since SDL 3.0.0.
  3572. *
  3573. * \sa SDL_sqrt
  3574. */
  3575. extern SDL_DECLSPEC float SDLCALL SDL_sqrtf(float x);
  3576. /**
  3577. * Compute the tangent of `x`.
  3578. *
  3579. * Domain: `-INF <= x <= INF`
  3580. *
  3581. * Range: `-INF <= y <= INF`
  3582. *
  3583. * This function operates on double-precision floating point values, use
  3584. * SDL_tanf for single-precision floats.
  3585. *
  3586. * This function may use a different approximation across different versions,
  3587. * platforms and configurations. i.e, it can return a different value given
  3588. * the same input on different machines or operating systems, or if SDL is
  3589. * updated.
  3590. *
  3591. * \param x floating point value, in radians.
  3592. * \returns tangent of `x`.
  3593. *
  3594. * \threadsafety It is safe to call this function from any thread.
  3595. *
  3596. * \since This function is available since SDL 3.0.0.
  3597. *
  3598. * \sa SDL_tanf
  3599. * \sa SDL_sin
  3600. * \sa SDL_cos
  3601. * \sa SDL_atan
  3602. * \sa SDL_atan2
  3603. */
  3604. extern SDL_DECLSPEC double SDLCALL SDL_tan(double x);
  3605. /**
  3606. * Compute the tangent of `x`.
  3607. *
  3608. * Domain: `-INF <= x <= INF`
  3609. *
  3610. * Range: `-INF <= y <= INF`
  3611. *
  3612. * This function operates on single-precision floating point values, use
  3613. * SDL_tanf for double-precision floats.
  3614. *
  3615. * This function may use a different approximation across different versions,
  3616. * platforms and configurations. i.e, it can return a different value given
  3617. * the same input on different machines or operating systems, or if SDL is
  3618. * updated.
  3619. *
  3620. * \param x floating point value, in radians.
  3621. * \returns tangent of `x`.
  3622. *
  3623. * \threadsafety It is safe to call this function from any thread.
  3624. *
  3625. * \since This function is available since SDL 3.0.0.
  3626. *
  3627. * \sa SDL_tan
  3628. * \sa SDL_sinf
  3629. * \sa SDL_cosf
  3630. * \sa SDL_atanf
  3631. * \sa SDL_atan2f
  3632. */
  3633. extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
  3634. /* The SDL implementation of iconv() returns these error codes */
  3635. #define SDL_ICONV_ERROR (size_t)-1
  3636. #define SDL_ICONV_E2BIG (size_t)-2
  3637. #define SDL_ICONV_EILSEQ (size_t)-3
  3638. #define SDL_ICONV_EINVAL (size_t)-4
  3639. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  3640. /**
  3641. * This function allocates a context for the specified character set
  3642. * conversion.
  3643. *
  3644. * \param tocode The target character encoding, must not be NULL.
  3645. * \param fromcode The source character encoding, must not be NULL.
  3646. * \returns a handle that must be freed with SDL_iconv_close, or
  3647. * SDL_ICONV_ERROR on failure.
  3648. *
  3649. * \since This function is available since SDL 3.0.0.
  3650. *
  3651. * \sa SDL_iconv
  3652. * \sa SDL_iconv_close
  3653. * \sa SDL_iconv_string
  3654. */
  3655. extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  3656. const char *fromcode);
  3657. /**
  3658. * This function frees a context used for character set conversion.
  3659. *
  3660. * \param cd The character set conversion handle.
  3661. * \returns 0 on success, or -1 on failure.
  3662. *
  3663. * \since This function is available since SDL 3.0.0.
  3664. *
  3665. * \sa SDL_iconv
  3666. * \sa SDL_iconv_open
  3667. * \sa SDL_iconv_string
  3668. */
  3669. extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  3670. /**
  3671. * This function converts text between encodings, reading from and writing to
  3672. * a buffer.
  3673. *
  3674. * It returns the number of succesful conversions.
  3675. *
  3676. * \param cd The character set conversion context, created in
  3677. * SDL_iconv_open().
  3678. * \param inbuf Address of variable that points to the first character of the
  3679. * input sequence.
  3680. * \param inbytesleft The number of bytes in the input buffer.
  3681. * \param outbuf Address of variable that points to the output buffer.
  3682. * \param outbytesleft The number of bytes in the output buffer.
  3683. * \returns the number of conversions on success, else SDL_ICONV_E2BIG is
  3684. * returned when the output buffer is too small, or SDL_ICONV_EILSEQ
  3685. * is returned when an invalid input sequence is encountered, or
  3686. * SDL_ICONV_EINVAL is returned when an incomplete input sequence is
  3687. * encountered.
  3688. *
  3689. * On exit:
  3690. *
  3691. * - inbuf will point to the beginning of the next multibyte
  3692. * sequence. On error, this is the location of the problematic
  3693. * input sequence. On success, this is the end of the input
  3694. * sequence. - inbytesleft will be set to the number of bytes left
  3695. * to convert, which will be 0 on success. - outbuf will point to
  3696. * the location where to store the next output byte. - outbytesleft
  3697. * will be set to the number of bytes left in the output buffer.
  3698. *
  3699. * \since This function is available since SDL 3.0.0.
  3700. *
  3701. * \sa SDL_iconv_open
  3702. * \sa SDL_iconv_close
  3703. * \sa SDL_iconv_string
  3704. */
  3705. extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  3706. size_t *inbytesleft, char **outbuf,
  3707. size_t *outbytesleft);
  3708. /**
  3709. * Helper function to convert a string's encoding in one call.
  3710. *
  3711. * This function converts a buffer or string between encodings in one pass.
  3712. *
  3713. * The string does not need to be NULL-terminated; this function operates on
  3714. * the number of bytes specified in `inbytesleft` whether there is a NULL
  3715. * character anywhere in the buffer.
  3716. *
  3717. * The returned string is owned by the caller, and should be passed to
  3718. * SDL_free when no longer needed.
  3719. *
  3720. * \param tocode the character encoding of the output string. Examples are
  3721. * "UTF-8", "UCS-4", etc.
  3722. * \param fromcode the character encoding of data in `inbuf`.
  3723. * \param inbuf the string to convert to a different encoding.
  3724. * \param inbytesleft the size of the input string _in bytes_.
  3725. * \returns a new string, converted to the new encoding, or NULL on error.
  3726. *
  3727. * \since This function is available since SDL 3.0.0.
  3728. *
  3729. * \sa SDL_iconv_open
  3730. * \sa SDL_iconv_close
  3731. * \sa SDL_iconv
  3732. */
  3733. extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
  3734. const char *fromcode,
  3735. const char *inbuf,
  3736. size_t inbytesleft);
  3737. /* Some helper macros for common cases... */
  3738. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  3739. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  3740. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  3741. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  3742. /* force builds using Clang's static analysis tools to use literal C runtime
  3743. here, since there are possibly tests that are ineffective otherwise. */
  3744. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  3745. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  3746. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  3747. size_t strlcpy(char *dst, const char *src, size_t size);
  3748. #endif
  3749. /* The analyzer knows about strlcat even when the system doesn't provide it */
  3750. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  3751. size_t strlcat(char *dst, const char *src, size_t size);
  3752. #endif
  3753. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  3754. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  3755. #endif
  3756. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  3757. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  3758. #endif
  3759. /* Starting LLVM 16, the analyser errors out if these functions do not have
  3760. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  3761. #include <stdio.h>
  3762. #include <stdlib.h>
  3763. #include <strings.h>
  3764. #define SDL_malloc malloc
  3765. #define SDL_calloc calloc
  3766. #define SDL_realloc realloc
  3767. #define SDL_free free
  3768. #ifndef SDL_memcpy
  3769. #define SDL_memcpy memcpy
  3770. #endif
  3771. #ifndef SDL_memmove
  3772. #define SDL_memmove memmove
  3773. #endif
  3774. #ifndef SDL_memset
  3775. #define SDL_memset memset
  3776. #endif
  3777. #define SDL_memcmp memcmp
  3778. #define SDL_strlcpy strlcpy
  3779. #define SDL_strlcat strlcat
  3780. #define SDL_strlen strlen
  3781. #define SDL_wcslen wcslen
  3782. #define SDL_wcslcpy wcslcpy
  3783. #define SDL_wcslcat wcslcat
  3784. #define SDL_strdup strdup
  3785. #define SDL_wcsdup wcsdup
  3786. #define SDL_strchr strchr
  3787. #define SDL_strrchr strrchr
  3788. #define SDL_strstr strstr
  3789. #define SDL_wcsstr wcsstr
  3790. #define SDL_strtok_r strtok_r
  3791. #define SDL_strcmp strcmp
  3792. #define SDL_wcscmp wcscmp
  3793. #define SDL_strncmp strncmp
  3794. #define SDL_wcsncmp wcsncmp
  3795. #define SDL_strcasecmp strcasecmp
  3796. #define SDL_strncasecmp strncasecmp
  3797. #define SDL_strpbrk strpbrk
  3798. #define SDL_sscanf sscanf
  3799. #define SDL_vsscanf vsscanf
  3800. #define SDL_snprintf snprintf
  3801. #define SDL_vsnprintf vsnprintf
  3802. #endif
  3803. /**
  3804. * Multiply two integers, checking for overflow.
  3805. *
  3806. * If `a * b` would overflow, return false.
  3807. *
  3808. * Otherwise store `a * b` via ret and return true.
  3809. *
  3810. * \param a the multiplicand.
  3811. * \param b the multiplier.
  3812. * \param ret on non-overflow output, stores the multiplication result. May
  3813. * not be NULL.
  3814. * \returns false on overflow, true if result is multiplied without overflow.
  3815. *
  3816. * \threadsafety It is safe to call this function from any thread.
  3817. *
  3818. * \since This function is available since SDL 3.0.0.
  3819. */
  3820. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret)
  3821. {
  3822. if (a != 0 && b > SDL_SIZE_MAX / a) {
  3823. return false;
  3824. }
  3825. *ret = a * b;
  3826. return true;
  3827. }
  3828. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3829. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  3830. /* This needs to be wrapped in an inline rather than being a direct #define,
  3831. * because __builtin_mul_overflow() is type-generic, but we want to be
  3832. * consistent about interpreting a and b as size_t. */
  3833. SDL_FORCE_INLINE bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3834. {
  3835. return (__builtin_mul_overflow(a, b, ret) == 0);
  3836. }
  3837. #define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret)
  3838. #endif
  3839. #endif
  3840. /**
  3841. * Add two integers, checking for overflow.
  3842. *
  3843. * If `a + b` would overflow, return -1.
  3844. *
  3845. * Otherwise store `a + b` via ret and return 0.
  3846. *
  3847. * \param a the first addend.
  3848. * \param b the second addend.
  3849. * \param ret on non-overflow output, stores the addition result. May not be
  3850. * NULL.
  3851. * \returns false on overflow, true if result is added without overflow.
  3852. *
  3853. * \threadsafety It is safe to call this function from any thread.
  3854. *
  3855. * \since This function is available since SDL 3.0.0.
  3856. */
  3857. SDL_FORCE_INLINE bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret)
  3858. {
  3859. if (b > SDL_SIZE_MAX - a) {
  3860. return false;
  3861. }
  3862. *ret = a + b;
  3863. return true;
  3864. }
  3865. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  3866. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  3867. /* This needs to be wrapped in an inline rather than being a direct #define,
  3868. * the same as the call to __builtin_mul_overflow() above. */
  3869. SDL_FORCE_INLINE bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret)
  3870. {
  3871. return (__builtin_add_overflow(a, b, ret) == 0);
  3872. }
  3873. #define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret)
  3874. #endif
  3875. #endif
  3876. /* This is a generic function pointer which should be cast to the type you expect */
  3877. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  3878. /**
  3879. * A generic function pointer.
  3880. *
  3881. * In theory, generic function pointers should use this, instead of `void *`,
  3882. * since some platforms could treat code addresses differently than data
  3883. * addresses. Although in current times no popular platforms make this
  3884. * distinction, it is more correct and portable to use the correct type for a
  3885. * generic pointer.
  3886. *
  3887. * If for some reason you need to force this typedef to be an actual `void *`,
  3888. * perhaps to work around a compiler or existing code, you can define
  3889. * `SDL_FUNCTION_POINTER_IS_VOID_POINTER` before including any SDL headers.
  3890. *
  3891. * \since This datatype is available since SDL 3.0.0.
  3892. */
  3893. typedef void (*SDL_FunctionPointer)(void);
  3894. #elif defined(SDL_FUNCTION_POINTER_IS_VOID_POINTER)
  3895. typedef void *SDL_FunctionPointer;
  3896. #else
  3897. typedef void (*SDL_FunctionPointer)(void);
  3898. #endif
  3899. /* Ends C function definitions when using C++ */
  3900. #ifdef __cplusplus
  3901. }
  3902. #endif
  3903. #include <SDL3/SDL_close_code.h>
  3904. #endif /* SDL_stdinc_h_ */