SDL_stdinc.h 133 KB

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