SDL_rwops.h 35 KB

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