SDL_rwops.h 35 KB

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