rwops: Give implementations access to status value.
parent
447c29e65c
commit
fe33b2a81b
|
@ -71,17 +71,25 @@ typedef struct SDL_RWopsInterface
|
||||||
* Read up to \c size bytes from the data stream to the area pointed
|
* Read up to \c size bytes from the data stream to the area pointed
|
||||||
* at by \c ptr.
|
* at by \c ptr.
|
||||||
*
|
*
|
||||||
|
* On an incomplete read, you should set `*status` to a value from the
|
||||||
|
* SDL_RWopsStatus enum. You do not have to explicitly set this on
|
||||||
|
* a complete, successful read.
|
||||||
|
*
|
||||||
* \return the number of bytes read
|
* \return the number of bytes read
|
||||||
*/
|
*/
|
||||||
size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size);
|
size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_RWopsStatus *status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write exactly \c size bytes from the area pointed at by \c ptr
|
* Write exactly \c size bytes from the area pointed at by \c ptr
|
||||||
* to data stream.
|
* to data stream.
|
||||||
*
|
*
|
||||||
|
* On an incomplete write, you should set `*status` to a value from the
|
||||||
|
* SDL_RWopsStatus enum. You do not have to explicitly set this on
|
||||||
|
* a complete, successful write.
|
||||||
|
*
|
||||||
* \return the number of bytes written
|
* \return the number of bytes written
|
||||||
*/
|
*/
|
||||||
size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size);
|
size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_RWopsStatus *status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close and free any allocated resources.
|
* Close and free any allocated resources.
|
||||||
|
|
|
@ -203,7 +203,7 @@ static Sint64 SDLCALL windows_file_seek(void *userdata, Sint64 offset, int whenc
|
||||||
return windowsoffset.QuadPart;
|
return windowsoffset.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL windows_file_read(void *userdata, void *ptr, size_t size)
|
static size_t SDLCALL windows_file_read(void *userdata, void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
RWopsWindowsData *rwopsdata = (RWopsWindowsData *) userdata;
|
RWopsWindowsData *rwopsdata = (RWopsWindowsData *) userdata;
|
||||||
size_t total_need = size;
|
size_t total_need = size;
|
||||||
|
@ -247,7 +247,7 @@ static size_t SDLCALL windows_file_read(void *userdata, void *ptr, size_t size)
|
||||||
return total_read;
|
return total_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL windows_file_write(void *userdata, const void *ptr, size_t size)
|
static size_t SDLCALL windows_file_write(void *userdata, const void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
RWopsWindowsData *rwopsdata = (RWopsWindowsData *) userdata;
|
RWopsWindowsData *rwopsdata = (RWopsWindowsData *) userdata;
|
||||||
const size_t total_bytes = size;
|
const size_t total_bytes = size;
|
||||||
|
@ -373,7 +373,7 @@ static Sint64 SDLCALL stdio_seek(void *userdata, Sint64 offset, int whence)
|
||||||
return SDL_Error(SDL_EFSEEK);
|
return SDL_Error(SDL_EFSEEK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size)
|
static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
RWopsStdioData *rwopsdata = (RWopsStdioData *) userdata;
|
RWopsStdioData *rwopsdata = (RWopsStdioData *) userdata;
|
||||||
const size_t bytes = fread(ptr, 1, size, rwopsdata->fp);
|
const size_t bytes = fread(ptr, 1, size, rwopsdata->fp);
|
||||||
|
@ -383,7 +383,7 @@ static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size)
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL stdio_write(void *userdata, const void *ptr, size_t size)
|
static size_t SDLCALL stdio_write(void *userdata, const void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
RWopsStdioData *rwopsdata = (RWopsStdioData *) userdata;
|
RWopsStdioData *rwopsdata = (RWopsStdioData *) userdata;
|
||||||
const size_t bytes = fwrite(ptr, 1, size, rwopsdata->fp);
|
const size_t bytes = fwrite(ptr, 1, size, rwopsdata->fp);
|
||||||
|
@ -493,13 +493,13 @@ static size_t mem_io(void *userdata, void *dst, const void *src, size_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL mem_read(void *userdata, void *ptr, size_t size)
|
static size_t SDLCALL mem_read(void *userdata, void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
const RWopsMemData *rwopsdata = (RWopsMemData *) userdata;
|
const RWopsMemData *rwopsdata = (RWopsMemData *) userdata;
|
||||||
return mem_io(userdata, ptr, rwopsdata->here, size);
|
return mem_io(userdata, ptr, rwopsdata->here, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t SDLCALL mem_write(void *userdata, const void *ptr, size_t size)
|
static size_t SDLCALL mem_write(void *userdata, const void *ptr, size_t size, SDL_RWopsStatus *status)
|
||||||
{
|
{
|
||||||
const RWopsMemData *rwopsdata = (RWopsMemData *) userdata;
|
const RWopsMemData *rwopsdata = (RWopsMemData *) userdata;
|
||||||
return mem_io(userdata, rwopsdata->here, ptr, size);
|
return mem_io(userdata, rwopsdata->here, ptr, size);
|
||||||
|
@ -903,7 +903,7 @@ size_t SDL_ReadRW(SDL_RWops *context, void *ptr, size_t size)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = context->iface.read(context->userdata, ptr, size);
|
bytes = context->iface.read(context->userdata, ptr, size, &context->status);
|
||||||
if (bytes == 0 && context->status == SDL_RWOPS_STATUS_READY) {
|
if (bytes == 0 && context->status == SDL_RWOPS_STATUS_READY) {
|
||||||
if (*SDL_GetError()) {
|
if (*SDL_GetError()) {
|
||||||
context->status = SDL_RWOPS_STATUS_ERROR;
|
context->status = SDL_RWOPS_STATUS_ERROR;
|
||||||
|
@ -934,7 +934,7 @@ size_t SDL_WriteRW(SDL_RWops *context, const void *ptr, size_t size)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = context->iface.write(context->userdata, ptr, size);
|
bytes = context->iface.write(context->userdata, ptr, size, &context->status);
|
||||||
if ((bytes == 0) && (context->status == SDL_RWOPS_STATUS_READY)) {
|
if ((bytes == 0) && (context->status == SDL_RWOPS_STATUS_READY)) {
|
||||||
context->status = SDL_RWOPS_STATUS_ERROR;
|
context->status = SDL_RWOPS_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue