SDL_iostream.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: IOStream */
  19. /**
  20. * # CategoryIOStream
  21. *
  22. * SDL provides an abstract interface for reading and writing data streams. It
  23. * offers implementations for files, memory, etc, and the app can provide
  24. * their own implementations, too.
  25. *
  26. * SDL_IOStream is not related to the standard C++ iostream class, other than
  27. * both are abstract interfaces to read/write data.
  28. */
  29. #ifndef SDL_iostream_h_
  30. #define SDL_iostream_h_
  31. #include <SDL3/SDL_stdinc.h>
  32. #include <SDL3/SDL_error.h>
  33. #include <SDL3/SDL_properties.h>
  34. #include <SDL3/SDL_begin_code.h>
  35. /* Set up for C function definitions, even when using C++ */
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * SDL_IOStream status, set by a read or write operation.
  41. *
  42. * \since This enum is available since SDL 3.2.0.
  43. */
  44. typedef enum SDL_IOStatus
  45. {
  46. SDL_IO_STATUS_READY, /**< Everything is ready (no errors and not EOF). */
  47. SDL_IO_STATUS_ERROR, /**< Read or write I/O error */
  48. SDL_IO_STATUS_EOF, /**< End of file */
  49. SDL_IO_STATUS_NOT_READY, /**< Non blocking I/O, not ready */
  50. SDL_IO_STATUS_READONLY, /**< Tried to write a read-only buffer */
  51. SDL_IO_STATUS_WRITEONLY /**< Tried to read a write-only buffer */
  52. } SDL_IOStatus;
  53. /**
  54. * Possible `whence` values for SDL_IOStream seeking.
  55. *
  56. * These map to the same "whence" concept that `fseek` or `lseek` use in the
  57. * standard C runtime.
  58. *
  59. * \since This enum is available since SDL 3.2.0.
  60. */
  61. typedef enum SDL_IOWhence
  62. {
  63. SDL_IO_SEEK_SET, /**< Seek from the beginning of data */
  64. SDL_IO_SEEK_CUR, /**< Seek relative to current read point */
  65. SDL_IO_SEEK_END /**< Seek relative to the end of data */
  66. } SDL_IOWhence;
  67. /**
  68. * The function pointers that drive an SDL_IOStream.
  69. *
  70. * Applications can provide this struct to SDL_OpenIO() to create their own
  71. * implementation of SDL_IOStream. This is not necessarily required, as SDL
  72. * already offers several common types of I/O streams, via functions like
  73. * SDL_IOFromFile() and SDL_IOFromMem().
  74. *
  75. * This structure should be initialized using SDL_INIT_INTERFACE()
  76. *
  77. * \since This struct is available since SDL 3.2.0.
  78. *
  79. * \sa SDL_INIT_INTERFACE
  80. */
  81. typedef struct SDL_IOStreamInterface
  82. {
  83. /* The version of this interface */
  84. Uint32 version;
  85. /**
  86. * Return the number of bytes in this SDL_IOStream
  87. *
  88. * \return the total size of the data stream, or -1 on error.
  89. */
  90. Sint64 (SDLCALL *size)(void *userdata);
  91. /**
  92. * Seek to `offset` relative to `whence`, one of stdio's whence values:
  93. * SDL_IO_SEEK_SET, SDL_IO_SEEK_CUR, SDL_IO_SEEK_END
  94. *
  95. * \return the final offset in the data stream, or -1 on error.
  96. */
  97. Sint64 (SDLCALL *seek)(void *userdata, Sint64 offset, SDL_IOWhence whence);
  98. /**
  99. * Read up to `size` bytes from the data stream to the area pointed
  100. * at by `ptr`.
  101. *
  102. * On an incomplete read, you should set `*status` to a value from the
  103. * SDL_IOStatus enum. You do not have to explicitly set this on
  104. * a complete, successful read.
  105. *
  106. * \return the number of bytes read
  107. */
  108. size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *status);
  109. /**
  110. * Write exactly `size` bytes from the area pointed at by `ptr`
  111. * to data stream.
  112. *
  113. * On an incomplete write, you should set `*status` to a value from the
  114. * SDL_IOStatus enum. You do not have to explicitly set this on
  115. * a complete, successful write.
  116. *
  117. * \return the number of bytes written
  118. */
  119. size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status);
  120. /**
  121. * If the stream is buffering, make sure the data is written out.
  122. *
  123. * On failure, you should set `*status` to a value from the
  124. * SDL_IOStatus enum. You do not have to explicitly set this on
  125. * a successful flush.
  126. *
  127. * \return true if successful or false on write error when flushing data.
  128. */
  129. bool (SDLCALL *flush)(void *userdata, SDL_IOStatus *status);
  130. /**
  131. * Close and free any allocated resources.
  132. *
  133. * This does not guarantee file writes will sync to physical media; they
  134. * can be in the system's file cache, waiting to go to disk.
  135. *
  136. * The SDL_IOStream is still destroyed even if this fails, so clean up anything
  137. * even if flushing buffers, etc, returns an error.
  138. *
  139. * \return true if successful or false on write error when flushing data.
  140. */
  141. bool (SDLCALL *close)(void *userdata);
  142. } SDL_IOStreamInterface;
  143. /* Check the size of SDL_IOStreamInterface
  144. *
  145. * If this assert fails, either the compiler is padding to an unexpected size,
  146. * or the interface has been updated and this should be updated to match and
  147. * the code using this interface should be updated to handle the old version.
  148. */
  149. SDL_COMPILE_TIME_ASSERT(SDL_IOStreamInterface_SIZE,
  150. (sizeof(void *) == 4 && sizeof(SDL_IOStreamInterface) == 28) ||
  151. (sizeof(void *) == 8 && sizeof(SDL_IOStreamInterface) == 56));
  152. /**
  153. * The read/write operation structure.
  154. *
  155. * This operates as an opaque handle. There are several APIs to create various
  156. * types of I/O streams, or an app can supply an SDL_IOStreamInterface to
  157. * SDL_OpenIO() to provide their own stream implementation behind this
  158. * struct's abstract interface.
  159. *
  160. * \since This struct is available since SDL 3.2.0.
  161. */
  162. typedef struct SDL_IOStream SDL_IOStream;
  163. /**
  164. * \name IOFrom functions
  165. *
  166. * Functions to create SDL_IOStream structures from various data streams.
  167. */
  168. /* @{ */
  169. /**
  170. * Use this function to create a new SDL_IOStream structure for reading from
  171. * and/or writing to a named file.
  172. *
  173. * The `mode` string is treated roughly the same as in a call to the C
  174. * library's fopen(), even if SDL doesn't happen to use fopen() behind the
  175. * scenes.
  176. *
  177. * Available `mode` strings:
  178. *
  179. * - "r": Open a file for reading. The file must exist.
  180. * - "w": Create an empty file for writing. If a file with the same name
  181. * already exists its content is erased and the file is treated as a new
  182. * empty file.
  183. * - "a": Append to a file. Writing operations append data at the end of the
  184. * file. The file is created if it does not exist.
  185. * - "r+": Open a file for update both reading and writing. The file must
  186. * exist.
  187. * - "w+": Create an empty file for both reading and writing. If a file with
  188. * the same name already exists its content is erased and the file is
  189. * treated as a new empty file.
  190. * - "a+": Open a file for reading and appending. All writing operations are
  191. * performed at the end of the file, protecting the previous content to be
  192. * overwritten. You can reposition (fseek, rewind) the internal pointer to
  193. * anywhere in the file for reading, but writing operations will move it
  194. * back to the end of file. The file is created if it does not exist.
  195. *
  196. * **NOTE**: In order to open a file as a binary file, a "b" character has to
  197. * be included in the `mode` string. This additional "b" character can either
  198. * be appended at the end of the string (thus making the following compound
  199. * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the
  200. * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").
  201. * Additional characters may follow the sequence, although they should have no
  202. * effect. For example, "t" is sometimes appended to make explicit the file is
  203. * a text file.
  204. *
  205. * This function supports Unicode filenames, but they must be encoded in UTF-8
  206. * format, regardless of the underlying operating system.
  207. *
  208. * In Android, SDL_IOFromFile() can be used to open content:// URIs. As a
  209. * fallback, SDL_IOFromFile() will transparently open a matching filename in
  210. * the app's `assets`.
  211. *
  212. * Closing the SDL_IOStream will close SDL's internal file handle.
  213. *
  214. * The following properties may be set at creation time by SDL:
  215. *
  216. * - `SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER`: a pointer, that can be cast
  217. * to a win32 `HANDLE`, that this SDL_IOStream is using to access the
  218. * filesystem. If the program isn't running on Windows, or SDL used some
  219. * other method to access the filesystem, this property will not be set.
  220. * - `SDL_PROP_IOSTREAM_STDIO_FILE_POINTER`: a pointer, that can be cast to a
  221. * stdio `FILE *`, that this SDL_IOStream is using to access the filesystem.
  222. * If SDL used some other method to access the filesystem, this property
  223. * will not be set. PLEASE NOTE that if SDL is using a different C runtime
  224. * than your app, trying to use this pointer will almost certainly result in
  225. * a crash! This is mostly a problem on Windows; make sure you build SDL and
  226. * your app with the same compiler and settings to avoid it.
  227. * - `SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER`: a file descriptor that this
  228. * SDL_IOStream is using to access the filesystem.
  229. * - `SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER`: a pointer, that can be cast
  230. * to an Android NDK `AAsset *`, that this SDL_IOStream is using to access
  231. * the filesystem. If SDL used some other method to access the filesystem,
  232. * this property will not be set.
  233. *
  234. * \param file a UTF-8 string representing the filename to open.
  235. * \param mode an ASCII string representing the mode to be used for opening
  236. * the file.
  237. * \returns a pointer to the SDL_IOStream structure that is created or NULL on
  238. * failure; call SDL_GetError() for more information.
  239. *
  240. * \threadsafety This function is not thread safe.
  241. *
  242. * \since This function is available since SDL 3.2.0.
  243. *
  244. * \sa SDL_CloseIO
  245. * \sa SDL_FlushIO
  246. * \sa SDL_ReadIO
  247. * \sa SDL_SeekIO
  248. * \sa SDL_TellIO
  249. * \sa SDL_WriteIO
  250. */
  251. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, const char *mode);
  252. #define SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER "SDL.iostream.windows.handle"
  253. #define SDL_PROP_IOSTREAM_STDIO_FILE_POINTER "SDL.iostream.stdio.file"
  254. #define SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER "SDL.iostream.file_descriptor"
  255. #define SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER "SDL.iostream.android.aasset"
  256. /**
  257. * Use this function to prepare a read-write memory buffer for use with
  258. * SDL_IOStream.
  259. *
  260. * This function sets up an SDL_IOStream struct based on a memory area of a
  261. * certain size, for both read and write access.
  262. *
  263. * This memory buffer is not copied by the SDL_IOStream; the pointer you
  264. * provide must remain valid until you close the stream.
  265. *
  266. * If you need to make sure the SDL_IOStream never writes to the memory
  267. * buffer, you should use SDL_IOFromConstMem() with a read-only buffer of
  268. * memory instead.
  269. *
  270. * The following properties will be set at creation time by SDL:
  271. *
  272. * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
  273. * was passed to this function.
  274. * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
  275. * that was passed to this function.
  276. *
  277. * Additionally, the following properties are recognized:
  278. *
  279. * - `SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER`: if this property is set to
  280. * a non-NULL value it will be interpreted as a function of SDL_free_func
  281. * type and called with the passed `mem` pointer when closing the stream. By
  282. * default it is unset, i.e., the memory will not be freed.
  283. *
  284. * \param mem a pointer to a buffer to feed an SDL_IOStream stream.
  285. * \param size the buffer size, in bytes.
  286. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  287. * SDL_GetError() for more information.
  288. *
  289. * \threadsafety It is safe to call this function from any thread.
  290. *
  291. * \since This function is available since SDL 3.2.0.
  292. *
  293. * \sa SDL_IOFromConstMem
  294. * \sa SDL_CloseIO
  295. * \sa SDL_FlushIO
  296. * \sa SDL_ReadIO
  297. * \sa SDL_SeekIO
  298. * \sa SDL_TellIO
  299. * \sa SDL_WriteIO
  300. */
  301. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size);
  302. #define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base"
  303. #define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size"
  304. #define SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER "SDL.iostream.memory.free"
  305. /**
  306. * Use this function to prepare a read-only memory buffer for use with
  307. * SDL_IOStream.
  308. *
  309. * This function sets up an SDL_IOStream struct based on a memory area of a
  310. * certain size. It assumes the memory area is not writable.
  311. *
  312. * Attempting to write to this SDL_IOStream stream will report an error
  313. * without writing to the memory buffer.
  314. *
  315. * This memory buffer is not copied by the SDL_IOStream; the pointer you
  316. * provide must remain valid until you close the stream.
  317. *
  318. * If you need to write to a memory buffer, you should use SDL_IOFromMem()
  319. * with a writable buffer of memory instead.
  320. *
  321. * The following properties will be set at creation time by SDL:
  322. *
  323. * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
  324. * was passed to this function.
  325. * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
  326. * that was passed to this function.
  327. *
  328. * Additionally, the following properties are recognized:
  329. *
  330. * - `SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER`: if this property is set to
  331. * a non-NULL value it will be interpreted as a function of SDL_free_func
  332. * type and called with the passed `mem` pointer when closing the stream. By
  333. * default it is unset, i.e., the memory will not be freed.
  334. *
  335. * \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream.
  336. * \param size the buffer size, in bytes.
  337. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  338. * SDL_GetError() for more information.
  339. *
  340. * \threadsafety It is safe to call this function from any thread.
  341. *
  342. * \since This function is available since SDL 3.2.0.
  343. *
  344. * \sa SDL_IOFromMem
  345. * \sa SDL_CloseIO
  346. * \sa SDL_ReadIO
  347. * \sa SDL_SeekIO
  348. * \sa SDL_TellIO
  349. */
  350. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromConstMem(const void *mem, size_t size);
  351. /**
  352. * Use this function to create an SDL_IOStream that is backed by dynamically
  353. * allocated memory.
  354. *
  355. * This supports the following properties to provide access to the memory and
  356. * control over allocations:
  357. *
  358. * - `SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER`: a pointer to the internal
  359. * memory of the stream. This can be set to NULL to transfer ownership of
  360. * the memory to the application, which should free the memory with
  361. * SDL_free(). If this is done, the next operation on the stream must be
  362. * SDL_CloseIO().
  363. * - `SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER`: memory will be allocated in
  364. * multiples of this size, defaulting to 1024.
  365. *
  366. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  367. * SDL_GetError() for more information.
  368. *
  369. * \threadsafety It is safe to call this function from any thread.
  370. *
  371. * \since This function is available since SDL 3.2.0.
  372. *
  373. * \sa SDL_CloseIO
  374. * \sa SDL_ReadIO
  375. * \sa SDL_SeekIO
  376. * \sa SDL_TellIO
  377. * \sa SDL_WriteIO
  378. */
  379. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromDynamicMem(void);
  380. #define SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER "SDL.iostream.dynamic.memory"
  381. #define SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER "SDL.iostream.dynamic.chunksize"
  382. /* @} *//* IOFrom functions */
  383. /**
  384. * Create a custom SDL_IOStream.
  385. *
  386. * Applications do not need to use this function unless they are providing
  387. * their own SDL_IOStream implementation. If you just need an SDL_IOStream to
  388. * read/write a common data source, you should use the built-in
  389. * implementations in SDL, like SDL_IOFromFile() or SDL_IOFromMem(), etc.
  390. *
  391. * This function makes a copy of `iface` and the caller does not need to keep
  392. * it around after this call.
  393. *
  394. * \param iface the interface that implements this SDL_IOStream, initialized
  395. * using SDL_INIT_INTERFACE().
  396. * \param userdata the pointer that will be passed to the interface functions.
  397. * \returns a pointer to the allocated memory on success or NULL on failure;
  398. * call SDL_GetError() for more information.
  399. *
  400. * \threadsafety It is safe to call this function from any thread.
  401. *
  402. * \since This function is available since SDL 3.2.0.
  403. *
  404. * \sa SDL_CloseIO
  405. * \sa SDL_INIT_INTERFACE
  406. * \sa SDL_IOFromConstMem
  407. * \sa SDL_IOFromFile
  408. * \sa SDL_IOFromMem
  409. */
  410. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata);
  411. /**
  412. * Close and free an allocated SDL_IOStream structure.
  413. *
  414. * SDL_CloseIO() closes and cleans up the SDL_IOStream stream. It releases any
  415. * resources used by the stream and frees the SDL_IOStream itself. This
  416. * returns true on success, or false if the stream failed to flush to its
  417. * output (e.g. to disk).
  418. *
  419. * Note that if this fails to flush the stream for any reason, this function
  420. * reports an error, but the SDL_IOStream is still invalid once this function
  421. * returns.
  422. *
  423. * This call flushes any buffered writes to the operating system, but there
  424. * are no guarantees that those writes have gone to physical media; they might
  425. * be in the OS's file cache, waiting to go to disk later. If it's absolutely
  426. * crucial that writes go to disk immediately, so they are definitely stored
  427. * even if the power fails before the file cache would have caught up, one
  428. * should call SDL_FlushIO() before closing. Note that flushing takes time and
  429. * makes the system and your app operate less efficiently, so do so sparingly.
  430. *
  431. * \param context SDL_IOStream structure to close.
  432. * \returns true on success or false on failure; call SDL_GetError() for more
  433. * information.
  434. *
  435. * \threadsafety This function is not thread safe.
  436. *
  437. * \since This function is available since SDL 3.2.0.
  438. *
  439. * \sa SDL_OpenIO
  440. */
  441. extern SDL_DECLSPEC bool SDLCALL SDL_CloseIO(SDL_IOStream *context);
  442. /**
  443. * Get the properties associated with an SDL_IOStream.
  444. *
  445. * \param context a pointer to an SDL_IOStream structure.
  446. * \returns a valid property ID on success or 0 on failure; call
  447. * SDL_GetError() for more information.
  448. *
  449. * \threadsafety This function is not thread safe.
  450. *
  451. * \since This function is available since SDL 3.2.0.
  452. */
  453. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetIOProperties(SDL_IOStream *context);
  454. /**
  455. * Query the stream status of an SDL_IOStream.
  456. *
  457. * This information can be useful to decide if a short read or write was due
  458. * to an error, an EOF, or a non-blocking operation that isn't yet ready to
  459. * complete.
  460. *
  461. * An SDL_IOStream's status is only expected to change after a SDL_ReadIO or
  462. * SDL_WriteIO call; don't expect it to change if you just call this query
  463. * function in a tight loop.
  464. *
  465. * \param context the SDL_IOStream to query.
  466. * \returns an SDL_IOStatus enum with the current state.
  467. *
  468. * \threadsafety This function is not thread safe.
  469. *
  470. * \since This function is available since SDL 3.2.0.
  471. */
  472. extern SDL_DECLSPEC SDL_IOStatus SDLCALL SDL_GetIOStatus(SDL_IOStream *context);
  473. /**
  474. * Use this function to get the size of the data stream in an SDL_IOStream.
  475. *
  476. * \param context the SDL_IOStream to get the size of the data stream from.
  477. * \returns the size of the data stream in the SDL_IOStream on success or a
  478. * negative error code on failure; call SDL_GetError() for more
  479. * information.
  480. *
  481. * \threadsafety This function is not thread safe.
  482. *
  483. * \since This function is available since SDL 3.2.0.
  484. */
  485. extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetIOSize(SDL_IOStream *context);
  486. /**
  487. * Seek within an SDL_IOStream data stream.
  488. *
  489. * This function seeks to byte `offset`, relative to `whence`.
  490. *
  491. * `whence` may be any of the following values:
  492. *
  493. * - `SDL_IO_SEEK_SET`: seek from the beginning of data
  494. * - `SDL_IO_SEEK_CUR`: seek relative to current read point
  495. * - `SDL_IO_SEEK_END`: seek relative to the end of data
  496. *
  497. * If this stream can not seek, it will return -1.
  498. *
  499. * \param context a pointer to an SDL_IOStream structure.
  500. * \param offset an offset in bytes, relative to `whence` location; can be
  501. * negative.
  502. * \param whence any of `SDL_IO_SEEK_SET`, `SDL_IO_SEEK_CUR`,
  503. * `SDL_IO_SEEK_END`.
  504. * \returns the final offset in the data stream after the seek or -1 on
  505. * failure; call SDL_GetError() for more information.
  506. *
  507. * \threadsafety This function is not thread safe.
  508. *
  509. * \since This function is available since SDL 3.2.0.
  510. *
  511. * \sa SDL_TellIO
  512. */
  513. extern SDL_DECLSPEC Sint64 SDLCALL SDL_SeekIO(SDL_IOStream *context, Sint64 offset, SDL_IOWhence whence);
  514. /**
  515. * Determine the current read/write offset in an SDL_IOStream data stream.
  516. *
  517. * SDL_TellIO is actually a wrapper function that calls the SDL_IOStream's
  518. * `seek` method, with an offset of 0 bytes from `SDL_IO_SEEK_CUR`, to
  519. * simplify application development.
  520. *
  521. * \param context an SDL_IOStream data stream object from which to get the
  522. * current offset.
  523. * \returns the current offset in the stream, or -1 if the information can not
  524. * be determined.
  525. *
  526. * \threadsafety This function is not thread safe.
  527. *
  528. * \since This function is available since SDL 3.2.0.
  529. *
  530. * \sa SDL_SeekIO
  531. */
  532. extern SDL_DECLSPEC Sint64 SDLCALL SDL_TellIO(SDL_IOStream *context);
  533. /**
  534. * Read from a data source.
  535. *
  536. * This function reads up `size` bytes from the data source to the area
  537. * pointed at by `ptr`. This function may read less bytes than requested.
  538. *
  539. * This function will return zero when the data stream is completely read, and
  540. * SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If zero is returned and
  541. * the stream is not at EOF, SDL_GetIOStatus() will return a different error
  542. * value and SDL_GetError() will offer a human-readable message.
  543. *
  544. * \param context a pointer to an SDL_IOStream structure.
  545. * \param ptr a pointer to a buffer to read data into.
  546. * \param size the number of bytes to read from the data source.
  547. * \returns the number of bytes read, or 0 on end of file or other failure;
  548. * call SDL_GetError() for more information.
  549. *
  550. * \threadsafety This function is not thread safe.
  551. *
  552. * \since This function is available since SDL 3.2.0.
  553. *
  554. * \sa SDL_WriteIO
  555. * \sa SDL_GetIOStatus
  556. */
  557. extern SDL_DECLSPEC size_t SDLCALL SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size);
  558. /**
  559. * Write to an SDL_IOStream data stream.
  560. *
  561. * This function writes exactly `size` bytes from the area pointed at by `ptr`
  562. * to the stream. If this fails for any reason, it'll return less than `size`
  563. * to demonstrate how far the write progressed. On success, it returns `size`.
  564. *
  565. * On error, this function still attempts to write as much as possible, so it
  566. * might return a positive value less than the requested write size.
  567. *
  568. * The caller can use SDL_GetIOStatus() to determine if the problem is
  569. * recoverable, such as a non-blocking write that can simply be retried later,
  570. * or a fatal error.
  571. *
  572. * \param context a pointer to an SDL_IOStream structure.
  573. * \param ptr a pointer to a buffer containing data to write.
  574. * \param size the number of bytes to write.
  575. * \returns the number of bytes written, which will be less than `size` on
  576. * failure; call SDL_GetError() for more information.
  577. *
  578. * \threadsafety This function is not thread safe.
  579. *
  580. * \since This function is available since SDL 3.2.0.
  581. *
  582. * \sa SDL_IOprintf
  583. * \sa SDL_ReadIO
  584. * \sa SDL_SeekIO
  585. * \sa SDL_FlushIO
  586. * \sa SDL_GetIOStatus
  587. */
  588. extern SDL_DECLSPEC size_t SDLCALL SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size);
  589. /**
  590. * Print to an SDL_IOStream data stream.
  591. *
  592. * This function does formatted printing to the stream.
  593. *
  594. * \param context a pointer to an SDL_IOStream structure.
  595. * \param fmt a printf() style format string.
  596. * \param ... additional parameters matching % tokens in the `fmt` string, if
  597. * any.
  598. * \returns the number of bytes written or 0 on failure; call SDL_GetError()
  599. * for more information.
  600. *
  601. * \threadsafety This function is not thread safe.
  602. *
  603. * \since This function is available since SDL 3.2.0.
  604. *
  605. * \sa SDL_IOvprintf
  606. * \sa SDL_WriteIO
  607. */
  608. extern SDL_DECLSPEC size_t SDLCALL SDL_IOprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  609. /**
  610. * Print to an SDL_IOStream data stream.
  611. *
  612. * This function does formatted printing to the stream.
  613. *
  614. * \param context a pointer to an SDL_IOStream structure.
  615. * \param fmt a printf() style format string.
  616. * \param ap a variable argument list.
  617. * \returns the number of bytes written or 0 on failure; call SDL_GetError()
  618. * for more information.
  619. *
  620. * \threadsafety This function is not thread safe.
  621. *
  622. * \since This function is available since SDL 3.2.0.
  623. *
  624. * \sa SDL_IOprintf
  625. * \sa SDL_WriteIO
  626. */
  627. extern SDL_DECLSPEC size_t SDLCALL SDL_IOvprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  628. /**
  629. * Flush any buffered data in the stream.
  630. *
  631. * This function makes sure that any buffered data is written to the stream.
  632. * Normally this isn't necessary but if the stream is a pipe or socket it
  633. * guarantees that any pending data is sent.
  634. *
  635. * \param context SDL_IOStream structure to flush.
  636. * \returns true on success or false on failure; call SDL_GetError() for more
  637. * information.
  638. *
  639. * \threadsafety This function is not thread safe.
  640. *
  641. * \since This function is available since SDL 3.2.0.
  642. *
  643. * \sa SDL_OpenIO
  644. * \sa SDL_WriteIO
  645. */
  646. extern SDL_DECLSPEC bool SDLCALL SDL_FlushIO(SDL_IOStream *context);
  647. /**
  648. * Load all the data from an SDL data stream.
  649. *
  650. * The data is allocated with a zero byte at the end (null terminated) for
  651. * convenience. This extra byte is not included in the value reported via
  652. * `datasize`.
  653. *
  654. * The data should be freed with SDL_free().
  655. *
  656. * \param src the SDL_IOStream to read all available data from.
  657. * \param datasize a pointer filled in with the number of bytes read, may be
  658. * NULL.
  659. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  660. * in the case of an error.
  661. * \returns the data or NULL on failure; call SDL_GetError() for more
  662. * information.
  663. *
  664. * \threadsafety This function is not thread safe.
  665. *
  666. * \since This function is available since SDL 3.2.0.
  667. *
  668. * \sa SDL_LoadFile
  669. * \sa SDL_SaveFile_IO
  670. */
  671. extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio);
  672. /**
  673. * Load all the data from a file path.
  674. *
  675. * The data is allocated with a zero byte at the end (null terminated) for
  676. * convenience. This extra byte is not included in the value reported via
  677. * `datasize`.
  678. *
  679. * The data should be freed with SDL_free().
  680. *
  681. * \param file the path to read all available data from.
  682. * \param datasize if not NULL, will store the number of bytes read.
  683. * \returns the data or NULL on failure; call SDL_GetError() for more
  684. * information.
  685. *
  686. * \threadsafety This function is not thread safe.
  687. *
  688. * \since This function is available since SDL 3.2.0.
  689. *
  690. * \sa SDL_LoadFile_IO
  691. * \sa SDL_SaveFile
  692. */
  693. extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
  694. /**
  695. * Save all the data into an SDL data stream.
  696. *
  697. * \param src the SDL_IOStream to write all data to.
  698. * \param data the data to be written. If datasize is 0, may be NULL or a
  699. * invalid pointer.
  700. * \param datasize the number of bytes to be written.
  701. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  702. * in the case of an error.
  703. * \returns true on success or false on failure; call SDL_GetError() for more
  704. * information.
  705. *
  706. * \threadsafety This function is not thread safe.
  707. *
  708. * \since This function is available since SDL 3.2.0.
  709. *
  710. * \sa SDL_SaveFile
  711. * \sa SDL_LoadFile_IO
  712. */
  713. extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool closeio);
  714. /**
  715. * Save all the data into a file path.
  716. *
  717. * \param file the path to write all available data into.
  718. * \param data the data to be written. If datasize is 0, may be NULL or a
  719. * invalid pointer.
  720. * \param datasize the number of bytes to be written.
  721. * \returns true on success or false on failure; call SDL_GetError() for more
  722. * information.
  723. *
  724. * \threadsafety This function is not thread safe.
  725. *
  726. * \since This function is available since SDL 3.2.0.
  727. *
  728. * \sa SDL_SaveFile_IO
  729. * \sa SDL_LoadFile
  730. */
  731. extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile(const char *file, const void *data, size_t datasize);
  732. /**
  733. * \name Read endian functions
  734. *
  735. * Read an item of the specified endianness and return in native format.
  736. */
  737. /* @{ */
  738. /**
  739. * Use this function to read a byte from an SDL_IOStream.
  740. *
  741. * This function will return false when the data stream is completely read,
  742. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  743. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  744. * error value and SDL_GetError() will offer a human-readable message.
  745. *
  746. * \param src the SDL_IOStream to read from.
  747. * \param value a pointer filled in with the data read.
  748. * \returns true on success or false on failure or EOF; call SDL_GetError()
  749. * for more information.
  750. *
  751. * \threadsafety This function is not thread safe.
  752. *
  753. * \since This function is available since SDL 3.2.0.
  754. */
  755. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU8(SDL_IOStream *src, Uint8 *value);
  756. /**
  757. * Use this function to read a signed byte from an SDL_IOStream.
  758. *
  759. * This function will return false when the data stream is completely read,
  760. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  761. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  762. * error value and SDL_GetError() will offer a human-readable message.
  763. *
  764. * \param src the SDL_IOStream to read from.
  765. * \param value a pointer filled in with the data read.
  766. * \returns true on success or false on failure; call SDL_GetError() for more
  767. * information.
  768. *
  769. * \threadsafety This function is not thread safe.
  770. *
  771. * \since This function is available since SDL 3.2.0.
  772. */
  773. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS8(SDL_IOStream *src, Sint8 *value);
  774. /**
  775. * Use this function to read 16 bits of little-endian data from an
  776. * SDL_IOStream and return in native format.
  777. *
  778. * SDL byteswaps the data only if necessary, so the data returned will be in
  779. * the native byte order.
  780. *
  781. * This function will return false when the data stream is completely read,
  782. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  783. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  784. * error value and SDL_GetError() will offer a human-readable message.
  785. *
  786. * \param src the stream from which to read data.
  787. * \param value a pointer filled in with the data read.
  788. * \returns true on successful read or false on failure; call SDL_GetError()
  789. * for more information.
  790. *
  791. * \threadsafety This function is not thread safe.
  792. *
  793. * \since This function is available since SDL 3.2.0.
  794. */
  795. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16LE(SDL_IOStream *src, Uint16 *value);
  796. /**
  797. * Use this function to read 16 bits of little-endian data from an
  798. * SDL_IOStream and return in native format.
  799. *
  800. * SDL byteswaps the data only if necessary, so the data returned will be in
  801. * the native byte order.
  802. *
  803. * This function will return false when the data stream is completely read,
  804. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  805. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  806. * error value and SDL_GetError() will offer a human-readable message.
  807. *
  808. * \param src the stream from which to read data.
  809. * \param value a pointer filled in with the data read.
  810. * \returns true on successful read or false on failure; call SDL_GetError()
  811. * for more information.
  812. *
  813. * \threadsafety This function is not thread safe.
  814. *
  815. * \since This function is available since SDL 3.2.0.
  816. */
  817. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16LE(SDL_IOStream *src, Sint16 *value);
  818. /**
  819. * Use this function to read 16 bits of big-endian data from an SDL_IOStream
  820. * and return in native format.
  821. *
  822. * SDL byteswaps the data only if necessary, so the data returned will be in
  823. * the native byte order.
  824. *
  825. * This function will return false when the data stream is completely read,
  826. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  827. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  828. * error value and SDL_GetError() will offer a human-readable message.
  829. *
  830. * \param src the stream from which to read data.
  831. * \param value a pointer filled in with the data read.
  832. * \returns true on successful read or false on failure; call SDL_GetError()
  833. * for more information.
  834. *
  835. * \threadsafety This function is not thread safe.
  836. *
  837. * \since This function is available since SDL 3.2.0.
  838. */
  839. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value);
  840. /**
  841. * Use this function to read 16 bits of big-endian data from an SDL_IOStream
  842. * and return in native format.
  843. *
  844. * SDL byteswaps the data only if necessary, so the data returned will be in
  845. * the native byte order.
  846. *
  847. * This function will return false when the data stream is completely read,
  848. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  849. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  850. * error value and SDL_GetError() will offer a human-readable message.
  851. *
  852. * \param src the stream from which to read data.
  853. * \param value a pointer filled in with the data read.
  854. * \returns true on successful read or false on failure; call SDL_GetError()
  855. * for more information.
  856. *
  857. * \threadsafety This function is not thread safe.
  858. *
  859. * \since This function is available since SDL 3.2.0.
  860. */
  861. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16BE(SDL_IOStream *src, Sint16 *value);
  862. /**
  863. * Use this function to read 32 bits of little-endian data from an
  864. * SDL_IOStream and return in native format.
  865. *
  866. * SDL byteswaps the data only if necessary, so the data returned will be in
  867. * the native byte order.
  868. *
  869. * This function will return false when the data stream is completely read,
  870. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  871. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  872. * error value and SDL_GetError() will offer a human-readable message.
  873. *
  874. * \param src the stream from which to read data.
  875. * \param value a pointer filled in with the data read.
  876. * \returns true on successful read or false on failure; call SDL_GetError()
  877. * for more information.
  878. *
  879. * \threadsafety This function is not thread safe.
  880. *
  881. * \since This function is available since SDL 3.2.0.
  882. */
  883. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32LE(SDL_IOStream *src, Uint32 *value);
  884. /**
  885. * Use this function to read 32 bits of little-endian data from an
  886. * SDL_IOStream and return in native format.
  887. *
  888. * SDL byteswaps the data only if necessary, so the data returned will be in
  889. * the native byte order.
  890. *
  891. * This function will return false when the data stream is completely read,
  892. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  893. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  894. * error value and SDL_GetError() will offer a human-readable message.
  895. *
  896. * \param src the stream from which to read data.
  897. * \param value a pointer filled in with the data read.
  898. * \returns true on successful read or false on failure; call SDL_GetError()
  899. * for more information.
  900. *
  901. * \threadsafety This function is not thread safe.
  902. *
  903. * \since This function is available since SDL 3.2.0.
  904. */
  905. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32LE(SDL_IOStream *src, Sint32 *value);
  906. /**
  907. * Use this function to read 32 bits of big-endian data from an SDL_IOStream
  908. * and return in native format.
  909. *
  910. * SDL byteswaps the data only if necessary, so the data returned will be in
  911. * the native byte order.
  912. *
  913. * This function will return false when the data stream is completely read,
  914. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  915. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  916. * error value and SDL_GetError() will offer a human-readable message.
  917. *
  918. * \param src the stream from which to read data.
  919. * \param value a pointer filled in with the data read.
  920. * \returns true on successful read or false on failure; call SDL_GetError()
  921. * for more information.
  922. *
  923. * \threadsafety This function is not thread safe.
  924. *
  925. * \since This function is available since SDL 3.2.0.
  926. */
  927. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32BE(SDL_IOStream *src, Uint32 *value);
  928. /**
  929. * Use this function to read 32 bits of big-endian data from an SDL_IOStream
  930. * and return in native format.
  931. *
  932. * SDL byteswaps the data only if necessary, so the data returned will be in
  933. * the native byte order.
  934. *
  935. * This function will return false when the data stream is completely read,
  936. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  937. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  938. * error value and SDL_GetError() will offer a human-readable message.
  939. *
  940. * \param src the stream from which to read data.
  941. * \param value a pointer filled in with the data read.
  942. * \returns true on successful read or false on failure; call SDL_GetError()
  943. * for more information.
  944. *
  945. * \threadsafety This function is not thread safe.
  946. *
  947. * \since This function is available since SDL 3.2.0.
  948. */
  949. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32BE(SDL_IOStream *src, Sint32 *value);
  950. /**
  951. * Use this function to read 64 bits of little-endian data from an
  952. * SDL_IOStream and return in native format.
  953. *
  954. * SDL byteswaps the data only if necessary, so the data returned will be in
  955. * the native byte order.
  956. *
  957. * This function will return false when the data stream is completely read,
  958. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  959. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  960. * error value and SDL_GetError() will offer a human-readable message.
  961. *
  962. * \param src the stream from which to read data.
  963. * \param value a pointer filled in with the data read.
  964. * \returns true on successful read or false on failure; call SDL_GetError()
  965. * for more information.
  966. *
  967. * \threadsafety This function is not thread safe.
  968. *
  969. * \since This function is available since SDL 3.2.0.
  970. */
  971. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64LE(SDL_IOStream *src, Uint64 *value);
  972. /**
  973. * Use this function to read 64 bits of little-endian data from an
  974. * SDL_IOStream and return in native format.
  975. *
  976. * SDL byteswaps the data only if necessary, so the data returned will be in
  977. * the native byte order.
  978. *
  979. * This function will return false when the data stream is completely read,
  980. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  981. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  982. * error value and SDL_GetError() will offer a human-readable message.
  983. *
  984. * \param src the stream from which to read data.
  985. * \param value a pointer filled in with the data read.
  986. * \returns true on successful read or false on failure; call SDL_GetError()
  987. * for more information.
  988. *
  989. * \threadsafety This function is not thread safe.
  990. *
  991. * \since This function is available since SDL 3.2.0.
  992. */
  993. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64LE(SDL_IOStream *src, Sint64 *value);
  994. /**
  995. * Use this function to read 64 bits of big-endian data from an SDL_IOStream
  996. * and return in native format.
  997. *
  998. * SDL byteswaps the data only if necessary, so the data returned will be in
  999. * the native byte order.
  1000. *
  1001. * This function will return false when the data stream is completely read,
  1002. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  1003. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  1004. * error value and SDL_GetError() will offer a human-readable message.
  1005. *
  1006. * \param src the stream from which to read data.
  1007. * \param value a pointer filled in with the data read.
  1008. * \returns true on successful read or false on failure; call SDL_GetError()
  1009. * for more information.
  1010. *
  1011. * \threadsafety This function is not thread safe.
  1012. *
  1013. * \since This function is available since SDL 3.2.0.
  1014. */
  1015. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64BE(SDL_IOStream *src, Uint64 *value);
  1016. /**
  1017. * Use this function to read 64 bits of big-endian data from an SDL_IOStream
  1018. * and return in native format.
  1019. *
  1020. * SDL byteswaps the data only if necessary, so the data returned will be in
  1021. * the native byte order.
  1022. *
  1023. * This function will return false when the data stream is completely read,
  1024. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  1025. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  1026. * error value and SDL_GetError() will offer a human-readable message.
  1027. *
  1028. * \param src the stream from which to read data.
  1029. * \param value a pointer filled in with the data read.
  1030. * \returns true on successful read or false on failure; call SDL_GetError()
  1031. * for more information.
  1032. *
  1033. * \threadsafety This function is not thread safe.
  1034. *
  1035. * \since This function is available since SDL 3.2.0.
  1036. */
  1037. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64BE(SDL_IOStream *src, Sint64 *value);
  1038. /* @} *//* Read endian functions */
  1039. /**
  1040. * \name Write endian functions
  1041. *
  1042. * Write an item of native format to the specified endianness.
  1043. */
  1044. /* @{ */
  1045. /**
  1046. * Use this function to write a byte to an SDL_IOStream.
  1047. *
  1048. * \param dst the SDL_IOStream to write to.
  1049. * \param value the byte value to write.
  1050. * \returns true on successful write or false on failure; call SDL_GetError()
  1051. * for more information.
  1052. *
  1053. * \threadsafety This function is not thread safe.
  1054. *
  1055. * \since This function is available since SDL 3.2.0.
  1056. */
  1057. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU8(SDL_IOStream *dst, Uint8 value);
  1058. /**
  1059. * Use this function to write a signed byte to an SDL_IOStream.
  1060. *
  1061. * \param dst the SDL_IOStream to write to.
  1062. * \param value the byte value to write.
  1063. * \returns true on successful write or false on failure; call SDL_GetError()
  1064. * for more information.
  1065. *
  1066. * \threadsafety This function is not thread safe.
  1067. *
  1068. * \since This function is available since SDL 3.2.0.
  1069. */
  1070. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS8(SDL_IOStream *dst, Sint8 value);
  1071. /**
  1072. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1073. * little-endian data.
  1074. *
  1075. * SDL byteswaps the data only if necessary, so the application always
  1076. * specifies native format, and the data written will be in little-endian
  1077. * format.
  1078. *
  1079. * \param dst the stream to which data will be written.
  1080. * \param value the data to be written, in native format.
  1081. * \returns true on successful write or false on failure; call SDL_GetError()
  1082. * for more information.
  1083. *
  1084. * \threadsafety This function is not thread safe.
  1085. *
  1086. * \since This function is available since SDL 3.2.0.
  1087. */
  1088. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16LE(SDL_IOStream *dst, Uint16 value);
  1089. /**
  1090. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1091. * little-endian data.
  1092. *
  1093. * SDL byteswaps the data only if necessary, so the application always
  1094. * specifies native format, and the data written will be in little-endian
  1095. * format.
  1096. *
  1097. * \param dst the stream to which data will be written.
  1098. * \param value the data to be written, in native format.
  1099. * \returns true on successful write or false on failure; call SDL_GetError()
  1100. * for more information.
  1101. *
  1102. * \threadsafety This function is not thread safe.
  1103. *
  1104. * \since This function is available since SDL 3.2.0.
  1105. */
  1106. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16LE(SDL_IOStream *dst, Sint16 value);
  1107. /**
  1108. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1109. * big-endian data.
  1110. *
  1111. * SDL byteswaps the data only if necessary, so the application always
  1112. * specifies native format, and the data written will be in big-endian format.
  1113. *
  1114. * \param dst the stream to which data will be written.
  1115. * \param value the data to be written, in native format.
  1116. * \returns true on successful write or false on failure; call SDL_GetError()
  1117. * for more information.
  1118. *
  1119. * \threadsafety This function is not thread safe.
  1120. *
  1121. * \since This function is available since SDL 3.2.0.
  1122. */
  1123. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16BE(SDL_IOStream *dst, Uint16 value);
  1124. /**
  1125. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1126. * big-endian data.
  1127. *
  1128. * SDL byteswaps the data only if necessary, so the application always
  1129. * specifies native format, and the data written will be in big-endian format.
  1130. *
  1131. * \param dst the stream to which data will be written.
  1132. * \param value the data to be written, in native format.
  1133. * \returns true on successful write or false on failure; call SDL_GetError()
  1134. * for more information.
  1135. *
  1136. * \threadsafety This function is not thread safe.
  1137. *
  1138. * \since This function is available since SDL 3.2.0.
  1139. */
  1140. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16BE(SDL_IOStream *dst, Sint16 value);
  1141. /**
  1142. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1143. * little-endian data.
  1144. *
  1145. * SDL byteswaps the data only if necessary, so the application always
  1146. * specifies native format, and the data written will be in little-endian
  1147. * format.
  1148. *
  1149. * \param dst the stream to which data will be written.
  1150. * \param value the data to be written, in native format.
  1151. * \returns true on successful write or false on failure; call SDL_GetError()
  1152. * for more information.
  1153. *
  1154. * \threadsafety This function is not thread safe.
  1155. *
  1156. * \since This function is available since SDL 3.2.0.
  1157. */
  1158. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32LE(SDL_IOStream *dst, Uint32 value);
  1159. /**
  1160. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1161. * little-endian data.
  1162. *
  1163. * SDL byteswaps the data only if necessary, so the application always
  1164. * specifies native format, and the data written will be in little-endian
  1165. * format.
  1166. *
  1167. * \param dst the stream to which data will be written.
  1168. * \param value the data to be written, in native format.
  1169. * \returns true on successful write or false on failure; call SDL_GetError()
  1170. * for more information.
  1171. *
  1172. * \threadsafety This function is not thread safe.
  1173. *
  1174. * \since This function is available since SDL 3.2.0.
  1175. */
  1176. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32LE(SDL_IOStream *dst, Sint32 value);
  1177. /**
  1178. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1179. * big-endian data.
  1180. *
  1181. * SDL byteswaps the data only if necessary, so the application always
  1182. * specifies native format, and the data written will be in big-endian format.
  1183. *
  1184. * \param dst the stream to which data will be written.
  1185. * \param value the data to be written, in native format.
  1186. * \returns true on successful write or false on failure; call SDL_GetError()
  1187. * for more information.
  1188. *
  1189. * \threadsafety This function is not thread safe.
  1190. *
  1191. * \since This function is available since SDL 3.2.0.
  1192. */
  1193. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32BE(SDL_IOStream *dst, Uint32 value);
  1194. /**
  1195. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1196. * big-endian data.
  1197. *
  1198. * SDL byteswaps the data only if necessary, so the application always
  1199. * specifies native format, and the data written will be in big-endian format.
  1200. *
  1201. * \param dst the stream to which data will be written.
  1202. * \param value the data to be written, in native format.
  1203. * \returns true on successful write or false on failure; call SDL_GetError()
  1204. * for more information.
  1205. *
  1206. * \threadsafety This function is not thread safe.
  1207. *
  1208. * \since This function is available since SDL 3.2.0.
  1209. */
  1210. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32BE(SDL_IOStream *dst, Sint32 value);
  1211. /**
  1212. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1213. * little-endian data.
  1214. *
  1215. * SDL byteswaps the data only if necessary, so the application always
  1216. * specifies native format, and the data written will be in little-endian
  1217. * format.
  1218. *
  1219. * \param dst the stream to which data will be written.
  1220. * \param value the data to be written, in native format.
  1221. * \returns true on successful write or false on failure; call SDL_GetError()
  1222. * for more information.
  1223. *
  1224. * \threadsafety This function is not thread safe.
  1225. *
  1226. * \since This function is available since SDL 3.2.0.
  1227. */
  1228. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64LE(SDL_IOStream *dst, Uint64 value);
  1229. /**
  1230. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1231. * little-endian data.
  1232. *
  1233. * SDL byteswaps the data only if necessary, so the application always
  1234. * specifies native format, and the data written will be in little-endian
  1235. * format.
  1236. *
  1237. * \param dst the stream to which data will be written.
  1238. * \param value the data to be written, in native format.
  1239. * \returns true on successful write or false on failure; call SDL_GetError()
  1240. * for more information.
  1241. *
  1242. * \threadsafety This function is not thread safe.
  1243. *
  1244. * \since This function is available since SDL 3.2.0.
  1245. */
  1246. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64LE(SDL_IOStream *dst, Sint64 value);
  1247. /**
  1248. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1249. * big-endian data.
  1250. *
  1251. * SDL byteswaps the data only if necessary, so the application always
  1252. * specifies native format, and the data written will be in big-endian format.
  1253. *
  1254. * \param dst the stream to which data will be written.
  1255. * \param value the data to be written, in native format.
  1256. * \returns true on successful write or false on failure; call SDL_GetError()
  1257. * for more information.
  1258. *
  1259. * \threadsafety This function is not thread safe.
  1260. *
  1261. * \since This function is available since SDL 3.2.0.
  1262. */
  1263. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64BE(SDL_IOStream *dst, Uint64 value);
  1264. /**
  1265. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1266. * big-endian data.
  1267. *
  1268. * SDL byteswaps the data only if necessary, so the application always
  1269. * specifies native format, and the data written will be in big-endian format.
  1270. *
  1271. * \param dst the stream to which data will be written.
  1272. * \param value the data to be written, in native format.
  1273. * \returns true on successful write or false on failure; call SDL_GetError()
  1274. * for more information.
  1275. *
  1276. * \threadsafety This function is not thread safe.
  1277. *
  1278. * \since This function is available since SDL 3.2.0.
  1279. */
  1280. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64BE(SDL_IOStream *dst, Sint64 value);
  1281. /* @} *//* Write endian functions */
  1282. /* Ends C function definitions when using C++ */
  1283. #ifdef __cplusplus
  1284. }
  1285. #endif
  1286. #include <SDL3/SDL_close_code.h>
  1287. #endif /* SDL_iostream_h_ */