|
@@ -156,25 +156,216 @@ typedef struct SDL_RWops
|
|
|
*/
|
|
|
/* @{ */
|
|
|
|
|
|
+/**
|
|
|
+ * Use this function to create a new SDL_RWops structure for reading from
|
|
|
+ * and/or writing to a named file.
|
|
|
+ *
|
|
|
+ * The `mode` string is treated roughly the same as in a call to the C
|
|
|
+ * library's fopen(), even if SDL doesn't happen to use fopen() behind the
|
|
|
+ * scenes.
|
|
|
+ *
|
|
|
+ * Available `mode` strings:
|
|
|
+ *
|
|
|
+ * - "r": Open a file for reading. The file must exist.
|
|
|
+ * - "w": Create an empty file for writing. If a file with the same name
|
|
|
+ * already exists its content is erased and the file is treated as a new
|
|
|
+ * empty file.
|
|
|
+ * - "a": Append to a file. Writing operations append data at the end of the
|
|
|
+ * file. The file is created if it does not exist.
|
|
|
+ * - "r+": Open a file for update both reading and writing. The file must
|
|
|
+ * exist.
|
|
|
+ * - "w+": Create an empty file for both reading and writing. If a file with
|
|
|
+ * the same name already exists its content is erased and the file is
|
|
|
+ * treated as a new empty file.
|
|
|
+ * - "a+": Open a file for reading and appending. All writing operations are
|
|
|
+ * performed at the end of the file, protecting the previous content to be
|
|
|
+ * overwritten. You can reposition (fseek, rewind) the internal pointer to
|
|
|
+ * anywhere in the file for reading, but writing operations will move it
|
|
|
+ * back to the end of file. The file is created if it does not exist.
|
|
|
+ *
|
|
|
+ * **NOTE**: In order to open a file as a binary file, a "b" character has to
|
|
|
+ * be included in the `mode` string. This additional "b" character can either
|
|
|
+ * be appended at the end of the string (thus making the following compound
|
|
|
+ * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the
|
|
|
+ * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").
|
|
|
+ * Additional characters may follow the sequence, although they should have no
|
|
|
+ * effect. For example, "t" is sometimes appended to make explicit the file is
|
|
|
+ * a text file.
|
|
|
+ *
|
|
|
+ * This function supports Unicode filenames, but they must be encoded in UTF-8
|
|
|
+ * format, regardless of the underlying operating system.
|
|
|
+ *
|
|
|
+ * As a fallback, SDL_RWFromFile() will transparently open a matching filename
|
|
|
+ * in an Android app's `assets`.
|
|
|
+ *
|
|
|
+ * Closing the SDL_RWops will close the file handle SDL is holding internally.
|
|
|
+ *
|
|
|
+ * \param file a UTF-8 string representing the filename to open
|
|
|
+ * \param mode an ASCII string representing the mode to be used for opening
|
|
|
+ * the file.
|
|
|
+ * \returns a pointer to the SDL_RWops structure that is created, or NULL on
|
|
|
+ * failure; call SDL_GetError() for more information.
|
|
|
+ *
|
|
|
+ * \sa SDL_RWclose
|
|
|
+ * \sa SDL_RWFromConstMem
|
|
|
+ * \sa SDL_RWFromFP
|
|
|
+ * \sa SDL_RWFromMem
|
|
|
+ * \sa SDL_RWread
|
|
|
+ * \sa SDL_RWseek
|
|
|
+ * \sa SDL_RWtell
|
|
|
+ * \sa SDL_RWwrite
|
|
|
+ */
|
|
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
|
|
|
const char *mode);
|
|
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
-extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
|
|
|
- SDL_bool autoclose);
|
|
|
+
|
|
|
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
|
|
|
+
|
|
|
#else
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to create an SDL_RWops structure from a standard I/O file
|
|
|
+ * pointer (stdio.h's `FILE*`).
|
|
|
+ *
|
|
|
+ * This function is not available on Windows, since files opened in an
|
|
|
+ * application on that platform cannot be used by a dynamically linked
|
|
|
+ * library.
|
|
|
+ *
|
|
|
+ * On some platforms, the first parameter is a `void*`, on others, it's a
|
|
|
+ * `FILE*`, depending on what system headers are available to SDL. It is
|
|
|
+ * always intended to be the `FILE*` type from the C runtime's stdio.h.
|
|
|
+ *
|
|
|
+ * \param fp the `FILE*` that feeds the SDL_RWops stream
|
|
|
+ * \param autoclose SDL_TRUE to close the `FILE*` when closing the SDL_RWops,
|
|
|
+ * SDL_FALSE to leave the `FILE*` open when the RWops is
|
|
|
+ * closed
|
|
|
+ * \returns a pointer to the SDL_RWops structure that is created, or NULL on
|
|
|
+ * failure; call SDL_GetError() for more information.
|
|
|
+ *
|
|
|
+ * \sa SDL_RWclose
|
|
|
+ * \sa SDL_RWFromConstMem
|
|
|
+ * \sa SDL_RWFromFile
|
|
|
+ * \sa SDL_RWFromMem
|
|
|
+ * \sa SDL_RWread
|
|
|
+ * \sa SDL_RWseek
|
|
|
+ * \sa SDL_RWtell
|
|
|
+ * \sa SDL_RWwrite
|
|
|
+ */
|
|
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
|
|
|
SDL_bool autoclose);
|
|
|
#endif
|
|
|
|
|
|
+/**
|
|
|
+ * Use this function to prepare a read-write memory buffer for use with
|
|
|
+ * SDL_RWops.
|
|
|
+ *
|
|
|
+ * This function sets up an SDL_RWops struct based on a memory area of a
|
|
|
+ * certain size, for both read and write access.
|
|
|
+ *
|
|
|
+ * This memory buffer is not copied by the RWops; the pointer you provide must
|
|
|
+ * remain valid until you close the stream. Closing the stream will not free
|
|
|
+ * the original buffer.
|
|
|
+ *
|
|
|
+ * If you need to make sure the RWops never writes to the memory buffer, you
|
|
|
+ * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
|
|
|
+ *
|
|
|
+ * \param mem a pointer to a buffer to feed an SDL_RWops stream
|
|
|
+ * \param size the buffer size, in bytes
|
|
|
+ * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
|
|
|
+ * SDL_GetError() for more information.
|
|
|
+ *
|
|
|
+ * \sa SDL_RWclose
|
|
|
+ * \sa SDL_RWFromConstMem
|
|
|
+ * \sa SDL_RWFromFile
|
|
|
+ * \sa SDL_RWFromFP
|
|
|
+ * \sa SDL_RWFromMem
|
|
|
+ * \sa SDL_RWread
|
|
|
+ * \sa SDL_RWseek
|
|
|
+ * \sa SDL_RWtell
|
|
|
+ * \sa SDL_RWwrite
|
|
|
+ */
|
|
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to prepare a read-only memory buffer for use with RWops.
|
|
|
+ *
|
|
|
+ * This function sets up an SDL_RWops struct based on a memory area of a
|
|
|
+ * certain size. It assumes the memory area is not writable.
|
|
|
+ *
|
|
|
+ * Attempting to write to this RWops stream will report an error without
|
|
|
+ * writing to the memory buffer.
|
|
|
+ *
|
|
|
+ * This memory buffer is not copied by the RWops; the pointer you provide must
|
|
|
+ * remain valid until you close the stream. Closing the stream will not free
|
|
|
+ * the original buffer.
|
|
|
+ *
|
|
|
+ * If you need to write to a memory buffer, you should use SDL_RWFromMem()
|
|
|
+ * with a writable buffer of memory instead.
|
|
|
+ *
|
|
|
+ * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
|
|
|
+ * \param size the buffer size, in bytes
|
|
|
+ * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
|
|
|
+ * SDL_GetError() for more information.
|
|
|
+ *
|
|
|
+ * \sa SDL_RWclose
|
|
|
+ * \sa SDL_RWFromConstMem
|
|
|
+ * \sa SDL_RWFromFile
|
|
|
+ * \sa SDL_RWFromFP
|
|
|
+ * \sa SDL_RWFromMem
|
|
|
+ * \sa SDL_RWread
|
|
|
+ * \sa SDL_RWseek
|
|
|
+ * \sa SDL_RWtell
|
|
|
+ */
|
|
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
|
|
|
int size);
|
|
|
|
|
|
/* @} *//* RWFrom functions */
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ * Use this function to allocate an empty, unpopulated SDL_RWops structure.
|
|
|
+ *
|
|
|
+ * Applications do not need to use this function unless they are providing
|
|
|
+ * their own SDL_RWops implementation. If you just need a SDL_RWops to
|
|
|
+ * read/write a common data source, you should use the built-in
|
|
|
+ * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
|
|
|
+ *
|
|
|
+ * You must free the returned pointer with SDL_FreeRW(). Depending on your
|
|
|
+ * operating system and compiler, there may be a difference between the
|
|
|
+ * malloc() and free() your program uses and the versions SDL calls
|
|
|
+ * internally. Trying to mix the two can cause crashing such as segmentation
|
|
|
+ * faults. Since all SDL_RWops must free themselves when their **close**
|
|
|
+ * method is called, all SDL_RWops must be allocated through this function, so
|
|
|
+ * they can all be freed correctly with SDL_FreeRW().
|
|
|
+ *
|
|
|
+ * \returns a pointer to the allocated memory on success, or NULL on failure;
|
|
|
+ * call SDL_GetError() for more information.
|
|
|
+ *
|
|
|
+ * \sa SDL_FreeRW
|
|
|
+ */
|
|
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to free an SDL_RWops structure allocated by
|
|
|
+ * SDL_AllocRW().
|
|
|
+ *
|
|
|
+ * Applications do not need to use this function unless they are providing
|
|
|
+ * their own SDL_RWops implementation. If you just need a SDL_RWops to
|
|
|
+ * read/write a common data source, you should use the built-in
|
|
|
+ * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
|
|
|
+ * call the **close** method on those SDL_RWops pointers when you are done
|
|
|
+ * with them.
|
|
|
+ *
|
|
|
+ * Only use SDL_FreeRW() on pointers returned by SDL_AllocRW(). The pointer is
|
|
|
+ * invalid as soon as this function returns. Any extra memory allocated during
|
|
|
+ * creation of the SDL_RWops is not freed by SDL_FreeRW(); the programmer must
|
|
|
+ * be responsible for managing that memory in their **close** method.
|
|
|
+ *
|
|
|
+ * \param area the SDL_RWops structure to be freed
|
|
|
+ *
|
|
|
+ * \sa SDL_AllocRW
|
|
|
+ */
|
|
|
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
|
|
|
|
|
|
#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
|
|
@@ -377,12 +568,102 @@ extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
|
|
|
* Read an item of the specified endianness and return in native format.
|
|
|
*/
|
|
|
/* @{ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read a byte from an SDL_RWops.
|
|
|
+ *
|
|
|
+ * \param src the SDL_RWops to read from
|
|
|
+ * \returns the read byte on success or 0 on failure; call SDL_GetError() for
|
|
|
+ * more information.
|
|
|
+ *
|
|
|
+ * \since This function is available since SDL 2.0.0.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteU8
|
|
|
+ */
|
|
|
extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 16 bits of little-endian data from an SDL_RWops
|
|
|
+ * and return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 16 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadBE16
|
|
|
+ */
|
|
|
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 16 bits of big-endian data from an SDL_RWops and
|
|
|
+ * return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 16 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadLE16
|
|
|
+ */
|
|
|
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 32 bits of little-endian data from an SDL_RWops
|
|
|
+ * and return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 32 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadBE32
|
|
|
+ */
|
|
|
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 32 bits of big-endian data from an SDL_RWops and
|
|
|
+ * return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 32 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadLE32
|
|
|
+ */
|
|
|
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 64 bits of little-endian data from an SDL_RWops
|
|
|
+ * and return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 64 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadBE64
|
|
|
+ */
|
|
|
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to read 64 bits of big-endian data from an SDL_RWops and
|
|
|
+ * return in native format.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the data returned will be in
|
|
|
+ * the native byte order.
|
|
|
+ *
|
|
|
+ * \param src the stream from which to read data
|
|
|
+ * \returns 64 bits of data in the native byte order of the platform.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadLE64
|
|
|
+ */
|
|
|
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
|
|
|
/* @} *//* Read endian functions */
|
|
|
|
|
@@ -392,12 +673,112 @@ extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
|
|
|
* Write an item of native format to the specified endianness.
|
|
|
*/
|
|
|
/* @{ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write a byte to an SDL_RWops.
|
|
|
+ *
|
|
|
+ * \param dst the SDL_RWops to write to
|
|
|
+ * \param value the byte value to write
|
|
|
+ * \returns 1 on success or 0 on failure; call SDL_GetError() for more
|
|
|
+ * information.
|
|
|
+ *
|
|
|
+ * \since This function is available since SDL 2.0.0.
|
|
|
+ *
|
|
|
+ * \sa SDL_ReadU8
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 16 bits in native format to a SDL_RWops as
|
|
|
+ * little-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in little-endian
|
|
|
+ * format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteBE16
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 16 bits in native format to a SDL_RWops as
|
|
|
+ * big-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in big-endian format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteLE16
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 32 bits in native format to a SDL_RWops as
|
|
|
+ * little-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in little-endian
|
|
|
+ * format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteBE32
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 32 bits in native format to a SDL_RWops as
|
|
|
+ * big-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in big-endian format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteLE32
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 64 bits in native format to a SDL_RWops as
|
|
|
+ * little-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in little-endian
|
|
|
+ * format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteBE64
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Use this function to write 64 bits in native format to a SDL_RWops as
|
|
|
+ * big-endian data.
|
|
|
+ *
|
|
|
+ * SDL byteswaps the data only if necessary, so the application always
|
|
|
+ * specifies native format, and the data written will be in big-endian format.
|
|
|
+ *
|
|
|
+ * \param dst the stream to which data will be written
|
|
|
+ * \param value the data to be written, in native format
|
|
|
+ * \returns 1 on successful write, 0 on error.
|
|
|
+ *
|
|
|
+ * \sa SDL_WriteLE64
|
|
|
+ */
|
|
|
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
|
|
|
/* @} *//* Write endian functions */
|
|
|
|