SDL_rwops.h 27 KB

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