SDL_iostream.h 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. /* 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.1.3.
  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.1.3.
  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.1.3.
  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.1.3.
  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. * \since This function is available since SDL 3.1.3.
  241. *
  242. * \sa SDL_CloseIO
  243. * \sa SDL_FlushIO
  244. * \sa SDL_ReadIO
  245. * \sa SDL_SeekIO
  246. * \sa SDL_TellIO
  247. * \sa SDL_WriteIO
  248. */
  249. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, const char *mode);
  250. #define SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER "SDL.iostream.windows.handle"
  251. #define SDL_PROP_IOSTREAM_STDIO_FILE_POINTER "SDL.iostream.stdio.file"
  252. #define SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER "SDL.iostream.file_descriptor"
  253. #define SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER "SDL.iostream.android.aasset"
  254. /**
  255. * Use this function to prepare a read-write memory buffer for use with
  256. * SDL_IOStream.
  257. *
  258. * This function sets up an SDL_IOStream struct based on a memory area of a
  259. * certain size, for both read and write access.
  260. *
  261. * This memory buffer is not copied by the SDL_IOStream; the pointer you
  262. * provide must remain valid until you close the stream. Closing the stream
  263. * will not free the original buffer.
  264. *
  265. * If you need to make sure the SDL_IOStream never writes to the memory
  266. * buffer, you should use SDL_IOFromConstMem() with a read-only buffer of
  267. * memory instead.
  268. *
  269. * The following properties will be set at creation time by SDL:
  270. *
  271. * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
  272. * was passed to this function.
  273. * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
  274. * that was passed to this function.
  275. *
  276. * \param mem a pointer to a buffer to feed an SDL_IOStream stream.
  277. * \param size the buffer size, in bytes.
  278. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  279. * SDL_GetError() for more information.
  280. *
  281. * \since This function is available since SDL 3.1.3.
  282. *
  283. * \sa SDL_IOFromConstMem
  284. * \sa SDL_CloseIO
  285. * \sa SDL_FlushIO
  286. * \sa SDL_ReadIO
  287. * \sa SDL_SeekIO
  288. * \sa SDL_TellIO
  289. * \sa SDL_WriteIO
  290. */
  291. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size);
  292. #define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base"
  293. #define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size"
  294. /**
  295. * Use this function to prepare a read-only memory buffer for use with
  296. * SDL_IOStream.
  297. *
  298. * This function sets up an SDL_IOStream struct based on a memory area of a
  299. * certain size. It assumes the memory area is not writable.
  300. *
  301. * Attempting to write to this SDL_IOStream stream will report an error
  302. * without writing to the memory buffer.
  303. *
  304. * This memory buffer is not copied by the SDL_IOStream; the pointer you
  305. * provide must remain valid until you close the stream. Closing the stream
  306. * will not free the original buffer.
  307. *
  308. * If you need to write to a memory buffer, you should use SDL_IOFromMem()
  309. * with a writable buffer of memory instead.
  310. *
  311. * The following properties will be set at creation time by SDL:
  312. *
  313. * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
  314. * was passed to this function.
  315. * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
  316. * that was passed to this function.
  317. *
  318. * \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream.
  319. * \param size the buffer size, in bytes.
  320. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  321. * SDL_GetError() for more information.
  322. *
  323. * \since This function is available since SDL 3.1.3.
  324. *
  325. * \sa SDL_IOFromMem
  326. * \sa SDL_CloseIO
  327. * \sa SDL_ReadIO
  328. * \sa SDL_SeekIO
  329. * \sa SDL_TellIO
  330. */
  331. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromConstMem(const void *mem, size_t size);
  332. /**
  333. * Use this function to create an SDL_IOStream that is backed by dynamically
  334. * allocated memory.
  335. *
  336. * This supports the following properties to provide access to the memory and
  337. * control over allocations:
  338. *
  339. * - `SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER`: a pointer to the internal
  340. * memory of the stream. This can be set to NULL to transfer ownership of
  341. * the memory to the application, which should free the memory with
  342. * SDL_free(). If this is done, the next operation on the stream must be
  343. * SDL_CloseIO().
  344. * - `SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER`: memory will be allocated in
  345. * multiples of this size, defaulting to 1024.
  346. *
  347. * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
  348. * SDL_GetError() for more information.
  349. *
  350. * \since This function is available since SDL 3.1.3.
  351. *
  352. * \sa SDL_CloseIO
  353. * \sa SDL_ReadIO
  354. * \sa SDL_SeekIO
  355. * \sa SDL_TellIO
  356. * \sa SDL_WriteIO
  357. */
  358. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromDynamicMem(void);
  359. #define SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER "SDL.iostream.dynamic.memory"
  360. #define SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER "SDL.iostream.dynamic.chunksize"
  361. /* @} *//* IOFrom functions */
  362. /**
  363. * Create a custom SDL_IOStream.
  364. *
  365. * Applications do not need to use this function unless they are providing
  366. * their own SDL_IOStream implementation. If you just need an SDL_IOStream to
  367. * read/write a common data source, you should use the built-in
  368. * implementations in SDL, like SDL_IOFromFile() or SDL_IOFromMem(), etc.
  369. *
  370. * This function makes a copy of `iface` and the caller does not need to keep
  371. * it around after this call.
  372. *
  373. * \param iface the interface that implements this SDL_IOStream, initialized
  374. * using SDL_INIT_INTERFACE().
  375. * \param userdata the pointer that will be passed to the interface functions.
  376. * \returns a pointer to the allocated memory on success or NULL on failure;
  377. * call SDL_GetError() for more information.
  378. *
  379. * \since This function is available since SDL 3.1.3.
  380. *
  381. * \sa SDL_CloseIO
  382. * \sa SDL_INIT_INTERFACE
  383. * \sa SDL_IOFromConstMem
  384. * \sa SDL_IOFromFile
  385. * \sa SDL_IOFromMem
  386. */
  387. extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata);
  388. /**
  389. * Close and free an allocated SDL_IOStream structure.
  390. *
  391. * SDL_CloseIO() closes and cleans up the SDL_IOStream stream. It releases any
  392. * resources used by the stream and frees the SDL_IOStream itself. This
  393. * returns true on success, or false if the stream failed to flush to its
  394. * output (e.g. to disk).
  395. *
  396. * Note that if this fails to flush the stream for any reason, this function
  397. * reports an error, but the SDL_IOStream is still invalid once this function
  398. * returns.
  399. *
  400. * This call flushes any buffered writes to the operating system, but there
  401. * are no guarantees that those writes have gone to physical media; they might
  402. * be in the OS's file cache, waiting to go to disk later. If it's absolutely
  403. * crucial that writes go to disk immediately, so they are definitely stored
  404. * even if the power fails before the file cache would have caught up, one
  405. * should call SDL_FlushIO() before closing. Note that flushing takes time and
  406. * makes the system and your app operate less efficiently, so do so sparingly.
  407. *
  408. * \param context SDL_IOStream structure to close.
  409. * \returns true on success or false on failure; call SDL_GetError() for more
  410. * information.
  411. *
  412. * \since This function is available since SDL 3.1.3.
  413. *
  414. * \sa SDL_OpenIO
  415. */
  416. extern SDL_DECLSPEC bool SDLCALL SDL_CloseIO(SDL_IOStream *context);
  417. /**
  418. * Get the properties associated with an SDL_IOStream.
  419. *
  420. * \param context a pointer to an SDL_IOStream structure.
  421. * \returns a valid property ID on success or 0 on failure; call
  422. * SDL_GetError() for more information.
  423. *
  424. * \since This function is available since SDL 3.1.3.
  425. */
  426. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetIOProperties(SDL_IOStream *context);
  427. /**
  428. * Query the stream status of an SDL_IOStream.
  429. *
  430. * This information can be useful to decide if a short read or write was due
  431. * to an error, an EOF, or a non-blocking operation that isn't yet ready to
  432. * complete.
  433. *
  434. * An SDL_IOStream's status is only expected to change after a SDL_ReadIO or
  435. * SDL_WriteIO call; don't expect it to change if you just call this query
  436. * function in a tight loop.
  437. *
  438. * \param context the SDL_IOStream to query.
  439. * \returns an SDL_IOStatus enum with the current state.
  440. *
  441. * \threadsafety This function should not be called at the same time that
  442. * another thread is operating on the same SDL_IOStream.
  443. *
  444. * \since This function is available since SDL 3.1.3.
  445. */
  446. extern SDL_DECLSPEC SDL_IOStatus SDLCALL SDL_GetIOStatus(SDL_IOStream *context);
  447. /**
  448. * Use this function to get the size of the data stream in an SDL_IOStream.
  449. *
  450. * \param context the SDL_IOStream to get the size of the data stream from.
  451. * \returns the size of the data stream in the SDL_IOStream on success or a
  452. * negative error code on failure; call SDL_GetError() for more
  453. * information.
  454. *
  455. * \since This function is available since SDL 3.1.3.
  456. */
  457. extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetIOSize(SDL_IOStream *context);
  458. /**
  459. * Seek within an SDL_IOStream data stream.
  460. *
  461. * This function seeks to byte `offset`, relative to `whence`.
  462. *
  463. * `whence` may be any of the following values:
  464. *
  465. * - `SDL_IO_SEEK_SET`: seek from the beginning of data
  466. * - `SDL_IO_SEEK_CUR`: seek relative to current read point
  467. * - `SDL_IO_SEEK_END`: seek relative to the end of data
  468. *
  469. * If this stream can not seek, it will return -1.
  470. *
  471. * \param context a pointer to an SDL_IOStream structure.
  472. * \param offset an offset in bytes, relative to `whence` location; can be
  473. * negative.
  474. * \param whence any of `SDL_IO_SEEK_SET`, `SDL_IO_SEEK_CUR`,
  475. * `SDL_IO_SEEK_END`.
  476. * \returns the final offset in the data stream after the seek or -1 on
  477. * failure; call SDL_GetError() for more information.
  478. *
  479. * \since This function is available since SDL 3.1.3.
  480. *
  481. * \sa SDL_TellIO
  482. */
  483. extern SDL_DECLSPEC Sint64 SDLCALL SDL_SeekIO(SDL_IOStream *context, Sint64 offset, SDL_IOWhence whence);
  484. /**
  485. * Determine the current read/write offset in an SDL_IOStream data stream.
  486. *
  487. * SDL_TellIO is actually a wrapper function that calls the SDL_IOStream's
  488. * `seek` method, with an offset of 0 bytes from `SDL_IO_SEEK_CUR`, to
  489. * simplify application development.
  490. *
  491. * \param context an SDL_IOStream data stream object from which to get the
  492. * current offset.
  493. * \returns the current offset in the stream, or -1 if the information can not
  494. * be determined.
  495. *
  496. * \since This function is available since SDL 3.1.3.
  497. *
  498. * \sa SDL_SeekIO
  499. */
  500. extern SDL_DECLSPEC Sint64 SDLCALL SDL_TellIO(SDL_IOStream *context);
  501. /**
  502. * Read from a data source.
  503. *
  504. * This function reads up `size` bytes from the data source to the area
  505. * pointed at by `ptr`. This function may read less bytes than requested.
  506. *
  507. * This function will return zero when the data stream is completely read, and
  508. * SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If zero is returned and
  509. * the stream is not at EOF, SDL_GetIOStatus() will return a different error
  510. * value and SDL_GetError() will offer a human-readable message.
  511. *
  512. * \param context a pointer to an SDL_IOStream structure.
  513. * \param ptr a pointer to a buffer to read data into.
  514. * \param size the number of bytes to read from the data source.
  515. * \returns the number of bytes read, or 0 on end of file or other failure;
  516. * call SDL_GetError() for more information.
  517. *
  518. * \since This function is available since SDL 3.1.3.
  519. *
  520. * \sa SDL_WriteIO
  521. * \sa SDL_GetIOStatus
  522. */
  523. extern SDL_DECLSPEC size_t SDLCALL SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size);
  524. /**
  525. * Write to an SDL_IOStream data stream.
  526. *
  527. * This function writes exactly `size` bytes from the area pointed at by `ptr`
  528. * to the stream. If this fails for any reason, it'll return less than `size`
  529. * to demonstrate how far the write progressed. On success, it returns `size`.
  530. *
  531. * On error, this function still attempts to write as much as possible, so it
  532. * might return a positive value less than the requested write size.
  533. *
  534. * The caller can use SDL_GetIOStatus() to determine if the problem is
  535. * recoverable, such as a non-blocking write that can simply be retried later,
  536. * or a fatal error.
  537. *
  538. * \param context a pointer to an SDL_IOStream structure.
  539. * \param ptr a pointer to a buffer containing data to write.
  540. * \param size the number of bytes to write.
  541. * \returns the number of bytes written, which will be less than `size` on
  542. * failure; call SDL_GetError() for more information.
  543. *
  544. * \since This function is available since SDL 3.1.3.
  545. *
  546. * \sa SDL_IOprintf
  547. * \sa SDL_ReadIO
  548. * \sa SDL_SeekIO
  549. * \sa SDL_FlushIO
  550. * \sa SDL_GetIOStatus
  551. */
  552. extern SDL_DECLSPEC size_t SDLCALL SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size);
  553. /**
  554. * Print to an SDL_IOStream data stream.
  555. *
  556. * This function does formatted printing to the stream.
  557. *
  558. * \param context a pointer to an SDL_IOStream structure.
  559. * \param fmt a printf() style format string.
  560. * \param ... additional parameters matching % tokens in the `fmt` string, if
  561. * any.
  562. * \returns the number of bytes written or 0 on failure; call SDL_GetError()
  563. * for more information.
  564. *
  565. * \since This function is available since SDL 3.1.3.
  566. *
  567. * \sa SDL_IOvprintf
  568. * \sa SDL_WriteIO
  569. */
  570. extern SDL_DECLSPEC size_t SDLCALL SDL_IOprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  571. /**
  572. * Print to an SDL_IOStream data stream.
  573. *
  574. * This function does formatted printing to the stream.
  575. *
  576. * \param context a pointer to an SDL_IOStream structure.
  577. * \param fmt a printf() style format string.
  578. * \param ap a variable argument list.
  579. * \returns the number of bytes written or 0 on failure; call SDL_GetError()
  580. * for more information.
  581. *
  582. * \since This function is available since SDL 3.1.3.
  583. *
  584. * \sa SDL_IOprintf
  585. * \sa SDL_WriteIO
  586. */
  587. 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);
  588. /**
  589. * Flush any buffered data in the stream.
  590. *
  591. * This function makes sure that any buffered data is written to the stream.
  592. * Normally this isn't necessary but if the stream is a pipe or socket it
  593. * guarantees that any pending data is sent.
  594. *
  595. * \param context SDL_IOStream structure to flush.
  596. * \returns true on success or false on failure; call SDL_GetError() for more
  597. * information.
  598. *
  599. * \since This function is available since SDL 3.1.3.
  600. *
  601. * \sa SDL_OpenIO
  602. * \sa SDL_WriteIO
  603. */
  604. extern SDL_DECLSPEC bool SDLCALL SDL_FlushIO(SDL_IOStream *context);
  605. /**
  606. * Load all the data from an SDL data stream.
  607. *
  608. * The data is allocated with a zero byte at the end (null terminated) for
  609. * convenience. This extra byte is not included in the value reported via
  610. * `datasize`.
  611. *
  612. * The data should be freed with SDL_free().
  613. *
  614. * \param src the SDL_IOStream to read all available data from.
  615. * \param datasize a pointer filled in with the number of bytes read, may be
  616. * NULL.
  617. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  618. * in the case of an error.
  619. * \returns the data or NULL on failure; call SDL_GetError() for more
  620. * information.
  621. *
  622. * \since This function is available since SDL 3.1.3.
  623. *
  624. * \sa SDL_LoadFile
  625. * \sa SDL_SaveFile_IO
  626. */
  627. extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio);
  628. /**
  629. * Load all the data from a file path.
  630. *
  631. * The data is allocated with a zero byte at the end (null terminated) for
  632. * convenience. This extra byte is not included in the value reported via
  633. * `datasize`.
  634. *
  635. * The data should be freed with SDL_free().
  636. *
  637. * \param file the path to read all available data from.
  638. * \param datasize if not NULL, will store the number of bytes read.
  639. * \returns the data or NULL on failure; call SDL_GetError() for more
  640. * information.
  641. *
  642. * \since This function is available since SDL 3.1.3.
  643. *
  644. * \sa SDL_LoadFile_IO
  645. * \sa SDL_SaveFile
  646. */
  647. extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
  648. /**
  649. * Save all the data into an SDL data stream.
  650. *
  651. * \param src the SDL_IOStream to write all data to.
  652. * \param data the data to be written. If datasize is 0, may be NULL or a
  653. * invalid pointer.
  654. * \param datasize the number of bytes to be written.
  655. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  656. * in the case of an error.
  657. * \returns true on success or false on failure; call SDL_GetError() for more
  658. * information.
  659. *
  660. * \since This function is available since SDL 3.2.0.
  661. *
  662. * \sa SDL_SaveFile
  663. * \sa SDL_LoadFile_IO
  664. */
  665. extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool closeio);
  666. /**
  667. * Save all the data into a file path.
  668. *
  669. * \param file the path to read all available data from.
  670. * \param data the data to be written. If datasize is 0, may be NULL or a
  671. * invalid pointer.
  672. * \param datasize the number of bytes to be written.
  673. * \returns true on success or false on failure; call SDL_GetError() for more
  674. * information.
  675. *
  676. * \since This function is available since SDL 3.2.0.
  677. *
  678. * \sa SDL_SaveFile_IO
  679. * \sa SDL_LoadFile
  680. */
  681. extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile(const char *file, const void *data, size_t datasize);
  682. /**
  683. * \name Read endian functions
  684. *
  685. * Read an item of the specified endianness and return in native format.
  686. */
  687. /* @{ */
  688. /**
  689. * Use this function to read a byte from an SDL_IOStream.
  690. *
  691. * This function will return false when the data stream is completely read,
  692. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  693. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  694. * error value and SDL_GetError() will offer a human-readable message.
  695. *
  696. * \param src the SDL_IOStream to read from.
  697. * \param value a pointer filled in with the data read.
  698. * \returns true on success or false on failure or EOF; call SDL_GetError()
  699. * for more information.
  700. *
  701. * \since This function is available since SDL 3.1.3.
  702. */
  703. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU8(SDL_IOStream *src, Uint8 *value);
  704. /**
  705. * Use this function to read a signed byte from an SDL_IOStream.
  706. *
  707. * This function will return false when the data stream is completely read,
  708. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  709. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  710. * error value and SDL_GetError() will offer a human-readable message.
  711. *
  712. * \param src the SDL_IOStream to read from.
  713. * \param value a pointer filled in with the data read.
  714. * \returns true on success or false on failure; call SDL_GetError() for more
  715. * information.
  716. *
  717. * \since This function is available since SDL 3.1.3.
  718. */
  719. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS8(SDL_IOStream *src, Sint8 *value);
  720. /**
  721. * Use this function to read 16 bits of little-endian data from an
  722. * SDL_IOStream and return in native format.
  723. *
  724. * SDL byteswaps the data only if necessary, so the data returned will be in
  725. * the native byte order.
  726. *
  727. * This function will return false when the data stream is completely read,
  728. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  729. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  730. * error value and SDL_GetError() will offer a human-readable message.
  731. *
  732. * \param src the stream from which to read data.
  733. * \param value a pointer filled in with the data read.
  734. * \returns true on successful write or false on failure; call SDL_GetError()
  735. * for more information.
  736. *
  737. * \since This function is available since SDL 3.1.3.
  738. */
  739. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16LE(SDL_IOStream *src, Uint16 *value);
  740. /**
  741. * Use this function to read 16 bits of little-endian data from an
  742. * SDL_IOStream and return in native format.
  743. *
  744. * SDL byteswaps the data only if necessary, so the data returned will be in
  745. * the native byte order.
  746. *
  747. * This function will return false when the data stream is completely read,
  748. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  749. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  750. * error value and SDL_GetError() will offer a human-readable message.
  751. *
  752. * \param src the stream from which to read data.
  753. * \param value a pointer filled in with the data read.
  754. * \returns true on successful write or false on failure; call SDL_GetError()
  755. * for more information.
  756. *
  757. * \since This function is available since SDL 3.1.3.
  758. */
  759. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16LE(SDL_IOStream *src, Sint16 *value);
  760. /**
  761. * Use this function to read 16 bits of big-endian data from an SDL_IOStream
  762. * and return in native format.
  763. *
  764. * SDL byteswaps the data only if necessary, so the data returned will be in
  765. * the native byte order.
  766. *
  767. * This function will return false when the data stream is completely read,
  768. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  769. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  770. * error value and SDL_GetError() will offer a human-readable message.
  771. *
  772. * \param src the stream from which to read data.
  773. * \param value a pointer filled in with the data read.
  774. * \returns true on successful write or false on failure; call SDL_GetError()
  775. * for more information.
  776. *
  777. * \since This function is available since SDL 3.1.3.
  778. */
  779. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value);
  780. /**
  781. * Use this function to read 16 bits of big-endian data from an SDL_IOStream
  782. * and return in native format.
  783. *
  784. * SDL byteswaps the data only if necessary, so the data returned will be in
  785. * the native byte order.
  786. *
  787. * This function will return false when the data stream is completely read,
  788. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  789. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  790. * error value and SDL_GetError() will offer a human-readable message.
  791. *
  792. * \param src the stream from which to read data.
  793. * \param value a pointer filled in with the data read.
  794. * \returns true on successful write or false on failure; call SDL_GetError()
  795. * for more information.
  796. *
  797. * \since This function is available since SDL 3.1.3.
  798. */
  799. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16BE(SDL_IOStream *src, Sint16 *value);
  800. /**
  801. * Use this function to read 32 bits of little-endian data from an
  802. * SDL_IOStream and return in native format.
  803. *
  804. * SDL byteswaps the data only if necessary, so the data returned will be in
  805. * the native byte order.
  806. *
  807. * This function will return false when the data stream is completely read,
  808. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  809. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  810. * error value and SDL_GetError() will offer a human-readable message.
  811. *
  812. * \param src the stream from which to read data.
  813. * \param value a pointer filled in with the data read.
  814. * \returns true on successful write or false on failure; call SDL_GetError()
  815. * for more information.
  816. *
  817. * \since This function is available since SDL 3.1.3.
  818. */
  819. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32LE(SDL_IOStream *src, Uint32 *value);
  820. /**
  821. * Use this function to read 32 bits of little-endian data from an
  822. * SDL_IOStream and return in native format.
  823. *
  824. * SDL byteswaps the data only if necessary, so the data returned will be in
  825. * the native byte order.
  826. *
  827. * This function will return false when the data stream is completely read,
  828. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  829. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  830. * error value and SDL_GetError() will offer a human-readable message.
  831. *
  832. * \param src the stream from which to read data.
  833. * \param value a pointer filled in with the data read.
  834. * \returns true on successful write or false on failure; call SDL_GetError()
  835. * for more information.
  836. *
  837. * \since This function is available since SDL 3.1.3.
  838. */
  839. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32LE(SDL_IOStream *src, Sint32 *value);
  840. /**
  841. * Use this function to read 32 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 write or false on failure; call SDL_GetError()
  855. * for more information.
  856. *
  857. * \since This function is available since SDL 3.1.3.
  858. */
  859. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32BE(SDL_IOStream *src, Uint32 *value);
  860. /**
  861. * Use this function to read 32 bits of big-endian data from an SDL_IOStream
  862. * and return in native format.
  863. *
  864. * SDL byteswaps the data only if necessary, so the data returned will be in
  865. * the native byte order.
  866. *
  867. * This function will return false when the data stream is completely read,
  868. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  869. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  870. * error value and SDL_GetError() will offer a human-readable message.
  871. *
  872. * \param src the stream from which to read data.
  873. * \param value a pointer filled in with the data read.
  874. * \returns true on successful write or false on failure; call SDL_GetError()
  875. * for more information.
  876. *
  877. * \since This function is available since SDL 3.1.3.
  878. */
  879. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32BE(SDL_IOStream *src, Sint32 *value);
  880. /**
  881. * Use this function to read 64 bits of little-endian data from an
  882. * SDL_IOStream and return in native format.
  883. *
  884. * SDL byteswaps the data only if necessary, so the data returned will be in
  885. * the native byte order.
  886. *
  887. * This function will return false when the data stream is completely read,
  888. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  889. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  890. * error value and SDL_GetError() will offer a human-readable message.
  891. *
  892. * \param src the stream from which to read data.
  893. * \param value a pointer filled in with the data read.
  894. * \returns true on successful write or false on failure; call SDL_GetError()
  895. * for more information.
  896. *
  897. * \since This function is available since SDL 3.1.3.
  898. */
  899. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64LE(SDL_IOStream *src, Uint64 *value);
  900. /**
  901. * Use this function to read 64 bits of little-endian data from an
  902. * SDL_IOStream and return in native format.
  903. *
  904. * SDL byteswaps the data only if necessary, so the data returned will be in
  905. * the native byte order.
  906. *
  907. * This function will return false when the data stream is completely read,
  908. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  909. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  910. * error value and SDL_GetError() will offer a human-readable message.
  911. *
  912. * \param src the stream from which to read data.
  913. * \param value a pointer filled in with the data read.
  914. * \returns true on successful write or false on failure; call SDL_GetError()
  915. * for more information.
  916. *
  917. * \since This function is available since SDL 3.1.3.
  918. */
  919. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64LE(SDL_IOStream *src, Sint64 *value);
  920. /**
  921. * Use this function to read 64 bits of big-endian data from an SDL_IOStream
  922. * and return in native format.
  923. *
  924. * SDL byteswaps the data only if necessary, so the data returned will be in
  925. * the native byte order.
  926. *
  927. * This function will return false when the data stream is completely read,
  928. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  929. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  930. * error value and SDL_GetError() will offer a human-readable message.
  931. *
  932. * \param src the stream from which to read data.
  933. * \param value a pointer filled in with the data read.
  934. * \returns true on successful write or false on failure; call SDL_GetError()
  935. * for more information.
  936. *
  937. * \since This function is available since SDL 3.1.3.
  938. */
  939. extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64BE(SDL_IOStream *src, Uint64 *value);
  940. /**
  941. * Use this function to read 64 bits of big-endian data from an SDL_IOStream
  942. * and return in native format.
  943. *
  944. * SDL byteswaps the data only if necessary, so the data returned will be in
  945. * the native byte order.
  946. *
  947. * This function will return false when the data stream is completely read,
  948. * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
  949. * and the stream is not at EOF, SDL_GetIOStatus() will return a different
  950. * error value and SDL_GetError() will offer a human-readable message.
  951. *
  952. * \param src the stream from which to read data.
  953. * \param value a pointer filled in with the data read.
  954. * \returns true on successful write or false on failure; call SDL_GetError()
  955. * for more information.
  956. *
  957. * \since This function is available since SDL 3.1.3.
  958. */
  959. extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64BE(SDL_IOStream *src, Sint64 *value);
  960. /* @} *//* Read endian functions */
  961. /**
  962. * \name Write endian functions
  963. *
  964. * Write an item of native format to the specified endianness.
  965. */
  966. /* @{ */
  967. /**
  968. * Use this function to write a byte to an SDL_IOStream.
  969. *
  970. * \param dst the SDL_IOStream to write to.
  971. * \param value the byte value to write.
  972. * \returns true on successful write or false on failure; call SDL_GetError()
  973. * for more information.
  974. *
  975. * \since This function is available since SDL 3.1.3.
  976. */
  977. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU8(SDL_IOStream *dst, Uint8 value);
  978. /**
  979. * Use this function to write a signed byte to an SDL_IOStream.
  980. *
  981. * \param dst the SDL_IOStream to write to.
  982. * \param value the byte value to write.
  983. * \returns true on successful write or false on failure; call SDL_GetError()
  984. * for more information.
  985. *
  986. * \since This function is available since SDL 3.1.3.
  987. */
  988. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS8(SDL_IOStream *dst, Sint8 value);
  989. /**
  990. * Use this function to write 16 bits in native format to an SDL_IOStream as
  991. * little-endian data.
  992. *
  993. * SDL byteswaps the data only if necessary, so the application always
  994. * specifies native format, and the data written will be in little-endian
  995. * format.
  996. *
  997. * \param dst the stream to which data will be written.
  998. * \param value the data to be written, in native format.
  999. * \returns true on successful write or false on failure; call SDL_GetError()
  1000. * for more information.
  1001. *
  1002. * \since This function is available since SDL 3.1.3.
  1003. */
  1004. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16LE(SDL_IOStream *dst, Uint16 value);
  1005. /**
  1006. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1007. * little-endian data.
  1008. *
  1009. * SDL byteswaps the data only if necessary, so the application always
  1010. * specifies native format, and the data written will be in little-endian
  1011. * format.
  1012. *
  1013. * \param dst the stream to which data will be written.
  1014. * \param value the data to be written, in native format.
  1015. * \returns true on successful write or false on failure; call SDL_GetError()
  1016. * for more information.
  1017. *
  1018. * \since This function is available since SDL 3.1.3.
  1019. */
  1020. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16LE(SDL_IOStream *dst, Sint16 value);
  1021. /**
  1022. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1023. * big-endian data.
  1024. *
  1025. * SDL byteswaps the data only if necessary, so the application always
  1026. * specifies native format, and the data written will be in big-endian format.
  1027. *
  1028. * \param dst the stream to which data will be written.
  1029. * \param value the data to be written, in native format.
  1030. * \returns true on successful write or false on failure; call SDL_GetError()
  1031. * for more information.
  1032. *
  1033. * \since This function is available since SDL 3.1.3.
  1034. */
  1035. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16BE(SDL_IOStream *dst, Uint16 value);
  1036. /**
  1037. * Use this function to write 16 bits in native format to an SDL_IOStream as
  1038. * big-endian data.
  1039. *
  1040. * SDL byteswaps the data only if necessary, so the application always
  1041. * specifies native format, and the data written will be in big-endian format.
  1042. *
  1043. * \param dst the stream to which data will be written.
  1044. * \param value the data to be written, in native format.
  1045. * \returns true on successful write or false on failure; call SDL_GetError()
  1046. * for more information.
  1047. *
  1048. * \since This function is available since SDL 3.1.3.
  1049. */
  1050. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16BE(SDL_IOStream *dst, Sint16 value);
  1051. /**
  1052. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1053. * little-endian data.
  1054. *
  1055. * SDL byteswaps the data only if necessary, so the application always
  1056. * specifies native format, and the data written will be in little-endian
  1057. * format.
  1058. *
  1059. * \param dst the stream to which data will be written.
  1060. * \param value the data to be written, in native format.
  1061. * \returns true on successful write or false on failure; call SDL_GetError()
  1062. * for more information.
  1063. *
  1064. * \since This function is available since SDL 3.1.3.
  1065. */
  1066. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32LE(SDL_IOStream *dst, Uint32 value);
  1067. /**
  1068. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1069. * little-endian data.
  1070. *
  1071. * SDL byteswaps the data only if necessary, so the application always
  1072. * specifies native format, and the data written will be in little-endian
  1073. * format.
  1074. *
  1075. * \param dst the stream to which data will be written.
  1076. * \param value the data to be written, in native format.
  1077. * \returns true on successful write or false on failure; call SDL_GetError()
  1078. * for more information.
  1079. *
  1080. * \since This function is available since SDL 3.1.3.
  1081. */
  1082. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32LE(SDL_IOStream *dst, Sint32 value);
  1083. /**
  1084. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1085. * big-endian data.
  1086. *
  1087. * SDL byteswaps the data only if necessary, so the application always
  1088. * specifies native format, and the data written will be in big-endian format.
  1089. *
  1090. * \param dst the stream to which data will be written.
  1091. * \param value the data to be written, in native format.
  1092. * \returns true on successful write or false on failure; call SDL_GetError()
  1093. * for more information.
  1094. *
  1095. * \since This function is available since SDL 3.1.3.
  1096. */
  1097. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32BE(SDL_IOStream *dst, Uint32 value);
  1098. /**
  1099. * Use this function to write 32 bits in native format to an SDL_IOStream as
  1100. * big-endian data.
  1101. *
  1102. * SDL byteswaps the data only if necessary, so the application always
  1103. * specifies native format, and the data written will be in big-endian format.
  1104. *
  1105. * \param dst the stream to which data will be written.
  1106. * \param value the data to be written, in native format.
  1107. * \returns true on successful write or false on failure; call SDL_GetError()
  1108. * for more information.
  1109. *
  1110. * \since This function is available since SDL 3.1.3.
  1111. */
  1112. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32BE(SDL_IOStream *dst, Sint32 value);
  1113. /**
  1114. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1115. * little-endian data.
  1116. *
  1117. * SDL byteswaps the data only if necessary, so the application always
  1118. * specifies native format, and the data written will be in little-endian
  1119. * format.
  1120. *
  1121. * \param dst the stream to which data will be written.
  1122. * \param value the data to be written, in native format.
  1123. * \returns true on successful write or false on failure; call SDL_GetError()
  1124. * for more information.
  1125. *
  1126. * \since This function is available since SDL 3.1.3.
  1127. */
  1128. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64LE(SDL_IOStream *dst, Uint64 value);
  1129. /**
  1130. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1131. * little-endian data.
  1132. *
  1133. * SDL byteswaps the data only if necessary, so the application always
  1134. * specifies native format, and the data written will be in little-endian
  1135. * format.
  1136. *
  1137. * \param dst the stream to which data will be written.
  1138. * \param value the data to be written, in native format.
  1139. * \returns true on successful write or false on failure; call SDL_GetError()
  1140. * for more information.
  1141. *
  1142. * \since This function is available since SDL 3.1.3.
  1143. */
  1144. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64LE(SDL_IOStream *dst, Sint64 value);
  1145. /**
  1146. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1147. * big-endian data.
  1148. *
  1149. * SDL byteswaps the data only if necessary, so the application always
  1150. * specifies native format, and the data written will be in big-endian format.
  1151. *
  1152. * \param dst the stream to which data will be written.
  1153. * \param value the data to be written, in native format.
  1154. * \returns true on successful write or false on failure; call SDL_GetError()
  1155. * for more information.
  1156. *
  1157. * \since This function is available since SDL 3.1.3.
  1158. */
  1159. extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64BE(SDL_IOStream *dst, Uint64 value);
  1160. /**
  1161. * Use this function to write 64 bits in native format to an SDL_IOStream as
  1162. * big-endian data.
  1163. *
  1164. * SDL byteswaps the data only if necessary, so the application always
  1165. * specifies native format, and the data written will be in big-endian 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. * \since This function is available since SDL 3.1.3.
  1173. */
  1174. extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64BE(SDL_IOStream *dst, Sint64 value);
  1175. /* @} *//* Write endian functions */
  1176. /* Ends C function definitions when using C++ */
  1177. #ifdef __cplusplus
  1178. }
  1179. #endif
  1180. #include <SDL3/SDL_close_code.h>
  1181. #endif /* SDL_iostream_h_ */