SDL_rwops.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 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. * \sa SDL_RWclose
  191. * \sa SDL_RWFromConstMem
  192. * \sa SDL_RWFromFP
  193. * \sa SDL_RWFromMem
  194. * \sa SDL_RWread
  195. * \sa SDL_RWseek
  196. * \sa SDL_RWtell
  197. * \sa SDL_RWwrite
  198. */
  199. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
  200. const char *mode);
  201. #ifdef HAVE_STDIO_H
  202. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
  203. #else
  204. /**
  205. * Use this function to create an SDL_RWops structure from a standard I/O file
  206. * pointer (stdio.h's `FILE*`).
  207. *
  208. * This function is not available on Windows, since files opened in an
  209. * application on that platform cannot be used by a dynamically linked
  210. * library.
  211. *
  212. * On some platforms, the first parameter is a `void*`, on others, it's a
  213. * `FILE*`, depending on what system headers are available to SDL. It is
  214. * always intended to be the `FILE*` type from the C runtime's stdio.h.
  215. *
  216. * \param fp the `FILE*` that feeds the SDL_RWops stream
  217. * \param autoclose SDL_TRUE to close the `FILE*` when closing the SDL_RWops,
  218. * SDL_FALSE to leave the `FILE*` open when the RWops is
  219. * closed
  220. * \returns a pointer to the SDL_RWops structure that is created, or NULL on
  221. * failure; call SDL_GetError() for more information.
  222. *
  223. * \sa SDL_RWclose
  224. * \sa SDL_RWFromConstMem
  225. * \sa SDL_RWFromFile
  226. * \sa SDL_RWFromMem
  227. * \sa SDL_RWread
  228. * \sa SDL_RWseek
  229. * \sa SDL_RWtell
  230. * \sa SDL_RWwrite
  231. */
  232. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
  233. SDL_bool autoclose);
  234. #endif
  235. /**
  236. * Use this function to prepare a read-write memory buffer for use with
  237. * SDL_RWops.
  238. *
  239. * This function sets up an SDL_RWops struct based on a memory area of a
  240. * certain size, for both read and write access.
  241. *
  242. * This memory buffer is not copied by the RWops; the pointer you provide must
  243. * remain valid until you close the stream. Closing the stream will not free
  244. * the original buffer.
  245. *
  246. * If you need to make sure the RWops never writes to the memory buffer, you
  247. * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
  248. *
  249. * \param mem a pointer to a buffer to feed an SDL_RWops stream
  250. * \param size the buffer size, in bytes
  251. * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
  252. * SDL_GetError() for more information.
  253. *
  254. * \sa SDL_RWclose
  255. * \sa SDL_RWFromConstMem
  256. * \sa SDL_RWFromFile
  257. * \sa SDL_RWFromFP
  258. * \sa SDL_RWFromMem
  259. * \sa SDL_RWread
  260. * \sa SDL_RWseek
  261. * \sa SDL_RWtell
  262. * \sa SDL_RWwrite
  263. */
  264. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
  265. /**
  266. * Use this function to prepare a read-only memory buffer for use with RWops.
  267. *
  268. * This function sets up an SDL_RWops struct based on a memory area of a
  269. * certain size. It assumes the memory area is not writable.
  270. *
  271. * Attempting to write to this RWops stream will report an error without
  272. * writing to the memory buffer.
  273. *
  274. * This memory buffer is not copied by the RWops; the pointer you provide must
  275. * remain valid until you close the stream. Closing the stream will not free
  276. * the original buffer.
  277. *
  278. * If you need to write to a memory buffer, you should use SDL_RWFromMem()
  279. * with a writable buffer of memory instead.
  280. *
  281. * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
  282. * \param size the buffer size, in bytes
  283. * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
  284. * SDL_GetError() for more information.
  285. *
  286. * \sa SDL_RWclose
  287. * \sa SDL_RWFromConstMem
  288. * \sa SDL_RWFromFile
  289. * \sa SDL_RWFromFP
  290. * \sa SDL_RWFromMem
  291. * \sa SDL_RWread
  292. * \sa SDL_RWseek
  293. * \sa SDL_RWtell
  294. */
  295. extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
  296. int size);
  297. /* @} *//* RWFrom functions */
  298. /**
  299. * Use this function to allocate an empty, unpopulated SDL_RWops structure.
  300. *
  301. * Applications do not need to use this function unless they are providing
  302. * their own SDL_RWops implementation. If you just need a SDL_RWops to
  303. * read/write a common data source, you should use the built-in
  304. * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
  305. *
  306. * You must free the returned pointer with SDL_FreeRW(). Depending on your
  307. * operating system and compiler, there may be a difference between the
  308. * malloc() and free() your program uses and the versions SDL calls
  309. * internally. Trying to mix the two can cause crashing such as segmentation
  310. * faults. Since all SDL_RWops must free themselves when their **close**
  311. * method is called, all SDL_RWops must be allocated through this function, so
  312. * they can all be freed correctly with SDL_FreeRW().
  313. *
  314. * \returns a pointer to the allocated memory on success, or NULL on failure;
  315. * call SDL_GetError() for more information.
  316. *
  317. * \sa SDL_FreeRW
  318. */
  319. extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
  320. /**
  321. * Use this function to free an SDL_RWops structure allocated by
  322. * SDL_AllocRW().
  323. *
  324. * Applications do not need to use this function unless they are providing
  325. * their own SDL_RWops implementation. If you just need a SDL_RWops to
  326. * read/write a common data source, you should use the built-in
  327. * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
  328. * call the **close** method on those SDL_RWops pointers when you are done
  329. * with them.
  330. *
  331. * Only use SDL_FreeRW() on pointers returned by SDL_AllocRW(). The pointer is
  332. * invalid as soon as this function returns. Any extra memory allocated during
  333. * creation of the SDL_RWops is not freed by SDL_FreeRW(); the programmer must
  334. * be responsible for managing that memory in their **close** method.
  335. *
  336. * \param area the SDL_RWops structure to be freed
  337. *
  338. * \sa SDL_AllocRW
  339. */
  340. extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
  341. #define RW_SEEK_SET 0 /**< Seek from the beginning of data */
  342. #define RW_SEEK_CUR 1 /**< Seek relative to current read point */
  343. #define RW_SEEK_END 2 /**< Seek relative to the end of data */
  344. /**
  345. * Use this macro to get the size of the data stream in an SDL_RWops.
  346. *
  347. * \param context the SDL_RWops to get the size of the data stream from
  348. * \returns the size of the data stream in the SDL_RWops on success, -1 if
  349. * unknown or a negative error code on failure; call SDL_GetError()
  350. * for more information.
  351. *
  352. * \since This function is available since SDL 2.0.0.
  353. */
  354. extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
  355. /**
  356. * Seek within an SDL_RWops data stream.
  357. *
  358. * This function seeks to byte `offset`, relative to `whence`.
  359. *
  360. * `whence` may be any of the following values:
  361. *
  362. * - `RW_SEEK_SET`: seek from the beginning of data
  363. * - `RW_SEEK_CUR`: seek relative to current read point
  364. * - `RW_SEEK_END`: seek relative to the end of data
  365. *
  366. * If this stream can not seek, it will return -1.
  367. *
  368. * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
  369. * `seek` method appropriately, to simplify application development.
  370. *
  371. * \param context a pointer to an SDL_RWops structure
  372. * \param offset an offset in bytes, relative to **whence** location; can be
  373. * negative
  374. * \param whence any of `RW_SEEK_SET`, `RW_SEEK_CUR`, `RW_SEEK_END`
  375. * \returns the final offset in the data stream after the seek or -1 on error.
  376. *
  377. * \sa SDL_RWclose
  378. * \sa SDL_RWFromConstMem
  379. * \sa SDL_RWFromFile
  380. * \sa SDL_RWFromFP
  381. * \sa SDL_RWFromMem
  382. * \sa SDL_RWread
  383. * \sa SDL_RWtell
  384. * \sa SDL_RWwrite
  385. */
  386. extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context,
  387. Sint64 offset, int whence);
  388. /**
  389. * Determine the current read/write offset in an SDL_RWops data stream.
  390. *
  391. * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
  392. * method, with an offset of 0 bytes from `RW_SEEK_CUR`, to simplify
  393. * application development.
  394. *
  395. * \param context a SDL_RWops data stream object from which to get the current
  396. * offset
  397. * \returns the current offset in the stream, or -1 if the information can not
  398. * be determined.
  399. *
  400. * \sa SDL_RWclose
  401. * \sa SDL_RWFromConstMem
  402. * \sa SDL_RWFromFile
  403. * \sa SDL_RWFromFP
  404. * \sa SDL_RWFromMem
  405. * \sa SDL_RWread
  406. * \sa SDL_RWseek
  407. * \sa SDL_RWwrite
  408. */
  409. extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
  410. /**
  411. * Read from a data source.
  412. *
  413. * This function reads up to `maxnum` objects each of size `size` from the
  414. * data source to the area pointed at by `ptr`. This function may read less
  415. * objects than requested. It will return zero when there has been an error or
  416. * the data stream is completely read.
  417. *
  418. * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
  419. * `read` method appropriately, to simplify application development.
  420. *
  421. * \param context a pointer to an SDL_RWops structure
  422. * \param ptr a pointer to a buffer to read data into
  423. * \param size the size of each object to read, in bytes
  424. * \param maxnum the maximum number of objects to be read
  425. * \returns the number of objects read, or 0 at error or end of file; call
  426. * SDL_GetError() for more information.
  427. *
  428. * \sa SDL_RWclose
  429. * \sa SDL_RWFromConstMem
  430. * \sa SDL_RWFromFile
  431. * \sa SDL_RWFromFP
  432. * \sa SDL_RWFromMem
  433. * \sa SDL_RWseek
  434. * \sa SDL_RWwrite
  435. */
  436. extern DECLSPEC size_t SDLCALL SDL_RWread(SDL_RWops *context,
  437. void *ptr, size_t size,
  438. size_t maxnum);
  439. /**
  440. * Write to an SDL_RWops data stream.
  441. *
  442. * This function writes exactly `num` objects each of size `size` from the
  443. * area pointed at by `ptr` to the stream. If this fails for any reason, it'll
  444. * return less than `num` to demonstrate how far the write progressed. On
  445. * success, it returns `num`.
  446. *
  447. * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
  448. * `write` method appropriately, to simplify application development.
  449. *
  450. * \param context a pointer to an SDL_RWops structure
  451. * \param ptr a pointer to a buffer containing data to write
  452. * \param size the size of an object to write, in bytes
  453. * \param num the number of objects to write
  454. * \returns the number of objects written, which will be less than **num** on
  455. * error; call SDL_GetError() for more information.
  456. *
  457. * \sa SDL_RWclose
  458. * \sa SDL_RWFromConstMem
  459. * \sa SDL_RWFromFile
  460. * \sa SDL_RWFromFP
  461. * \sa SDL_RWFromMem
  462. * \sa SDL_RWread
  463. * \sa SDL_RWseek
  464. */
  465. extern DECLSPEC size_t SDLCALL SDL_RWwrite(SDL_RWops *context,
  466. const void *ptr, size_t size,
  467. size_t num);
  468. /**
  469. * Close and free an allocated SDL_RWops structure.
  470. *
  471. * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
  472. * resources used by the stream and frees the SDL_RWops itself with
  473. * SDL_FreeRW(). This returns 0 on success, or -1 if the stream failed to
  474. * flush to its output (e.g. to disk).
  475. *
  476. * Note that if this fails to flush the stream to disk, this function reports
  477. * an error, but the SDL_RWops is still invalid once this function returns.
  478. *
  479. * SDL_RWclose() is actually a macro that calls the SDL_RWops's `close` method
  480. * appropriately, to simplify application development.
  481. *
  482. * \param context SDL_RWops structure to close
  483. * \returns 0 on success or a negative error code on failure; call
  484. * SDL_GetError() for more information.
  485. *
  486. * \sa SDL_RWFromConstMem
  487. * \sa SDL_RWFromFile
  488. * \sa SDL_RWFromFP
  489. * \sa SDL_RWFromMem
  490. * \sa SDL_RWread
  491. * \sa SDL_RWseek
  492. * \sa SDL_RWwrite
  493. */
  494. extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
  495. /**
  496. * Load all the data from an SDL data stream.
  497. *
  498. * The data is allocated with a zero byte at the end (null terminated) for
  499. * convenience. This extra byte is not included in the value reported via
  500. * `datasize`.
  501. *
  502. * The data should be freed with SDL_free().
  503. *
  504. * \param src the SDL_RWops to read all available data from
  505. * \param datasize if not NULL, will store the number of bytes read
  506. * \param freesrc if non-zero, calls SDL_RWclose() on `src` before returning
  507. * \returns the data, or NULL if there was an error.
  508. */
  509. extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
  510. size_t *datasize,
  511. int freesrc);
  512. /**
  513. * Load all the data from a file path.
  514. *
  515. * The data is allocated with a zero byte at the end (null terminated) for
  516. * convenience. This extra byte is not included in the value reported via
  517. * `datasize`.
  518. *
  519. * The data should be freed with SDL_free().
  520. *
  521. * \param file the path to read all available data from
  522. * \param datasize if not NULL, will store the number of bytes read
  523. * \returns the data, or NULL if there was an error.
  524. */
  525. extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
  526. /**
  527. * \name Read endian functions
  528. *
  529. * Read an item of the specified endianness and return in native format.
  530. */
  531. /* @{ */
  532. /**
  533. * Use this function to read a byte from an SDL_RWops.
  534. *
  535. * \param src the SDL_RWops to read from
  536. * \returns the read byte on success or 0 on failure; call SDL_GetError() for
  537. * more information.
  538. *
  539. * \since This function is available since SDL 2.0.0.
  540. *
  541. * \sa SDL_WriteU8
  542. */
  543. extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
  544. /**
  545. * Use this function to read 16 bits of little-endian data from an SDL_RWops
  546. * and return in native format.
  547. *
  548. * SDL byteswaps the data only if necessary, so the data returned will be in
  549. * the native byte order.
  550. *
  551. * \param src the stream from which to read data
  552. * \returns 16 bits of data in the native byte order of the platform.
  553. *
  554. * \sa SDL_ReadBE16
  555. */
  556. extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
  557. /**
  558. * Use this function to read 16 bits of big-endian data from an SDL_RWops and
  559. * 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. * \sa SDL_ReadLE16
  568. */
  569. extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
  570. /**
  571. * Use this function to read 32 bits of little-endian data from an SDL_RWops
  572. * and return in native format.
  573. *
  574. * SDL byteswaps the data only if necessary, so the data returned will be in
  575. * the native byte order.
  576. *
  577. * \param src the stream from which to read data
  578. * \returns 32 bits of data in the native byte order of the platform.
  579. *
  580. * \sa SDL_ReadBE32
  581. */
  582. extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
  583. /**
  584. * Use this function to read 32 bits of big-endian data from an SDL_RWops and
  585. * return in native format.
  586. *
  587. * SDL byteswaps the data only if necessary, so the data returned will be in
  588. * the native byte order.
  589. *
  590. * \param src the stream from which to read data
  591. * \returns 32 bits of data in the native byte order of the platform.
  592. *
  593. * \sa SDL_ReadLE32
  594. */
  595. extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
  596. /**
  597. * Use this function to read 64 bits of little-endian data from an SDL_RWops
  598. * and return in native format.
  599. *
  600. * SDL byteswaps the data only if necessary, so the data returned will be in
  601. * the native byte order.
  602. *
  603. * \param src the stream from which to read data
  604. * \returns 64 bits of data in the native byte order of the platform.
  605. *
  606. * \sa SDL_ReadBE64
  607. */
  608. extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
  609. /**
  610. * Use this function to read 64 bits of big-endian data from an SDL_RWops and
  611. * return in native format.
  612. *
  613. * SDL byteswaps the data only if necessary, so the data returned will be in
  614. * the native byte order.
  615. *
  616. * \param src the stream from which to read data
  617. * \returns 64 bits of data in the native byte order of the platform.
  618. *
  619. * \sa SDL_ReadLE64
  620. */
  621. extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
  622. /* @} *//* Read endian functions */
  623. /**
  624. * \name Write endian functions
  625. *
  626. * Write an item of native format to the specified endianness.
  627. */
  628. /* @{ */
  629. /**
  630. * Use this function to write a byte to an SDL_RWops.
  631. *
  632. * \param dst the SDL_RWops to write to
  633. * \param value the byte value to write
  634. * \returns 1 on success or 0 on failure; call SDL_GetError() for more
  635. * information.
  636. *
  637. * \since This function is available since SDL 2.0.0.
  638. *
  639. * \sa SDL_ReadU8
  640. */
  641. extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
  642. /**
  643. * Use this function to write 16 bits in native format to a SDL_RWops as
  644. * little-endian data.
  645. *
  646. * SDL byteswaps the data only if necessary, so the application always
  647. * specifies native format, and the data written will be in little-endian
  648. * format.
  649. *
  650. * \param dst the stream to which data will be written
  651. * \param value the data to be written, in native format
  652. * \returns 1 on successful write, 0 on error.
  653. *
  654. * \sa SDL_WriteBE16
  655. */
  656. extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
  657. /**
  658. * Use this function to write 16 bits in native format to a SDL_RWops as
  659. * big-endian data.
  660. *
  661. * SDL byteswaps the data only if necessary, so the application always
  662. * specifies native format, and the data written will be in big-endian format.
  663. *
  664. * \param dst the stream to which data will be written
  665. * \param value the data to be written, in native format
  666. * \returns 1 on successful write, 0 on error.
  667. *
  668. * \sa SDL_WriteLE16
  669. */
  670. extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
  671. /**
  672. * Use this function to write 32 bits in native format to a SDL_RWops as
  673. * little-endian data.
  674. *
  675. * SDL byteswaps the data only if necessary, so the application always
  676. * specifies native format, and the data written will be in little-endian
  677. * format.
  678. *
  679. * \param dst the stream to which data will be written
  680. * \param value the data to be written, in native format
  681. * \returns 1 on successful write, 0 on error.
  682. *
  683. * \sa SDL_WriteBE32
  684. */
  685. extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
  686. /**
  687. * Use this function to write 32 bits in native format to a SDL_RWops as
  688. * big-endian data.
  689. *
  690. * SDL byteswaps the data only if necessary, so the application always
  691. * specifies native format, and the data written will be in big-endian format.
  692. *
  693. * \param dst the stream to which data will be written
  694. * \param value the data to be written, in native format
  695. * \returns 1 on successful write, 0 on error.
  696. *
  697. * \sa SDL_WriteLE32
  698. */
  699. extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
  700. /**
  701. * Use this function to write 64 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. * \sa SDL_WriteBE64
  713. */
  714. extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
  715. /**
  716. * Use this function to write 64 bits in native format to a SDL_RWops as
  717. * big-endian data.
  718. *
  719. * SDL byteswaps the data only if necessary, so the application always
  720. * specifies native format, and the data written will be in big-endian format.
  721. *
  722. * \param dst the stream to which data will be written
  723. * \param value the data to be written, in native format
  724. * \returns 1 on successful write, 0 on error.
  725. *
  726. * \sa SDL_WriteLE64
  727. */
  728. extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
  729. /* @} *//* Write endian functions */
  730. /* Ends C function definitions when using C++ */
  731. #ifdef __cplusplus
  732. }
  733. #endif
  734. #include "close_code.h"
  735. #endif /* SDL_rwops_h_ */
  736. /* vi: set ts=4 sw=4 expandtab: */