SDL_rwops.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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. /**
  19. * \file SDL_rwops.h
  20. *
  21. * This file provides a general interface for SDL to read and write
  22. * data streams. It can easily be extended to files, memory, etc.
  23. */
  24. #ifndef SDL_rwops_h_
  25. #define SDL_rwops_h_
  26. #include <SDL3/SDL_stdinc.h>
  27. #include <SDL3/SDL_error.h>
  28. #include <SDL3/SDL_begin_code.h>
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* RWops Types */
  34. #define SDL_RWOPS_UNKNOWN 0U /**< Unknown stream type */
  35. #define SDL_RWOPS_WINFILE 1U /**< Win32 file */
  36. #define SDL_RWOPS_STDFILE 2U /**< Stdio file */
  37. #define SDL_RWOPS_JNIFILE 3U /**< Android asset */
  38. #define SDL_RWOPS_MEMORY 4U /**< Memory stream */
  39. #define SDL_RWOPS_MEMORY_RO 5U /**< Read-Only memory stream */
  40. /**
  41. * This is the read/write operation structure -- very basic.
  42. */
  43. typedef struct SDL_RWops
  44. {
  45. /**
  46. * Return the size of the file in this rwops, or -1 if unknown
  47. */
  48. Sint64 (SDLCALL * size) (struct SDL_RWops * context);
  49. /**
  50. * Seek to \c offset relative to \c whence, one of stdio's whence values:
  51. * SDL_RW_SEEK_SET, SDL_RW_SEEK_CUR, SDL_RW_SEEK_END
  52. *
  53. * \return the final offset in the data stream, or -1 on error.
  54. */
  55. Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
  56. int whence);
  57. /**
  58. * Read up to \c size bytes from the data stream to the area pointed
  59. * at by \c ptr.
  60. *
  61. * It is an error to use a negative \c size, but this parameter is
  62. * signed so you definitely cannot overflow the return value on a
  63. * successful run with enormous amounts of data.
  64. *
  65. * \return the number of objects read, or 0 on end of file, or -1 on error.
  66. */
  67. Sint64 (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
  68. Sint64 size);
  69. /**
  70. * Write exactly \c size bytes from the area pointed at by \c ptr
  71. * to data stream. May write less than requested (error, non-blocking i/o,
  72. * etc). Returns -1 on error when nothing was written.
  73. *
  74. * It is an error to use a negative \c size, but this parameter is
  75. * signed so you definitely cannot overflow the return value on a
  76. * successful run with enormous amounts of data.
  77. *
  78. * \return the number of bytes written, which might be less than \c size,
  79. * and -1 on error.
  80. */
  81. Sint64 (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
  82. Sint64 size);
  83. /**
  84. * Close and free an allocated SDL_RWops structure.
  85. *
  86. * \return 0 if successful or -1 on write error when flushing data.
  87. */
  88. int (SDLCALL * close) (struct SDL_RWops * context);
  89. Uint32 type;
  90. union
  91. {
  92. #if defined(__ANDROID__)
  93. struct
  94. {
  95. void *asset;
  96. } androidio;
  97. #elif defined(__WIN32__) || defined(__GDK__)
  98. struct
  99. {
  100. SDL_bool append;
  101. void *h;
  102. struct
  103. {
  104. void *data;
  105. size_t size;
  106. size_t left;
  107. } buffer;
  108. } windowsio;
  109. #endif
  110. struct
  111. {
  112. SDL_bool autoclose;
  113. void *fp;
  114. } stdio;
  115. struct
  116. {
  117. Uint8 *base;
  118. Uint8 *here;
  119. Uint8 *stop;
  120. } mem;
  121. struct
  122. {
  123. void *data1;
  124. void *data2;
  125. } unknown;
  126. } hidden;
  127. } SDL_RWops;
  128. /**
  129. * \name RWFrom functions
  130. *
  131. * Functions to create SDL_RWops structures from various data streams.
  132. */
  133. /* @{ */
  134. /**
  135. * Use this function to create a new SDL_RWops structure for reading from
  136. * and/or writing to a named file.
  137. *
  138. * The `mode` string is treated roughly the same as in a call to the C
  139. * library's fopen(), even if SDL doesn't happen to use fopen() behind the
  140. * scenes.
  141. *
  142. * Available `mode` strings:
  143. *
  144. * - "r": Open a file for reading. The file must exist.
  145. * - "w": Create an empty file for writing. If a file with the same name
  146. * already exists its content is erased and the file is treated as a new
  147. * empty file.
  148. * - "a": Append to a file. Writing operations append data at the end of the
  149. * file. The file is created if it does not exist.
  150. * - "r+": Open a file for update both reading and writing. The file must
  151. * exist.
  152. * - "w+": Create an empty file for both reading and writing. If a file with
  153. * the same name already exists its content is erased and the file is
  154. * treated as a new empty file.
  155. * - "a+": Open a file for reading and appending. All writing operations are
  156. * performed at the end of the file, protecting the previous content to be
  157. * overwritten. You can reposition (fseek, rewind) the internal pointer to
  158. * anywhere in the file for reading, but writing operations will move it
  159. * back to the end of file. The file is created if it does not exist.
  160. *
  161. * **NOTE**: In order to open a file as a binary file, a "b" character has to
  162. * be included in the `mode` string. This additional "b" character can either
  163. * be appended at the end of the string (thus making the following compound
  164. * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the
  165. * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").
  166. * Additional characters may follow the sequence, although they should have no
  167. * effect. For example, "t" is sometimes appended to make explicit the file is
  168. * a text file.
  169. *
  170. * This function supports Unicode filenames, but they must be encoded in UTF-8
  171. * format, regardless of the underlying operating system.
  172. *
  173. * As a fallback, SDL_RWFromFile() will transparently open a matching filename
  174. * in an Android app's `assets`.
  175. *
  176. * Closing the SDL_RWops will close the file handle SDL is holding internally.
  177. *
  178. * \param file a UTF-8 string representing the filename to open
  179. * \param mode an ASCII string representing the mode to be used for opening
  180. * the file.
  181. * \returns a pointer to the SDL_RWops structure that is created, or NULL on
  182. * failure; call SDL_GetError() for more information.
  183. *
  184. * \since This function is available since SDL 3.0.0.
  185. *
  186. * \sa SDL_RWclose
  187. * \sa SDL_RWFromConstMem
  188. * \sa SDL_RWFromMem
  189. * \sa SDL_RWread
  190. * \sa SDL_RWseek
  191. * \sa SDL_RWtell
  192. * \sa SDL_RWwrite
  193. */
  194. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
  195. const char *mode);
  196. /**
  197. * Use this function to prepare a read-write memory buffer for use with
  198. * SDL_RWops.
  199. *
  200. * This function sets up an SDL_RWops struct based on a memory area of a
  201. * certain size, for both read and write access.
  202. *
  203. * This memory buffer is not copied by the RWops; the pointer you provide must
  204. * remain valid until you close the stream. Closing the stream will not free
  205. * the original buffer.
  206. *
  207. * If you need to make sure the RWops never writes to the memory buffer, you
  208. * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
  209. *
  210. * \param mem a pointer to a buffer to feed an SDL_RWops stream
  211. * \param size the buffer size, in bytes
  212. * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
  213. * SDL_GetError() for more information.
  214. *
  215. * \since This function is available since SDL 3.0.0.
  216. *
  217. * \sa SDL_RWclose
  218. * \sa SDL_RWFromConstMem
  219. * \sa SDL_RWFromFile
  220. * \sa SDL_RWFromMem
  221. * \sa SDL_RWread
  222. * \sa SDL_RWseek
  223. * \sa SDL_RWtell
  224. * \sa SDL_RWwrite
  225. */
  226. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
  227. /**
  228. * Use this function to prepare a read-only memory buffer for use with RWops.
  229. *
  230. * This function sets up an SDL_RWops struct based on a memory area of a
  231. * certain size. It assumes the memory area is not writable.
  232. *
  233. * Attempting to write to this RWops stream will report an error without
  234. * writing to the memory buffer.
  235. *
  236. * This memory buffer is not copied by the RWops; the pointer you provide must
  237. * remain valid until you close the stream. Closing the stream will not free
  238. * the original buffer.
  239. *
  240. * If you need to write to a memory buffer, you should use SDL_RWFromMem()
  241. * with a writable buffer of memory instead.
  242. *
  243. * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
  244. * \param size the buffer size, in bytes
  245. * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
  246. * SDL_GetError() for more information.
  247. *
  248. * \since This function is available since SDL 3.0.0.
  249. *
  250. * \sa SDL_RWclose
  251. * \sa SDL_RWFromConstMem
  252. * \sa SDL_RWFromFile
  253. * \sa SDL_RWFromMem
  254. * \sa SDL_RWread
  255. * \sa SDL_RWseek
  256. * \sa SDL_RWtell
  257. */
  258. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
  259. int size);
  260. /* @} *//* RWFrom functions */
  261. /**
  262. * Use this function to allocate an empty, unpopulated SDL_RWops structure.
  263. *
  264. * Applications do not need to use this function unless they are providing
  265. * their own SDL_RWops implementation. If you just need a SDL_RWops to
  266. * read/write a common data source, you should use the built-in
  267. * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
  268. *
  269. * You must free the returned pointer with SDL_DestroyRW(). Depending on your
  270. * operating system and compiler, there may be a difference between the
  271. * malloc() and free() your program uses and the versions SDL calls
  272. * internally. Trying to mix the two can cause crashing such as segmentation
  273. * faults. Since all SDL_RWops must free themselves when their **close**
  274. * method is called, all SDL_RWops must be allocated through this function, so
  275. * they can all be freed correctly with SDL_DestroyRW().
  276. *
  277. * \returns a pointer to the allocated memory on success, or NULL on failure;
  278. * call SDL_GetError() for more information.
  279. *
  280. * \since This function is available since SDL 3.0.0.
  281. *
  282. * \sa SDL_DestroyRW
  283. */
  284. extern DECLSPEC SDL_RWops *SDLCALL SDL_CreateRW(void);
  285. /**
  286. * Use this function to free an SDL_RWops structure allocated by
  287. * SDL_CreateRW().
  288. *
  289. * Applications do not need to use this function unless they are providing
  290. * their own SDL_RWops implementation. If you just need a SDL_RWops to
  291. * read/write a common data source, you should use the built-in
  292. * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
  293. * call the **close** method on those SDL_RWops pointers when you are done
  294. * with them.
  295. *
  296. * Only use SDL_DestroyRW() on pointers returned by SDL_CreateRW(). The pointer is
  297. * invalid as soon as this function returns. Any extra memory allocated during
  298. * creation of the SDL_RWops is not freed by SDL_DestroyRW(); the programmer must
  299. * be responsible for managing that memory in their **close** method.
  300. *
  301. * \param area the SDL_RWops structure to be freed
  302. *
  303. * \since This function is available since SDL 3.0.0.
  304. *
  305. * \sa SDL_CreateRW
  306. */
  307. extern DECLSPEC void SDLCALL SDL_DestroyRW(SDL_RWops * area);
  308. #define SDL_RW_SEEK_SET 0 /**< Seek from the beginning of data */
  309. #define SDL_RW_SEEK_CUR 1 /**< Seek relative to current read point */
  310. #define SDL_RW_SEEK_END 2 /**< Seek relative to the end of data */
  311. /**
  312. * Use this function to get the size of the data stream in an SDL_RWops.
  313. *
  314. * Prior to SDL 2.0.10, this function was a macro.
  315. *
  316. * \param context the SDL_RWops to get the size of the data stream from
  317. * \returns the size of the data stream in the SDL_RWops on success, -1 if
  318. * unknown or a negative error code on failure; call SDL_GetError()
  319. * for more information.
  320. *
  321. * \since This function is available since SDL 3.0.0.
  322. */
  323. extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
  324. /**
  325. * Seek within an SDL_RWops data stream.
  326. *
  327. * This function seeks to byte `offset`, relative to `whence`.
  328. *
  329. * `whence` may be any of the following values:
  330. *
  331. * - `SDL_RW_SEEK_SET`: seek from the beginning of data
  332. * - `SDL_RW_SEEK_CUR`: seek relative to current read point
  333. * - `SDL_RW_SEEK_END`: seek relative to the end of data
  334. *
  335. * If this stream can not seek, it will return -1.
  336. *
  337. * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
  338. * `seek` method appropriately, to simplify application development.
  339. *
  340. * Prior to SDL 2.0.10, this function was a macro.
  341. *
  342. * \param context a pointer to an SDL_RWops structure
  343. * \param offset an offset in bytes, relative to **whence** location; can be
  344. * negative
  345. * \param whence any of `SDL_RW_SEEK_SET`, `SDL_RW_SEEK_CUR`, `SDL_RW_SEEK_END`
  346. * \returns the final offset in the data stream after the seek or -1 on error.
  347. *
  348. * \since This function is available since SDL 3.0.0.
  349. *
  350. * \sa SDL_RWclose
  351. * \sa SDL_RWFromConstMem
  352. * \sa SDL_RWFromFile
  353. * \sa SDL_RWFromMem
  354. * \sa SDL_RWread
  355. * \sa SDL_RWtell
  356. * \sa SDL_RWwrite
  357. */
  358. extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context,
  359. Sint64 offset, int whence);
  360. /**
  361. * Determine the current read/write offset in an SDL_RWops data stream.
  362. *
  363. * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
  364. * method, with an offset of 0 bytes from `SDL_RW_SEEK_CUR`, to simplify
  365. * application development.
  366. *
  367. * Prior to SDL 2.0.10, this function was a macro.
  368. *
  369. * \param context a SDL_RWops data stream object from which to get the current
  370. * offset
  371. * \returns the current offset in the stream, or -1 if the information can not
  372. * be determined.
  373. *
  374. * \since This function is available since SDL 3.0.0.
  375. *
  376. * \sa SDL_RWclose
  377. * \sa SDL_RWFromConstMem
  378. * \sa SDL_RWFromFile
  379. * \sa SDL_RWFromMem
  380. * \sa SDL_RWread
  381. * \sa SDL_RWseek
  382. * \sa SDL_RWwrite
  383. */
  384. extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
  385. /**
  386. * Read from a data source.
  387. *
  388. * This function reads up `size` bytes from the data source to the area
  389. * pointed at by `ptr`. This function may read less bytes than requested.
  390. * It will return zero when the data stream is completely read, or
  391. * -1 on error. For streams that support non-blocking
  392. * operation, if nothing was read because it would require blocking,
  393. * this function returns -2 to distinguish that this is not an error or
  394. * end-of-file, and the caller can try again later.
  395. *
  396. * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
  397. * `read` method appropriately, to simplify application development.
  398. *
  399. * It is an error to specify a negative `size`, but this parameter is
  400. * signed so you definitely cannot overflow the return value on a
  401. * successful run with enormous amounts of data.
  402. *
  403. * \param context a pointer to an SDL_RWops structure
  404. * \param ptr a pointer to a buffer to read data into
  405. * \param size the number of bytes to read from the data source.
  406. * \returns the number of bytes read, 0 at end of file, -1 on error, and -2 for data not ready with a non-blocking context.
  407. *
  408. * \since This function is available since SDL 3.0.0.
  409. *
  410. * \sa SDL_RWclose
  411. * \sa SDL_RWFromConstMem
  412. * \sa SDL_RWFromFile
  413. * \sa SDL_RWFromMem
  414. * \sa SDL_RWseek
  415. * \sa SDL_RWwrite
  416. */
  417. extern DECLSPEC Sint64 SDLCALL SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size);
  418. /**
  419. * Write to an SDL_RWops data stream.
  420. *
  421. * This function writes exactly `size` bytes from the area pointed at by
  422. * `ptr` to the stream. If this fails for any reason, it'll return less
  423. * than `size` to demonstrate how far the write progressed. On success,
  424. * it returns `num`.
  425. *
  426. * On error, this function still attempts to write as much as possible,
  427. * so it might return a positive value less than the requested write
  428. * size. If the function failed to write anything and there was an
  429. * actual error, it will return -1. For streams that support non-blocking
  430. * operation, if nothing was written because it would require blocking,
  431. * this function returns -2 to distinguish that this is not an error and
  432. * the caller can try again later.
  433. *
  434. * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
  435. * `write` method appropriately, to simplify application development.
  436. *
  437. * It is an error to specify a negative `size`, but this parameter is
  438. * signed so you definitely cannot overflow the return value on a
  439. * successful run with enormous amounts of data.
  440. *
  441. * \param context a pointer to an SDL_RWops structure
  442. * \param ptr a pointer to a buffer containing data to write
  443. * \param size the number of bytes to write
  444. * \returns the number of bytes written, which will be less than `num` on
  445. * error; call SDL_GetError() for more information.
  446. *
  447. * \since This function is available since SDL 3.0.0.
  448. *
  449. * \sa SDL_RWclose
  450. * \sa SDL_RWFromConstMem
  451. * \sa SDL_RWFromFile
  452. * \sa SDL_RWFromMem
  453. * \sa SDL_RWread
  454. * \sa SDL_RWseek
  455. */
  456. extern DECLSPEC Sint64 SDLCALL SDL_RWwrite(SDL_RWops *context,
  457. const void *ptr, Sint64 size);
  458. /**
  459. * Close and free an allocated SDL_RWops structure.
  460. *
  461. * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
  462. * resources used by the stream and frees the SDL_RWops itself with
  463. * SDL_DestroyRW(). This returns 0 on success, or -1 if the stream failed to
  464. * flush to its output (e.g. to disk).
  465. *
  466. * Note that if this fails to flush the stream to disk, this function reports
  467. * an error, but the SDL_RWops is still invalid once this function returns.
  468. *
  469. * Prior to SDL 2.0.10, this function was a macro.
  470. *
  471. * \param context SDL_RWops structure to close
  472. * \returns 0 on success or a negative error code on failure; call
  473. * SDL_GetError() for more information.
  474. *
  475. * \since This function is available since SDL 3.0.0.
  476. *
  477. * \sa SDL_RWFromConstMem
  478. * \sa SDL_RWFromFile
  479. * \sa SDL_RWFromMem
  480. * \sa SDL_RWread
  481. * \sa SDL_RWseek
  482. * \sa SDL_RWwrite
  483. */
  484. extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
  485. /**
  486. * Load all the data from an SDL data stream.
  487. *
  488. * The data is allocated with a zero byte at the end (null terminated) for
  489. * convenience. This extra byte is not included in the value reported via
  490. * `datasize`.
  491. *
  492. * The data should be freed with SDL_free().
  493. *
  494. * \param src the SDL_RWops to read all available data from
  495. * \param datasize if not NULL, will store the number of bytes read
  496. * \param freesrc if non-zero, calls SDL_RWclose() on `src` before returning
  497. * \returns the data, or NULL if there was an error.
  498. *
  499. * \since This function is available since SDL 3.0.0.
  500. */
  501. extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
  502. size_t *datasize,
  503. int freesrc);
  504. /**
  505. * Load all the data from a file path.
  506. *
  507. * The data is allocated with a zero byte at the end (null terminated) for
  508. * convenience. This extra byte is not included in the value reported via
  509. * `datasize`.
  510. *
  511. * The data should be freed with SDL_free().
  512. *
  513. * Prior to SDL 2.0.10, this function was a macro wrapping around
  514. * SDL_LoadFile_RW.
  515. *
  516. * \param file the path to read all available data from
  517. * \param datasize if not NULL, will store the number of bytes read
  518. * \returns the data, or NULL if there was an error.
  519. *
  520. * \since This function is available since SDL 3.0.0.
  521. */
  522. extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
  523. /**
  524. * \name Read endian functions
  525. *
  526. * Read an item of the specified endianness and return in native format.
  527. */
  528. /* @{ */
  529. /**
  530. * Use this function to read a byte from an SDL_RWops.
  531. *
  532. * \param src the SDL_RWops to read from
  533. * \returns the read byte on success or 0 on failure; call SDL_GetError() for
  534. * more information.
  535. *
  536. * \since This function is available since SDL 3.0.0.
  537. *
  538. * \sa SDL_WriteU8
  539. */
  540. extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
  541. /**
  542. * Use this function to read 16 bits of little-endian data from an SDL_RWops
  543. * and return in native format.
  544. *
  545. * SDL byteswaps the data only if necessary, so the data returned will be in
  546. * the native byte order.
  547. *
  548. * \param src the stream from which to read data
  549. * \returns 16 bits of data in the native byte order of the platform.
  550. *
  551. * \since This function is available since SDL 3.0.0.
  552. *
  553. * \sa SDL_ReadBE16
  554. */
  555. extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
  556. /**
  557. * Use this function to read 16 bits of big-endian data from an SDL_RWops and
  558. * return in native format.
  559. *
  560. * SDL byteswaps the data only if necessary, so the data returned will be in
  561. * the native byte order.
  562. *
  563. * \param src the stream from which to read data
  564. * \returns 16 bits of data in the native byte order of the platform.
  565. *
  566. * \since This function is available since SDL 3.0.0.
  567. *
  568. * \sa SDL_ReadLE16
  569. */
  570. extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
  571. /**
  572. * Use this function to read 32 bits of little-endian data from an SDL_RWops
  573. * and return in native format.
  574. *
  575. * SDL byteswaps the data only if necessary, so the data returned will be in
  576. * the native byte order.
  577. *
  578. * \param src the stream from which to read data
  579. * \returns 32 bits of data in the native byte order of the platform.
  580. *
  581. * \since This function is available since SDL 3.0.0.
  582. *
  583. * \sa SDL_ReadBE32
  584. */
  585. extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
  586. /**
  587. * Use this function to read 32 bits of big-endian data from an SDL_RWops and
  588. * return in native format.
  589. *
  590. * SDL byteswaps the data only if necessary, so the data returned will be in
  591. * the native byte order.
  592. *
  593. * \param src the stream from which to read data
  594. * \returns 32 bits of data in the native byte order of the platform.
  595. *
  596. * \since This function is available since SDL 3.0.0.
  597. *
  598. * \sa SDL_ReadLE32
  599. */
  600. extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
  601. /**
  602. * Use this function to read 64 bits of little-endian data from an SDL_RWops
  603. * and return in native format.
  604. *
  605. * SDL byteswaps the data only if necessary, so the data returned will be in
  606. * the native byte order.
  607. *
  608. * \param src the stream from which to read data
  609. * \returns 64 bits of data in the native byte order of the platform.
  610. *
  611. * \since This function is available since SDL 3.0.0.
  612. *
  613. * \sa SDL_ReadBE64
  614. */
  615. extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
  616. /**
  617. * Use this function to read 64 bits of big-endian data from an SDL_RWops and
  618. * return in native format.
  619. *
  620. * SDL byteswaps the data only if necessary, so the data returned will be in
  621. * the native byte order.
  622. *
  623. * \param src the stream from which to read data
  624. * \returns 64 bits of data in the native byte order of the platform.
  625. *
  626. * \since This function is available since SDL 3.0.0.
  627. *
  628. * \sa SDL_ReadLE64
  629. */
  630. extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
  631. /* @} *//* Read endian functions */
  632. /**
  633. * \name Write endian functions
  634. *
  635. * Write an item of native format to the specified endianness.
  636. */
  637. /* @{ */
  638. /**
  639. * Use this function to write a byte to an SDL_RWops.
  640. *
  641. * \param dst the SDL_RWops to write to
  642. * \param value the byte value to write
  643. * \returns 1 on success or 0 on failure; call SDL_GetError() for more
  644. * information.
  645. *
  646. * \since This function is available since SDL 3.0.0.
  647. *
  648. * \sa SDL_ReadU8
  649. */
  650. extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
  651. /**
  652. * Use this function to write 16 bits in native format to a SDL_RWops as
  653. * little-endian data.
  654. *
  655. * SDL byteswaps the data only if necessary, so the application always
  656. * specifies native format, and the data written will be in little-endian
  657. * format.
  658. *
  659. * \param dst the stream to which data will be written
  660. * \param value the data to be written, in native format
  661. * \returns 1 on successful write, 0 on error.
  662. *
  663. * \since This function is available since SDL 3.0.0.
  664. *
  665. * \sa SDL_WriteBE16
  666. */
  667. extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
  668. /**
  669. * Use this function to write 16 bits in native format to a SDL_RWops as
  670. * big-endian data.
  671. *
  672. * SDL byteswaps the data only if necessary, so the application always
  673. * specifies native format, and the data written will be in big-endian format.
  674. *
  675. * \param dst the stream to which data will be written
  676. * \param value the data to be written, in native format
  677. * \returns 1 on successful write, 0 on error.
  678. *
  679. * \since This function is available since SDL 3.0.0.
  680. *
  681. * \sa SDL_WriteLE16
  682. */
  683. extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
  684. /**
  685. * Use this function to write 32 bits in native format to a SDL_RWops as
  686. * little-endian data.
  687. *
  688. * SDL byteswaps the data only if necessary, so the application always
  689. * specifies native format, and the data written will be in little-endian
  690. * format.
  691. *
  692. * \param dst the stream to which data will be written
  693. * \param value the data to be written, in native format
  694. * \returns 1 on successful write, 0 on error.
  695. *
  696. * \since This function is available since SDL 3.0.0.
  697. *
  698. * \sa SDL_WriteBE32
  699. */
  700. extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
  701. /**
  702. * Use this function to write 32 bits in native format to a SDL_RWops as
  703. * big-endian data.
  704. *
  705. * SDL byteswaps the data only if necessary, so the application always
  706. * specifies native format, and the data written will be in big-endian format.
  707. *
  708. * \param dst the stream to which data will be written
  709. * \param value the data to be written, in native format
  710. * \returns 1 on successful write, 0 on error.
  711. *
  712. * \since This function is available since SDL 3.0.0.
  713. *
  714. * \sa SDL_WriteLE32
  715. */
  716. extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
  717. /**
  718. * Use this function to write 64 bits in native format to a SDL_RWops as
  719. * little-endian data.
  720. *
  721. * SDL byteswaps the data only if necessary, so the application always
  722. * specifies native format, and the data written will be in little-endian
  723. * format.
  724. *
  725. * \param dst the stream to which data will be written
  726. * \param value the data to be written, in native format
  727. * \returns 1 on successful write, 0 on error.
  728. *
  729. * \since This function is available since SDL 3.0.0.
  730. *
  731. * \sa SDL_WriteBE64
  732. */
  733. extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
  734. /**
  735. * Use this function to write 64 bits in native format to a SDL_RWops as
  736. * big-endian data.
  737. *
  738. * SDL byteswaps the data only if necessary, so the application always
  739. * specifies native format, and the data written will be in big-endian format.
  740. *
  741. * \param dst the stream to which data will be written
  742. * \param value the data to be written, in native format
  743. * \returns 1 on successful write, 0 on error.
  744. *
  745. * \since This function is available since SDL 3.0.0.
  746. *
  747. * \sa SDL_WriteLE64
  748. */
  749. extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
  750. /* @} *//* Write endian functions */
  751. /* Ends C function definitions when using C++ */
  752. #ifdef __cplusplus
  753. }
  754. #endif
  755. #include <SDL3/SDL_close_code.h>
  756. #endif /* SDL_rwops_h_ */