Add properties to SDL_IOStreams returned by IOFromMem
This commit is contained in:
@@ -291,6 +291,13 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, cons
|
|||||||
* buffer, you should use SDL_IOFromConstMem() with a read-only buffer of
|
* buffer, you should use SDL_IOFromConstMem() with a read-only buffer of
|
||||||
* memory instead.
|
* memory instead.
|
||||||
*
|
*
|
||||||
|
* The following properties will be set at creation time by SDL:
|
||||||
|
*
|
||||||
|
* - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
|
||||||
|
* was passed to this function.
|
||||||
|
* - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
|
||||||
|
* that was passed to this function.
|
||||||
|
*
|
||||||
* \param mem a pointer to a buffer to feed an SDL_IOStream stream.
|
* \param mem a pointer to a buffer to feed an SDL_IOStream stream.
|
||||||
* \param size the buffer size, in bytes.
|
* \param size the buffer size, in bytes.
|
||||||
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
|
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
|
||||||
@@ -308,6 +315,9 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, cons
|
|||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size);
|
extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size);
|
||||||
|
|
||||||
|
#define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base"
|
||||||
|
#define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this function to prepare a read-only memory buffer for use with
|
* Use this function to prepare a read-only memory buffer for use with
|
||||||
* SDL_IOStream.
|
* SDL_IOStream.
|
||||||
@@ -325,6 +335,13 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size)
|
|||||||
* If you need to write to a memory buffer, you should use SDL_IOFromMem()
|
* If you need to write to a memory buffer, you should use SDL_IOFromMem()
|
||||||
* with a writable buffer of memory instead.
|
* with a writable buffer of memory instead.
|
||||||
*
|
*
|
||||||
|
* The following properties will be set at creation time by SDL:
|
||||||
|
*
|
||||||
|
* - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that
|
||||||
|
* was passed to this function.
|
||||||
|
* - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter
|
||||||
|
* that was passed to this function.
|
||||||
|
*
|
||||||
* \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream.
|
* \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream.
|
||||||
* \param size the buffer size, in bytes.
|
* \param size the buffer size, in bytes.
|
||||||
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
|
* \returns a pointer to a new SDL_IOStream structure or NULL on failure; call
|
||||||
|
|||||||
@@ -793,6 +793,12 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
|
|||||||
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
|
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
|
||||||
if (!iostr) {
|
if (!iostr) {
|
||||||
SDL_free(iodata);
|
SDL_free(iodata);
|
||||||
|
} else {
|
||||||
|
const SDL_PropertiesID props = SDL_GetIOProperties(iostr);
|
||||||
|
if (props) {
|
||||||
|
SDL_SetPointerProperty(props, SDL_PROP_IOSTREAM_MEMORY_POINTER, mem);
|
||||||
|
SDL_SetNumberProperty(props, SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return iostr;
|
return iostr;
|
||||||
}
|
}
|
||||||
@@ -827,6 +833,12 @@ SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
|
|||||||
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
|
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
|
||||||
if (!iostr) {
|
if (!iostr) {
|
||||||
SDL_free(iodata);
|
SDL_free(iodata);
|
||||||
|
} else {
|
||||||
|
const SDL_PropertiesID props = SDL_GetIOProperties(iostr);
|
||||||
|
if (props) {
|
||||||
|
SDL_SetPointerProperty(props, SDL_PROP_IOSTREAM_MEMORY_POINTER, (void *)mem);
|
||||||
|
SDL_SetNumberProperty(props, SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return iostr;
|
return iostr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user