author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 10 May 2002 09:25:25 +0000 | |
changeset 214 | 19846c18071b |
parent 201 | 7ea2ae5d1a6c |
child 321 | 50986060bee8 |
permissions | -rw-r--r-- |
177 | 1 |
/** |
2 |
* PhysicsFS; a portable, flexible file i/o abstraction. |
|
3 |
* |
|
4 |
* Documentation is in physfs.h. It's verbose, honest. :) |
|
5 |
* |
|
6 |
* Please see the file LICENSE in the source's root directory. |
|
7 |
* |
|
8 |
* This file written by Ryan C. Gordon. |
|
9 |
*/ |
|
10 |
||
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
201
diff
changeset
|
11 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
201
diff
changeset
|
12 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
201
diff
changeset
|
13 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
201
diff
changeset
|
14 |
|
177 | 15 |
#include <stdio.h> |
16 |
#include <stdlib.h> |
|
17 |
#include <assert.h> |
|
18 |
#include "physfs.h" |
|
19 |
||
20 |
/* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */ |
|
21 |
#define PHYSFS_LIL_ENDIAN 1234 |
|
22 |
#define PHYSFS_BIG_ENDIAN 4321 |
|
23 |
||
24 |
#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ |
|
25 |
(defined(__alpha__) || defined(__alpha)) || \ |
|
26 |
defined(__arm__) || \ |
|
27 |
(defined(__mips__) && defined(__MIPSEL__)) || \ |
|
28 |
defined(__SYMBIAN32__) || \ |
|
29 |
defined(__LITTLE_ENDIAN__) |
|
30 |
#define PHYSFS_BYTEORDER PHYSFS_LIL_ENDIAN |
|
31 |
#else |
|
32 |
#define PHYSFS_BYTEORDER PHYSFS_BIG_ENDIAN |
|
33 |
#endif |
|
34 |
||
35 |
||
36 |
/* The macros used to swap values */ |
|
37 |
/* Try to use superfast macros on systems that support them */ |
|
38 |
#ifdef linux |
|
39 |
#include <asm/byteorder.h> |
|
40 |
#ifdef __arch__swab16 |
|
41 |
#define PHYSFS_Swap16 __arch__swab16 |
|
42 |
#endif |
|
43 |
#ifdef __arch__swab32 |
|
44 |
#define PHYSFS_Swap32 __arch__swab32 |
|
45 |
#endif |
|
46 |
#endif /* linux */ |
|
201
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
47 |
|
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
48 |
#if (defined _MSC_VER) |
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
49 |
#define __inline__ __inline |
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
50 |
#endif |
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
51 |
|
177 | 52 |
#ifndef PHYSFS_Swap16 |
201
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
53 |
static __inline__ PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D) |
177 | 54 |
{ |
55 |
return((D<<8)|(D>>8)); |
|
56 |
} |
|
57 |
#endif |
|
58 |
#ifndef PHYSFS_Swap32 |
|
201
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
59 |
static __inline__ PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D) |
177 | 60 |
{ |
61 |
return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); |
|
62 |
} |
|
63 |
#endif |
|
64 |
#ifndef PHYSFS_NO_64BIT_SUPPORT |
|
65 |
#ifndef PHYSFS_Swap64 |
|
201
7ea2ae5d1a6c
Patched to stop -ansi bitching.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
66 |
static __inline__ PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) { |
177 | 67 |
PHYSFS_uint32 hi, lo; |
68 |
||
69 |
/* Separate into high and low 32-bit values and swap them */ |
|
70 |
lo = (PHYSFS_uint32)(val&0xFFFFFFFF); |
|
71 |
val >>= 32; |
|
72 |
hi = (PHYSFS_uint32)(val&0xFFFFFFFF); |
|
73 |
val = PHYSFS_Swap32(lo); |
|
74 |
val <<= 32; |
|
75 |
val |= PHYSFS_Swap32(hi); |
|
76 |
return(val); |
|
77 |
} |
|
78 |
#endif |
|
79 |
#else |
|
80 |
#ifndef PHYSFS_Swap64 |
|
81 |
/* This is mainly to keep compilers from complaining in PHYSFS code. |
|
82 |
If there is no real 64-bit datatype, then compilers will complain about |
|
83 |
the fake 64-bit datatype that PHYSFS provides when it compiles user code. |
|
84 |
*/ |
|
85 |
#define PHYSFS_Swap64(X) (X) |
|
86 |
#endif |
|
87 |
#endif /* PHYSFS_NO_64BIT_SUPPORT */ |
|
88 |
||
89 |
||
90 |
/* Byteswap item from the specified endianness to the native endianness */ |
|
91 |
#if PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN |
|
92 |
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return(x); } |
|
93 |
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return(x); } |
|
94 |
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return(x); } |
|
95 |
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return(x); } |
|
96 |
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return(x); } |
|
97 |
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return(x); } |
|
98 |
||
99 |
PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return(PHYSFS_Swap16(x)); } |
|
100 |
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return(PHYSFS_Swap16(x)); } |
|
101 |
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return(PHYSFS_Swap32(x)); } |
|
102 |
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return(PHYSFS_Swap32(x)); } |
|
103 |
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(PHYSFS_Swap64(x)); } |
|
104 |
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(PHYSFS_Swap64(x)); } |
|
105 |
#else |
|
106 |
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return(PHYSFS_Swap16(x)); } |
|
107 |
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return(PHYSFS_Swap16(x)); } |
|
108 |
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return(PHYSFS_Swap32(x)); } |
|
109 |
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return(PHYSFS_Swap32(x)); } |
|
110 |
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return(PHYSFS_Swap64(x)); } |
|
111 |
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return(PHYSFS_Swap64(x)); } |
|
112 |
||
113 |
PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return(x); } |
|
114 |
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return(x); } |
|
115 |
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return(x); } |
|
116 |
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return(x); } |
|
117 |
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(x); } |
|
118 |
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(x); } |
|
119 |
#endif |
|
120 |
||
121 |
/* end of physfs_byteorder.c ... */ |
|
122 |