SDL_rwops.h 35 KB

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