src/file/SDL_rwops.c
changeset 1354 22f39393668a
parent 1338 604d73db6802
child 1358 c71e05b4dc2e
     1.1 --- a/src/file/SDL_rwops.c	Thu Feb 09 09:07:13 2006 +0000
     1.2 +++ b/src/file/SDL_rwops.c	Thu Feb 09 09:38:05 2006 +0000
     1.3 @@ -24,11 +24,11 @@
     1.4     data sources.  It can easily be extended to files, memory, etc.
     1.5  */
     1.6  
     1.7 -#include "SDL_stdlib.h"
     1.8 -#include "SDL_string.h"
     1.9  #include "SDL_error.h"
    1.10 +#include "SDL_endian.h"
    1.11  #include "SDL_rwops.h"
    1.12  
    1.13 +
    1.14  #ifdef HAVE_STDIO_H
    1.15  
    1.16  /* Functions to read/write stdio file pointers */
    1.17 @@ -303,3 +303,79 @@
    1.18  {
    1.19  	SDL_free(area);
    1.20  }
    1.21 +
    1.22 +/* Functions for dynamically reading and writing endian-specific values */
    1.23 +
    1.24 +Uint16 SDL_ReadLE16 (SDL_RWops *src)
    1.25 +{
    1.26 +	Uint16 value;
    1.27 +
    1.28 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.29 +	return(SDL_SwapLE16(value));
    1.30 +}
    1.31 +Uint16 SDL_ReadBE16 (SDL_RWops *src)
    1.32 +{
    1.33 +	Uint16 value;
    1.34 +
    1.35 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.36 +	return(SDL_SwapBE16(value));
    1.37 +}
    1.38 +Uint32 SDL_ReadLE32 (SDL_RWops *src)
    1.39 +{
    1.40 +	Uint32 value;
    1.41 +
    1.42 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.43 +	return(SDL_SwapLE32(value));
    1.44 +}
    1.45 +Uint32 SDL_ReadBE32 (SDL_RWops *src)
    1.46 +{
    1.47 +	Uint32 value;
    1.48 +
    1.49 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.50 +	return(SDL_SwapBE32(value));
    1.51 +}
    1.52 +Uint64 SDL_ReadLE64 (SDL_RWops *src)
    1.53 +{
    1.54 +	Uint64 value;
    1.55 +
    1.56 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.57 +	return(SDL_SwapLE64(value));
    1.58 +}
    1.59 +Uint64 SDL_ReadBE64 (SDL_RWops *src)
    1.60 +{
    1.61 +	Uint64 value;
    1.62 +
    1.63 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.64 +	return(SDL_SwapBE64(value));
    1.65 +}
    1.66 +
    1.67 +int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
    1.68 +{
    1.69 +	value = SDL_SwapLE16(value);
    1.70 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.71 +}
    1.72 +int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
    1.73 +{
    1.74 +	value = SDL_SwapBE16(value);
    1.75 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.76 +}
    1.77 +int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
    1.78 +{
    1.79 +	value = SDL_SwapLE32(value);
    1.80 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.81 +}
    1.82 +int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
    1.83 +{
    1.84 +	value = SDL_SwapBE32(value);
    1.85 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.86 +}
    1.87 +int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
    1.88 +{
    1.89 +	value = SDL_SwapLE64(value);
    1.90 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.91 +}
    1.92 +int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
    1.93 +{
    1.94 +	value = SDL_SwapBE64(value);
    1.95 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.96 +}