mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-25 14:09:10 +00:00
Initialize interface structures so they can be extended in the future
We guarantee that we will only add to the end of these interfaces, and any new fields will be optional.
This commit is contained in:
parent
434193d153
commit
702ed83f72
13 changed files with 130 additions and 22 deletions
|
@ -419,7 +419,7 @@ static SDL_IOStream *SDL_IOFromFP(FILE *fp, bool autoclose)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
// There's no stdio_size because SDL_GetIOSize emulates it the same way we'd do it for stdio anyhow.
|
||||
iface.seek = stdio_seek;
|
||||
iface.read = stdio_read;
|
||||
|
@ -607,7 +607,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
iface.size = Android_JNI_FileSize;
|
||||
iface.seek = Android_JNI_FileSeek;
|
||||
iface.read = Android_JNI_FileRead;
|
||||
|
@ -636,7 +636,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
iface.size = windows_file_size;
|
||||
iface.seek = windows_file_seek;
|
||||
iface.read = windows_file_read;
|
||||
|
@ -698,7 +698,7 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
iface.size = mem_size;
|
||||
iface.seek = mem_seek;
|
||||
iface.read = mem_read;
|
||||
|
@ -732,7 +732,7 @@ SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
iface.size = mem_size;
|
||||
iface.seek = mem_seek;
|
||||
iface.read = mem_read;
|
||||
|
@ -832,7 +832,7 @@ SDL_IOStream *SDL_IOFromDynamicMem(void)
|
|||
}
|
||||
|
||||
SDL_IOStreamInterface iface;
|
||||
SDL_zero(iface);
|
||||
SDL_INIT_INTERFACE(&iface);
|
||||
iface.size = dynamic_mem_size;
|
||||
iface.seek = dynamic_mem_seek;
|
||||
iface.read = dynamic_mem_read;
|
||||
|
@ -868,6 +868,11 @@ SDL_IOStream *SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
|
|||
SDL_InvalidParamError("iface");
|
||||
return NULL;
|
||||
}
|
||||
if (iface->version < sizeof(*iface)) {
|
||||
// Update this to handle older versions of this interface
|
||||
SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_IOStream *iostr = (SDL_IOStream *)SDL_calloc(1, sizeof(*iostr));
|
||||
if (iostr) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue