2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2004 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 /* Functions for dynamically reading and writing endian-specific values */
30 #include "SDL_endian.h"
32 Uint16 SDL_ReadLE16 (SDL_RWops *src)
36 SDL_RWread(src, &value, (sizeof value), 1);
37 return(SDL_SwapLE16(value));
39 Uint16 SDL_ReadBE16 (SDL_RWops *src)
43 SDL_RWread(src, &value, (sizeof value), 1);
44 return(SDL_SwapBE16(value));
46 Uint32 SDL_ReadLE32 (SDL_RWops *src)
50 SDL_RWread(src, &value, (sizeof value), 1);
51 return(SDL_SwapLE32(value));
53 Uint32 SDL_ReadBE32 (SDL_RWops *src)
57 SDL_RWread(src, &value, (sizeof value), 1);
58 return(SDL_SwapBE32(value));
60 Uint64 SDL_ReadLE64 (SDL_RWops *src)
64 SDL_RWread(src, &value, (sizeof value), 1);
65 return(SDL_SwapLE64(value));
67 Uint64 SDL_ReadBE64 (SDL_RWops *src)
71 SDL_RWread(src, &value, (sizeof value), 1);
72 return(SDL_SwapBE64(value));
75 int SDL_WriteLE16 (SDL_RWops *dst, Uint16 value)
77 value = SDL_SwapLE16(value);
78 return(SDL_RWwrite(dst, &value, (sizeof value), 1));
80 int SDL_WriteBE16 (SDL_RWops *dst, Uint16 value)
82 value = SDL_SwapBE16(value);
83 return(SDL_RWwrite(dst, &value, (sizeof value), 1));
85 int SDL_WriteLE32 (SDL_RWops *dst, Uint32 value)
87 value = SDL_SwapLE32(value);
88 return(SDL_RWwrite(dst, &value, (sizeof value), 1));
90 int SDL_WriteBE32 (SDL_RWops *dst, Uint32 value)
92 value = SDL_SwapBE32(value);
93 return(SDL_RWwrite(dst, &value, (sizeof value), 1));
95 int SDL_WriteLE64 (SDL_RWops *dst, Uint64 value)
97 value = SDL_SwapLE64(value);
98 return(SDL_RWwrite(dst, &value, (sizeof value), 1));
100 int SDL_WriteBE64 (SDL_RWops *dst, Uint64 value)
102 value = SDL_SwapBE64(value);
103 return(SDL_RWwrite(dst, &value, (sizeof value), 1));