physfs_byteorder.c
changeset 578 bff1af8455ca
parent 566 1e640d4acab9
child 629 b01a59827192
child 704 f3c79a07201f
equal deleted inserted replaced
577:90a06832dcf3 578:bff1af8455ca
    52 #endif
    52 #endif
    53 
    53 
    54 #ifndef PHYSFS_Swap16
    54 #ifndef PHYSFS_Swap16
    55 static __inline__ PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D)
    55 static __inline__ PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D)
    56 {
    56 {
    57 	return((D<<8)|(D>>8));
    57     return((D<<8)|(D>>8));
    58 }
    58 }
    59 #endif
    59 #endif
    60 #ifndef PHYSFS_Swap32
    60 #ifndef PHYSFS_Swap32
    61 static __inline__ PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D)
    61 static __inline__ PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D)
    62 {
    62 {
    63 	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
    63     return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
    64 }
    64 }
    65 #endif
    65 #endif
    66 #ifndef PHYSFS_NO_64BIT_SUPPORT
    66 #ifndef PHYSFS_NO_64BIT_SUPPORT
    67 #ifndef PHYSFS_Swap64
    67 #ifndef PHYSFS_Swap64
    68 static __inline__ PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) {
    68 static __inline__ PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) {
    69 	PHYSFS_uint32 hi, lo;
    69     PHYSFS_uint32 hi, lo;
    70 
    70 
    71 	/* Separate into high and low 32-bit values and swap them */
    71     /* Separate into high and low 32-bit values and swap them */
    72 	lo = (PHYSFS_uint32)(val&0xFFFFFFFF);
    72     lo = (PHYSFS_uint32)(val&0xFFFFFFFF);
    73 	val >>= 32;
    73     val >>= 32;
    74 	hi = (PHYSFS_uint32)(val&0xFFFFFFFF);
    74     hi = (PHYSFS_uint32)(val&0xFFFFFFFF);
    75 	val = PHYSFS_Swap32(lo);
    75     val = PHYSFS_Swap32(lo);
    76 	val <<= 32;
    76     val <<= 32;
    77 	val |= PHYSFS_Swap32(hi);
    77     val |= PHYSFS_Swap32(hi);
    78 	return(val);
    78     return(val);
    79 }
    79 }
    80 #endif
    80 #endif
    81 #else
    81 #else
    82 #ifndef PHYSFS_Swap64
    82 #ifndef PHYSFS_Swap64
    83 /* This is mainly to keep compilers from complaining in PHYSFS code.
    83 /* This is mainly to keep compilers from complaining in PHYSFS code.
    84    If there is no real 64-bit datatype, then compilers will complain about
    84    If there is no real 64-bit datatype, then compilers will complain about
    85    the fake 64-bit datatype that PHYSFS provides when it compiles user code.
    85    the fake 64-bit datatype that PHYSFS provides when it compiles user code.
    86 */
    86 */
    87 #define PHYSFS_Swap64(X)	(X)
    87 #define PHYSFS_Swap64(X)    (X)
    88 #endif
    88 #endif
    89 #endif /* PHYSFS_NO_64BIT_SUPPORT */
    89 #endif /* PHYSFS_NO_64BIT_SUPPORT */
    90 
    90 
    91 
    91 
    92 /* Byteswap item from the specified endianness to the native endianness */
    92 /* Byteswap item from the specified endianness to the native endianness */