SDL_iostream.h 42 KB

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