SDL_rwops.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  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__)
  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 negative error code on failure; call SDL_GetError() for more information.
  312. *
  313. * \since This function is available since SDL 3.0.0.
  314. */
  315. extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
  316. /**
  317. * Seek within an SDL_RWops data stream.
  318. *
  319. * This function seeks to byte `offset`, relative to `whence`.
  320. *
  321. * `whence` may be any of the following values:
  322. *
  323. * - `SDL_RW_SEEK_SET`: seek from the beginning of data
  324. * - `SDL_RW_SEEK_CUR`: seek relative to current read point
  325. * - `SDL_RW_SEEK_END`: seek relative to the end of data
  326. *
  327. * If this stream can not seek, it will return -1.
  328. *
  329. * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
  330. * `seek` method appropriately, to simplify application development.
  331. *
  332. * \param context a pointer to an SDL_RWops structure
  333. * \param offset an offset in bytes, relative to **whence** location; can be
  334. * negative
  335. * \param whence any of `SDL_RW_SEEK_SET`, `SDL_RW_SEEK_CUR`,
  336. * `SDL_RW_SEEK_END`
  337. * \returns the final offset in the data stream after the seek or a negative error code on failure; call SDL_GetError() for more information.
  338. *
  339. * \since This function is available since SDL 3.0.0.
  340. *
  341. * \sa SDL_RWclose
  342. * \sa SDL_RWFromConstMem
  343. * \sa SDL_RWFromFile
  344. * \sa SDL_RWFromMem
  345. * \sa SDL_RWread
  346. * \sa SDL_RWtell
  347. * \sa SDL_RWwrite
  348. */
  349. extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context, Sint64 offset, int whence);
  350. /**
  351. * Determine the current read/write offset in an SDL_RWops data stream.
  352. *
  353. * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
  354. * method, with an offset of 0 bytes from `SDL_RW_SEEK_CUR`, to simplify
  355. * application development.
  356. *
  357. * \param context an SDL_RWops data stream object from which to get the current
  358. * offset
  359. * \returns the current offset in the stream, or -1 if the information can not
  360. * be determined.
  361. *
  362. * \since This function is available since SDL 3.0.0.
  363. *
  364. * \sa SDL_RWclose
  365. * \sa SDL_RWFromConstMem
  366. * \sa SDL_RWFromFile
  367. * \sa SDL_RWFromMem
  368. * \sa SDL_RWread
  369. * \sa SDL_RWseek
  370. * \sa SDL_RWwrite
  371. */
  372. extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
  373. /**
  374. * Read from a data source.
  375. *
  376. * This function reads up `size` bytes from the data source to the area
  377. * pointed at by `ptr`. This function may read less bytes than requested. It
  378. * will return zero when the data stream is completely read, or -1 on error.
  379. * For streams that support non-blocking operation, if nothing was read
  380. * because it would require blocking, this function returns -2 to distinguish
  381. * that this is not an error or end-of-file, and the caller can try again
  382. * later.
  383. *
  384. * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
  385. * `read` method appropriately, to simplify application development.
  386. *
  387. * It is an error to specify a negative `size`, but this parameter is signed
  388. * so you definitely cannot overflow the return value on a successful run with
  389. * enormous amounts of data.
  390. *
  391. * \param context a pointer to an SDL_RWops structure
  392. * \param ptr a pointer to a buffer to read data into
  393. * \param size the number of bytes to read from the data source.
  394. * \returns the number of bytes read, or 0 on end of file or other error.
  395. *
  396. * \since This function is available since SDL 3.0.0.
  397. *
  398. * \sa SDL_RWclose
  399. * \sa SDL_RWFromConstMem
  400. * \sa SDL_RWFromFile
  401. * \sa SDL_RWFromMem
  402. * \sa SDL_RWseek
  403. * \sa SDL_RWwrite
  404. */
  405. extern DECLSPEC size_t SDLCALL SDL_RWread(SDL_RWops *context, void *ptr, size_t size);
  406. /**
  407. * Write to an SDL_RWops data stream.
  408. *
  409. * This function writes exactly `size` bytes from the area pointed at by `ptr`
  410. * to the stream. If this fails for any reason, it'll return less than `size`
  411. * to demonstrate how far the write progressed. On success, it returns `num`.
  412. *
  413. * On error, this function still attempts to write as much as possible, so it
  414. * might return a positive value less than the requested write size. If the
  415. * function failed to write anything and there was an actual error, it will
  416. * return -1. For streams that support non-blocking operation, if nothing was
  417. * written because it would require blocking, this function returns -2 to
  418. * distinguish that this is not an error and the caller can try again later.
  419. *
  420. * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
  421. * `write` method appropriately, to simplify application development.
  422. *
  423. * It is an error to specify a negative `size`, but this parameter is signed
  424. * so you definitely cannot overflow the return value on a successful run with
  425. * enormous amounts of data.
  426. *
  427. * \param context a pointer to an SDL_RWops structure
  428. * \param ptr a pointer to a buffer containing data to write
  429. * \param size the number of bytes to write
  430. * \returns the number of bytes written, which will be less than `num` on
  431. * error; call SDL_GetError() for more information.
  432. *
  433. * \since This function is available since SDL 3.0.0.
  434. *
  435. * \sa SDL_RWclose
  436. * \sa SDL_RWFromConstMem
  437. * \sa SDL_RWFromFile
  438. * \sa SDL_RWFromMem
  439. * \sa SDL_RWread
  440. * \sa SDL_RWseek
  441. */
  442. extern DECLSPEC size_t SDLCALL SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size);
  443. /**
  444. * Close and free an allocated SDL_RWops structure.
  445. *
  446. * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
  447. * resources used by the stream and frees the SDL_RWops itself with
  448. * SDL_DestroyRW(). This returns 0 on success, or -1 if the stream failed to
  449. * flush to its output (e.g. to disk).
  450. *
  451. * Note that if this fails to flush the stream to disk, this function reports
  452. * an error, but the SDL_RWops is still invalid once this function returns.
  453. *
  454. * \param context SDL_RWops structure to close
  455. * \returns 0 on success or a negative error code on failure; call
  456. * SDL_GetError() for more information.
  457. *
  458. * \since This function is available since SDL 3.0.0.
  459. *
  460. * \sa SDL_RWFromConstMem
  461. * \sa SDL_RWFromFile
  462. * \sa SDL_RWFromMem
  463. * \sa SDL_RWread
  464. * \sa SDL_RWseek
  465. * \sa SDL_RWwrite
  466. */
  467. extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
  468. /**
  469. * Load all the data from an SDL data stream.
  470. *
  471. * The data is allocated with a zero byte at the end (null terminated) for
  472. * convenience. This extra byte is not included in the value reported via
  473. * `datasize`.
  474. *
  475. * The data should be freed with SDL_free().
  476. *
  477. * \param src the SDL_RWops to read all available data from
  478. * \param datasize if not NULL, will store the number of bytes read
  479. * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
  480. * even in the case of an error
  481. * \returns the data, or NULL if there was an error.
  482. *
  483. * \since This function is available since SDL 3.0.0.
  484. */
  485. extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc);
  486. /**
  487. * Load all the data from a file path.
  488. *
  489. * The data is allocated with a zero byte at the end (null terminated) for
  490. * convenience. This extra byte is not included in the value reported via
  491. * `datasize`.
  492. *
  493. * The data should be freed with SDL_free().
  494. *
  495. * \param file the path to read all available data from
  496. * \param datasize if not NULL, will store the number of bytes read
  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(const char *file, size_t *datasize);
  502. /**
  503. * \name Read endian functions
  504. *
  505. * Read an item of the specified endianness and return in native format.
  506. */
  507. /* @{ */
  508. /**
  509. * Use this function to read a byte from an SDL_RWops.
  510. *
  511. * \param src the SDL_RWops to read from
  512. * \param value a pointer filled in with the data read
  513. * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for
  514. * more information.
  515. *
  516. * \since This function is available since SDL 3.0.0.
  517. */
  518. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU8(SDL_RWops *src, Uint8 *value);
  519. /**
  520. * Use this function to read 16 bits of little-endian data from an SDL_RWops
  521. * and return in native format.
  522. *
  523. * SDL byteswaps the data only if necessary, so the data returned will be in
  524. * the native byte order.
  525. *
  526. * \param src the stream from which to read data
  527. * \param value a pointer filled in with the data read
  528. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  529. *
  530. * \since This function is available since SDL 3.0.0.
  531. */
  532. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU16LE(SDL_RWops *src, Uint16 *value);
  533. /**
  534. * Use this function to read 16 bits of little-endian data from an SDL_RWops
  535. * and return in native format.
  536. *
  537. * SDL byteswaps the data only if necessary, so the data returned will be in
  538. * the native byte order.
  539. *
  540. * \param src the stream from which to read data
  541. * \param value a pointer filled in with the data read
  542. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  543. *
  544. * \since This function is available since SDL 3.0.0.
  545. *
  546. */
  547. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS16LE(SDL_RWops *src, Sint16 *value);
  548. /**
  549. * Use this function to read 16 bits of big-endian data from an SDL_RWops and
  550. * return in native format.
  551. *
  552. * SDL byteswaps the data only if necessary, so the data returned will be in
  553. * the native byte order.
  554. *
  555. * \param src the stream from which to read data
  556. * \param value a pointer filled in with the data read
  557. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  558. *
  559. * \since This function is available since SDL 3.0.0.
  560. *
  561. */
  562. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU16BE(SDL_RWops *src, Uint16 *value);
  563. /**
  564. * Use this function to read 16 bits of big-endian data from an SDL_RWops and
  565. * return in native format.
  566. *
  567. * SDL byteswaps the data only if necessary, so the data returned will be in
  568. * the native byte order.
  569. *
  570. * \param src the stream from which to read data
  571. * \param value a pointer filled in with the data read
  572. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  573. *
  574. * \since This function is available since SDL 3.0.0.
  575. */
  576. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS16BE(SDL_RWops *src, Sint16 *value);
  577. /**
  578. * Use this function to read 32 bits of little-endian data from an SDL_RWops
  579. * and return in native format.
  580. *
  581. * SDL byteswaps the data only if necessary, so the data returned will be in
  582. * the native byte order.
  583. *
  584. * \param src the stream from which to read data
  585. * \param value a pointer filled in with the data read
  586. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  587. *
  588. * \since This function is available since SDL 3.0.0.
  589. */
  590. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU32LE(SDL_RWops *src, Uint32 *value);
  591. /**
  592. * Use this function to read 32 bits of little-endian data from an SDL_RWops
  593. * and return in native format.
  594. *
  595. * SDL byteswaps the data only if necessary, so the data returned will be in
  596. * the native byte order.
  597. *
  598. * \param src the stream from which to read data
  599. * \param value a pointer filled in with the data read
  600. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  601. *
  602. * \since This function is available since SDL 3.0.0.
  603. */
  604. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS32LE(SDL_RWops *src, Sint32 *value);
  605. /**
  606. * Use this function to read 32 bits of big-endian data from an SDL_RWops and
  607. * return in native format.
  608. *
  609. * SDL byteswaps the data only if necessary, so the data returned will be in
  610. * the native byte order.
  611. *
  612. * \param src the stream from which to read data
  613. * \param value a pointer filled in with the data read
  614. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  615. *
  616. * \since This function is available since SDL 3.0.0.
  617. */
  618. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU32BE(SDL_RWops *src, Uint32 *value);
  619. /**
  620. * Use this function to read 32 bits of big-endian data from an SDL_RWops and
  621. * return in native format.
  622. *
  623. * SDL byteswaps the data only if necessary, so the data returned will be in
  624. * the native byte order.
  625. *
  626. * \param src the stream from which to read data
  627. * \param value a pointer filled in with the data read
  628. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  629. *
  630. * \since This function is available since SDL 3.0.0.
  631. */
  632. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS32BE(SDL_RWops *src, Sint32 *value);
  633. /**
  634. * Use this function to read 64 bits of little-endian data from an SDL_RWops
  635. * and return in native format.
  636. *
  637. * SDL byteswaps the data only if necessary, so the data returned will be in
  638. * the native byte order.
  639. *
  640. * \param src the stream from which to read data
  641. * \param value a pointer filled in with the data read
  642. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  643. *
  644. * \since This function is available since SDL 3.0.0.
  645. */
  646. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU64LE(SDL_RWops *src, Uint64 *value);
  647. /**
  648. * Use this function to read 64 bits of little-endian data from an SDL_RWops
  649. * and return in native format.
  650. *
  651. * SDL byteswaps the data only if necessary, so the data returned will be in
  652. * the native byte order.
  653. *
  654. * \param src the stream from which to read data
  655. * \param value a pointer filled in with the data read
  656. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  657. *
  658. * \since This function is available since SDL 3.0.0.
  659. */
  660. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS64LE(SDL_RWops *src, Sint64 *value);
  661. /**
  662. * Use this function to read 64 bits of big-endian data from an SDL_RWops and
  663. * return in native format.
  664. *
  665. * SDL byteswaps the data only if necessary, so the data returned will be in
  666. * the native byte order.
  667. *
  668. * \param src the stream from which to read data
  669. * \param value a pointer filled in with the data read
  670. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  671. *
  672. * \since This function is available since SDL 3.0.0.
  673. */
  674. extern DECLSPEC SDL_bool SDLCALL SDL_ReadU64BE(SDL_RWops *src, Uint64 *value);
  675. /**
  676. * Use this function to read 64 bits of big-endian data from an SDL_RWops and
  677. * return in native format.
  678. *
  679. * SDL byteswaps the data only if necessary, so the data returned will be in
  680. * the native byte order.
  681. *
  682. * \param src the stream from which to read data
  683. * \param value a pointer filled in with the data read
  684. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  685. *
  686. * \since This function is available since SDL 3.0.0.
  687. */
  688. extern DECLSPEC SDL_bool SDLCALL SDL_ReadS64BE(SDL_RWops *src, Sint64 *value);
  689. /* @} *//* Read endian functions */
  690. /**
  691. * \name Write endian functions
  692. *
  693. * Write an item of native format to the specified endianness.
  694. */
  695. /* @{ */
  696. /**
  697. * Use this function to write a byte to an SDL_RWops.
  698. *
  699. * \param dst the SDL_RWops to write to
  700. * \param value the byte value to write
  701. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  702. *
  703. * \since This function is available since SDL 3.0.0.
  704. */
  705. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU8(SDL_RWops *dst, Uint8 value);
  706. /**
  707. * Use this function to write 16 bits in native format to an SDL_RWops as
  708. * little-endian data.
  709. *
  710. * SDL byteswaps the data only if necessary, so the application always
  711. * specifies native format, and the data written will be in little-endian
  712. * format.
  713. *
  714. * \param dst the stream to which data will be written
  715. * \param value the data to be written, in native format
  716. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  717. *
  718. * \since This function is available since SDL 3.0.0.
  719. */
  720. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU16LE(SDL_RWops *dst, Uint16 value);
  721. /**
  722. * Use this function to write 16 bits in native format to an SDL_RWops as
  723. * little-endian data.
  724. *
  725. * SDL byteswaps the data only if necessary, so the application always
  726. * specifies native format, and the data written will be in little-endian
  727. * format.
  728. *
  729. * \param dst the stream to which data will be written
  730. * \param value the data to be written, in native format
  731. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call 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_WriteS16LE(SDL_RWops *dst, Sint16 value);
  736. /**
  737. * Use this function to write 16 bits in native format to an SDL_RWops as
  738. * big-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 big-endian format.
  742. *
  743. * \param dst the stream to which data will be written
  744. * \param value the data to be written, in native format
  745. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  746. *
  747. * \since This function is available since SDL 3.0.0.
  748. */
  749. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU16BE(SDL_RWops *dst, Uint16 value);
  750. /**
  751. * Use this function to write 16 bits in native format to an SDL_RWops as
  752. * big-endian data.
  753. *
  754. * SDL byteswaps the data only if necessary, so the application always
  755. * specifies native format, and the data written will be in big-endian format.
  756. *
  757. * \param dst the stream to which data will be written
  758. * \param value the data to be written, in native format
  759. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  760. *
  761. * \since This function is available since SDL 3.0.0.
  762. */
  763. extern DECLSPEC SDL_bool SDLCALL SDL_WriteS16BE(SDL_RWops *dst, Sint16 value);
  764. /**
  765. * Use this function to write 32 bits in native format to an SDL_RWops as
  766. * little-endian data.
  767. *
  768. * SDL byteswaps the data only if necessary, so the application always
  769. * specifies native format, and the data written will be in little-endian
  770. * format.
  771. *
  772. * \param dst the stream to which data will be written
  773. * \param value the data to be written, in native format
  774. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  775. *
  776. * \since This function is available since SDL 3.0.0.
  777. */
  778. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU32LE(SDL_RWops *dst, Uint32 value);
  779. /**
  780. * Use this function to write 32 bits in native format to an SDL_RWops as
  781. * little-endian data.
  782. *
  783. * SDL byteswaps the data only if necessary, so the application always
  784. * specifies native format, and the data written will be in little-endian
  785. * format.
  786. *
  787. * \param dst the stream to which data will be written
  788. * \param value the data to be written, in native format
  789. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  790. *
  791. * \since This function is available since SDL 3.0.0.
  792. */
  793. extern DECLSPEC SDL_bool SDLCALL SDL_WriteS32LE(SDL_RWops *dst, Sint32 value);
  794. /**
  795. * Use this function to write 32 bits in native format to an SDL_RWops as
  796. * big-endian data.
  797. *
  798. * SDL byteswaps the data only if necessary, so the application always
  799. * specifies native format, and the data written will be in big-endian format.
  800. *
  801. * \param dst the stream to which data will be written
  802. * \param value the data to be written, in native format
  803. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  804. *
  805. * \since This function is available since SDL 3.0.0.
  806. */
  807. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU32BE(SDL_RWops *dst, Uint32 value);
  808. /**
  809. * Use this function to write 32 bits in native format to an SDL_RWops as
  810. * big-endian data.
  811. *
  812. * SDL byteswaps the data only if necessary, so the application always
  813. * specifies native format, and the data written will be in big-endian format.
  814. *
  815. * \param dst the stream to which data will be written
  816. * \param value the data to be written, in native format
  817. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  818. *
  819. * \since This function is available since SDL 3.0.0.
  820. */
  821. extern DECLSPEC SDL_bool SDLCALL SDL_WriteS32BE(SDL_RWops *dst, Sint32 value);
  822. /**
  823. * Use this function to write 64 bits in native format to an SDL_RWops as
  824. * little-endian data.
  825. *
  826. * SDL byteswaps the data only if necessary, so the application always
  827. * specifies native format, and the data written will be in little-endian
  828. * format.
  829. *
  830. * \param dst the stream to which data will be written
  831. * \param value the data to be written, in native format
  832. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  833. *
  834. * \since This function is available since SDL 3.0.0.
  835. */
  836. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64LE(SDL_RWops *dst, Uint64 value);
  837. /**
  838. * Use this function to write 64 bits in native format to an SDL_RWops as
  839. * little-endian data.
  840. *
  841. * SDL byteswaps the data only if necessary, so the application always
  842. * specifies native format, and the data written will be in little-endian
  843. * format.
  844. *
  845. * \param dst the stream to which data will be written
  846. * \param value the data to be written, in native format
  847. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  848. *
  849. * \since This function is available since SDL 3.0.0.
  850. */
  851. extern DECLSPEC SDL_bool SDLCALL SDL_WriteS64LE(SDL_RWops *dst, Sint64 value);
  852. /**
  853. * Use this function to write 64 bits in native format to an SDL_RWops as
  854. * big-endian data.
  855. *
  856. * SDL byteswaps the data only if necessary, so the application always
  857. * specifies native format, and the data written will be in big-endian format.
  858. *
  859. * \param dst the stream to which data will be written
  860. * \param value the data to be written, in native format
  861. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  862. *
  863. * \since This function is available since SDL 3.0.0.
  864. */
  865. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64BE(SDL_RWops *dst, Uint64 value);
  866. /**
  867. * Use this function to write 64 bits in native format to an SDL_RWops as
  868. * big-endian data.
  869. *
  870. * SDL byteswaps the data only if necessary, so the application always
  871. * specifies native format, and the data written will be in big-endian format.
  872. *
  873. * \param dst the stream to which data will be written
  874. * \param value the data to be written, in native format
  875. * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call SDL_GetError() for more information.
  876. *
  877. * \since This function is available since SDL 3.0.0.
  878. */
  879. extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64BE(SDL_RWops *dst, Uint64 value);
  880. /* @} *//* Write endian functions */
  881. /* Ends C function definitions when using C++ */
  882. #ifdef __cplusplus
  883. }
  884. #endif
  885. #include <SDL3/SDL_close_code.h>
  886. #endif /* SDL_rwops_h_ */