SDL_iostream.h 50 KB

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