src/endian/SDL_endian.c
changeset 0 74212992fb08
child 252 e8157fcb3114
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/endian/SDL_endian.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,104 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* Functions for dynamically reading and writing endian-specific values */
    1.32 +
    1.33 +#include "SDL_endian.h"
    1.34 +
    1.35 +Uint16 SDL_ReadLE16 (SDL_RWops *src)
    1.36 +{
    1.37 +	Uint16 value;
    1.38 +
    1.39 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.40 +	return(SDL_SwapLE16(value));
    1.41 +}
    1.42 +Uint16 SDL_ReadBE16 (SDL_RWops *src)
    1.43 +{
    1.44 +	Uint16 value;
    1.45 +
    1.46 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.47 +	return(SDL_SwapBE16(value));
    1.48 +}
    1.49 +Uint32 SDL_ReadLE32 (SDL_RWops *src)
    1.50 +{
    1.51 +	Uint32 value;
    1.52 +
    1.53 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.54 +	return(SDL_SwapLE32(value));
    1.55 +}
    1.56 +Uint32 SDL_ReadBE32 (SDL_RWops *src)
    1.57 +{
    1.58 +	Uint32 value;
    1.59 +
    1.60 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.61 +	return(SDL_SwapBE32(value));
    1.62 +}
    1.63 +Uint64 SDL_ReadLE64 (SDL_RWops *src)
    1.64 +{
    1.65 +	Uint64 value;
    1.66 +
    1.67 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.68 +	return(SDL_SwapLE64(value));
    1.69 +}
    1.70 +Uint64 SDL_ReadBE64 (SDL_RWops *src)
    1.71 +{
    1.72 +	Uint64 value;
    1.73 +
    1.74 +	SDL_RWread(src, &value, (sizeof value), 1);
    1.75 +	return(SDL_SwapBE64(value));
    1.76 +}
    1.77 +
    1.78 +int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
    1.79 +{
    1.80 +	value = SDL_SwapLE16(value);
    1.81 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.82 +}
    1.83 +int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
    1.84 +{
    1.85 +	value = SDL_SwapBE16(value);
    1.86 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.87 +}
    1.88 +int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
    1.89 +{
    1.90 +	value = SDL_SwapLE32(value);
    1.91 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.92 +}
    1.93 +int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
    1.94 +{
    1.95 +	value = SDL_SwapBE32(value);
    1.96 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
    1.97 +}
    1.98 +int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
    1.99 +{
   1.100 +	value = SDL_SwapLE64(value);
   1.101 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   1.102 +}
   1.103 +int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
   1.104 +{
   1.105 +	value = SDL_SwapBE64(value);
   1.106 +	return(SDL_RWwrite(dst, &value, (sizeof value), 1));
   1.107 +}