🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

855 lines
28 KiB

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