src/physfs_byteorder.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 21 Aug 2010 14:30:52 -0400
changeset 1101 6dd9d71b8e3f
parent 1100 f90724e3b4c6
child 1129 d81afe4b0a97
permissions -rw-r--r--
Replaced cut-and-paste byteswap i/o codepile with macros.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * PhysicsFS; a portable, flexible file i/o abstraction.
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Documentation is in physfs.h. It's verbose, honest.  :)
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     6
 * Please see the file LICENSE.txt in the source's root directory.
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 *  This file written by Ryan C. Gordon.
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 */
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <stdio.h>
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <stdlib.h>
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    13
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    14
#define __PHYSICSFS_INTERNAL__
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    15
#include "physfs_internal.h"
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#ifndef PHYSFS_Swap16
1100
f90724e3b4c6 Get rid of __inline__, just make sure "inline" is defined sanely instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
    18
static inline PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D)
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    20
    return ((D<<8)|(D>>8));
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
}
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#endif
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#ifndef PHYSFS_Swap32
1100
f90724e3b4c6 Get rid of __inline__, just make sure "inline" is defined sanely instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
    24
static inline PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D)
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    26
    return ((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
}
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#endif
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#ifndef PHYSFS_NO_64BIT_SUPPORT
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#ifndef PHYSFS_Swap64
1100
f90724e3b4c6 Get rid of __inline__, just make sure "inline" is defined sanely instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
    31
static inline PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    32
    PHYSFS_uint32 hi, lo;
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    34
    /* Separate into high and low 32-bit values and swap them */
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    35
    lo = (PHYSFS_uint32)(val&0xFFFFFFFF);
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    36
    val >>= 32;
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    37
    hi = (PHYSFS_uint32)(val&0xFFFFFFFF);
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    38
    val = PHYSFS_Swap32(lo);
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    39
    val <<= 32;
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    40
    val |= PHYSFS_Swap32(hi);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    41
    return val;
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
}
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#endif
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#else
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#ifndef PHYSFS_Swap64
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
/* This is mainly to keep compilers from complaining in PHYSFS code.
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
   If there is no real 64-bit datatype, then compilers will complain about
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
   the fake 64-bit datatype that PHYSFS provides when it compiles user code.
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
*/
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    50
#define PHYSFS_Swap64(X)    (X)
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
#endif
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
#endif /* PHYSFS_NO_64BIT_SUPPORT */
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
/* Byteswap item from the specified endianness to the native endianness */
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
#if PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    57
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    58
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    59
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    60
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    61
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    62
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return x; }
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    64
PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return PHYSFS_Swap16(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    65
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return PHYSFS_Swap16(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    66
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return PHYSFS_Swap32(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    67
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return PHYSFS_Swap32(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    68
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return PHYSFS_Swap64(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    69
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return PHYSFS_Swap64(x); }
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
#else
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    71
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return PHYSFS_Swap16(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    72
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return PHYSFS_Swap16(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    73
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return PHYSFS_Swap32(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    74
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return PHYSFS_Swap32(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    75
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return PHYSFS_Swap64(x); }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    76
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return PHYSFS_Swap64(x); }
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    78
PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    79
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    80
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    81
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    82
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return x; }
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    83
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return x; }
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
#endif
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    86
static inline int readAll(PHYSFS_File *file, void *val, const size_t len)
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    87
{
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    88
    return (PHYSFS_readBytes(file, val, len) == len);
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    89
} /* readAll */
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    90
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    91
#define PHYSFS_BYTEORDER_READ(datatype, swaptype) \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    92
    int PHYSFS_read##swaptype(PHYSFS_File *file, PHYSFS_##datatype *val) { \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    93
        PHYSFS_##datatype in; \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    94
        BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0); \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    95
        BAIL_IF_MACRO(!readAll(file, &in, sizeof (in)), NULL, 0); \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    96
        *val = PHYSFS_swap##swaptype(in); \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    97
        return 1; \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
    98
    }
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
    99
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   100
PHYSFS_BYTEORDER_READ(sint16, SLE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   101
PHYSFS_BYTEORDER_READ(uint16, ULE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   102
PHYSFS_BYTEORDER_READ(sint16, SBE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   103
PHYSFS_BYTEORDER_READ(uint16, UBE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   104
PHYSFS_BYTEORDER_READ(sint32, SLE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   105
PHYSFS_BYTEORDER_READ(uint32, ULE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   106
PHYSFS_BYTEORDER_READ(sint32, SBE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   107
PHYSFS_BYTEORDER_READ(uint32, UBE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   108
PHYSFS_BYTEORDER_READ(sint64, SLE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   109
PHYSFS_BYTEORDER_READ(uint64, ULE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   110
PHYSFS_BYTEORDER_READ(sint64, SBE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   111
PHYSFS_BYTEORDER_READ(uint64, UBE64)
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   112
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   113
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   114
static inline int writeAll(PHYSFS_File *f, const void *val, const size_t len)
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   115
{
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   116
    return (PHYSFS_writeBytes(f, val, len) == len);
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   117
} /* writeAll */
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   118
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   119
#define PHYSFS_BYTEORDER_WRITE(datatype, swaptype) \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   120
    int PHYSFS_write##swaptype(PHYSFS_File *file, PHYSFS_##datatype val) { \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   121
        const PHYSFS_##datatype out = PHYSFS_swap##swaptype(val); \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   122
        BAIL_IF_MACRO(!writeAll(file, &out, sizeof (out)), NULL, 0); \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   123
        return 1; \
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   124
    }
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   125
1101
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   126
PHYSFS_BYTEORDER_WRITE(sint16, SLE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   127
PHYSFS_BYTEORDER_WRITE(uint16, ULE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   128
PHYSFS_BYTEORDER_WRITE(sint16, SBE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   129
PHYSFS_BYTEORDER_WRITE(uint16, UBE16)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   130
PHYSFS_BYTEORDER_WRITE(sint32, SLE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   131
PHYSFS_BYTEORDER_WRITE(uint32, ULE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   132
PHYSFS_BYTEORDER_WRITE(sint32, SBE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   133
PHYSFS_BYTEORDER_WRITE(uint32, UBE32)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   134
PHYSFS_BYTEORDER_WRITE(sint64, SLE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   135
PHYSFS_BYTEORDER_WRITE(uint64, ULE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   136
PHYSFS_BYTEORDER_WRITE(sint64, SBE64)
6dd9d71b8e3f Replaced cut-and-paste byteswap i/o codepile with macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 1100
diff changeset
   137
PHYSFS_BYTEORDER_WRITE(uint64, UBE64)
321
50986060bee8 Added PHYSFS_(read|write)[SU][BL]E(16|32|64).
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   138
177
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
/* end of physfs_byteorder.c ... */
9aaf01f4b8ec Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140