SDL_rwops.h 35 KB

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