mirror of https://github.com/libsdl-org/SDL
Removed SDL_rwops.h dependency on stdio.h
This commit is contained in:
parent
34d538bd13
commit
fa3814ddf1
|
@ -112,13 +112,12 @@ typedef struct SDL_RWops
|
|||
} windowsio;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
struct
|
||||
{
|
||||
SDL_bool autoclose;
|
||||
FILE *fp;
|
||||
void *fp;
|
||||
} stdio;
|
||||
#endif
|
||||
|
||||
struct
|
||||
{
|
||||
Uint8 *base;
|
||||
|
@ -206,25 +205,15 @@ typedef struct SDL_RWops
|
|||
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);
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Use this function to create an SDL_RWops structure from a standard I/O file
|
||||
* pointer (stdio.h's `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 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
|
||||
|
@ -242,9 +231,7 @@ extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
|
|||
* \sa SDL_RWtell
|
||||
* \sa SDL_RWwrite
|
||||
*/
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
|
||||
SDL_bool autoclose);
|
||||
#endif
|
||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void *fp, SDL_bool autoclose);
|
||||
|
||||
/**
|
||||
* Use this function to prepare a read-write memory buffer for use with
|
||||
|
|
|
@ -55,7 +55,7 @@ SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(FILE *a, SDL_bool b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
|
||||
#else
|
||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
|
||||
#endif
|
||||
|
|
|
@ -386,8 +386,8 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
|
||||
Sint64 pos = ftell(context->hidden.stdio.fp);
|
||||
if (fseek((FILE *)context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
|
||||
Sint64 pos = ftell((FILE *)context->hidden.stdio.fp);
|
||||
if (pos < 0) {
|
||||
return SDL_SetError("Couldn't get stream offset");
|
||||
}
|
||||
|
@ -401,8 +401,8 @@ stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
|
|||
{
|
||||
size_t nread;
|
||||
|
||||
nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
|
||||
if (nread == 0 && ferror(context->hidden.stdio.fp)) {
|
||||
nread = fread(ptr, size, maxnum, (FILE *)context->hidden.stdio.fp);
|
||||
if (nread == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
SDL_Error(SDL_EFREAD);
|
||||
}
|
||||
return nread;
|
||||
|
@ -413,8 +413,8 @@ stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
|
|||
{
|
||||
size_t nwrote;
|
||||
|
||||
nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
|
||||
if (nwrote == 0 && ferror(context->hidden.stdio.fp)) {
|
||||
nwrote = fwrite(ptr, size, num, (FILE *)context->hidden.stdio.fp);
|
||||
if (nwrote == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||
SDL_Error(SDL_EFWRITE);
|
||||
}
|
||||
return nwrote;
|
||||
|
@ -427,7 +427,7 @@ stdio_close(SDL_RWops * context)
|
|||
if (context) {
|
||||
if (context->hidden.stdio.autoclose) {
|
||||
/* WARNING: Check the return value here! */
|
||||
if (fclose(context->hidden.stdio.fp) != 0) {
|
||||
if (fclose((FILE *)context->hidden.stdio.fp) != 0) {
|
||||
status = SDL_Error(SDL_EFWRITE);
|
||||
}
|
||||
}
|
||||
|
@ -616,7 +616,7 @@ SDL_RWFromFile(const char *file, const char *mode)
|
|||
|
||||
#ifdef HAVE_STDIO_H
|
||||
SDL_RWops *
|
||||
SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
|
||||
SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||
{
|
||||
SDL_RWops *rwops = NULL;
|
||||
|
||||
|
@ -635,7 +635,7 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
|
|||
}
|
||||
#else
|
||||
SDL_RWops *
|
||||
SDL_RWFromFP(void * fp, SDL_bool autoclose)
|
||||
SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||
{
|
||||
SDL_SetError("SDL not compiled with stdio support");
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue