SDL_iostream.h 52 KB

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