mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-20 11:48:29 +00:00
Removed SDL_rwops.h dependency on stdio.h
This commit is contained in:
parent
34d538bd13
commit
fa3814ddf1
3 changed files with 15 additions and 28 deletions
|
@ -112,13 +112,12 @@ typedef struct SDL_RWops
|
||||||
} windowsio;
|
} windowsio;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STDIO_H
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
SDL_bool autoclose;
|
SDL_bool autoclose;
|
||||||
FILE *fp;
|
void *fp;
|
||||||
} stdio;
|
} stdio;
|
||||||
#endif
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Uint8 *base;
|
Uint8 *base;
|
||||||
|
@ -206,12 +205,6 @@ typedef struct SDL_RWops
|
||||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
|
||||||
const char *mode);
|
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
|
* 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 *`).
|
||||||
|
@ -220,10 +213,6 @@ extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
|
||||||
* application on that platform cannot be used by a dynamically linked
|
* application on that platform cannot be used by a dynamically linked
|
||||||
* library.
|
* 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,
|
* \param autoclose SDL_TRUE to close the `FILE*` when closing the SDL_RWops,
|
||||||
* SDL_FALSE to leave the `FILE*` open when the RWops is
|
* SDL_FALSE to leave the `FILE*` open when the RWops is
|
||||||
|
@ -242,9 +231,7 @@ extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
|
||||||
* \sa SDL_RWtell
|
* \sa SDL_RWtell
|
||||||
* \sa SDL_RWwrite
|
* \sa SDL_RWwrite
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
|
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void *fp, SDL_bool autoclose);
|
||||||
SDL_bool autoclose);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this function to prepare a read-write memory buffer for use with
|
* 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
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STDIO_H
|
#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
|
#else
|
||||||
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -386,8 +386,8 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
|
if (fseek((FILE *)context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
|
||||||
Sint64 pos = ftell(context->hidden.stdio.fp);
|
Sint64 pos = ftell((FILE *)context->hidden.stdio.fp);
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
return SDL_SetError("Couldn't get stream offset");
|
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;
|
size_t nread;
|
||||||
|
|
||||||
nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
|
nread = fread(ptr, size, maxnum, (FILE *)context->hidden.stdio.fp);
|
||||||
if (nread == 0 && ferror(context->hidden.stdio.fp)) {
|
if (nread == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||||
SDL_Error(SDL_EFREAD);
|
SDL_Error(SDL_EFREAD);
|
||||||
}
|
}
|
||||||
return nread;
|
return nread;
|
||||||
|
@ -413,8 +413,8 @@ stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
|
||||||
{
|
{
|
||||||
size_t nwrote;
|
size_t nwrote;
|
||||||
|
|
||||||
nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
|
nwrote = fwrite(ptr, size, num, (FILE *)context->hidden.stdio.fp);
|
||||||
if (nwrote == 0 && ferror(context->hidden.stdio.fp)) {
|
if (nwrote == 0 && ferror((FILE *)context->hidden.stdio.fp)) {
|
||||||
SDL_Error(SDL_EFWRITE);
|
SDL_Error(SDL_EFWRITE);
|
||||||
}
|
}
|
||||||
return nwrote;
|
return nwrote;
|
||||||
|
@ -427,7 +427,7 @@ stdio_close(SDL_RWops * context)
|
||||||
if (context) {
|
if (context) {
|
||||||
if (context->hidden.stdio.autoclose) {
|
if (context->hidden.stdio.autoclose) {
|
||||||
/* WARNING: Check the return value here! */
|
/* 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);
|
status = SDL_Error(SDL_EFWRITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -616,7 +616,7 @@ SDL_RWFromFile(const char *file, const char *mode)
|
||||||
|
|
||||||
#ifdef HAVE_STDIO_H
|
#ifdef HAVE_STDIO_H
|
||||||
SDL_RWops *
|
SDL_RWops *
|
||||||
SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
|
SDL_RWFromFP(void *fp, SDL_bool autoclose)
|
||||||
{
|
{
|
||||||
SDL_RWops *rwops = NULL;
|
SDL_RWops *rwops = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue