Define and use endian conversion macros for big-endian machines.
This commit is contained in:
parent
576aa4a6d8
commit
b99dfb0c1a
|
@ -4051,27 +4051,33 @@ StorageInternalImpl* StorageInternalImpl_Construct(
|
|||
|
||||
/******************************************************************************
|
||||
** StorageUtl implementation
|
||||
* FIXME: these should read and write in little-endian order on all
|
||||
* architectures, but right now just assume the host is little-endian.
|
||||
*/
|
||||
|
||||
void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value)
|
||||
{
|
||||
memcpy(value, buffer+offset, sizeof(WORD));
|
||||
WORD tmp;
|
||||
|
||||
memcpy(&tmp, buffer+offset, sizeof(WORD));
|
||||
*value = le16toh(tmp);
|
||||
}
|
||||
|
||||
void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value)
|
||||
{
|
||||
value = htole16(value);
|
||||
memcpy(buffer+offset, &value, sizeof(WORD));
|
||||
}
|
||||
|
||||
void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value)
|
||||
{
|
||||
memcpy(value, buffer+offset, sizeof(DWORD));
|
||||
DWORD tmp;
|
||||
|
||||
memcpy(&tmp, buffer+offset, sizeof(DWORD));
|
||||
*value = le32toh(tmp);
|
||||
}
|
||||
|
||||
void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value)
|
||||
{
|
||||
value = htole32(value);
|
||||
memcpy(buffer+offset, &value, sizeof(DWORD));
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "winbase.h"
|
||||
#include "winnt.h"
|
||||
#include "objbase.h"
|
||||
#include "winreg.h"
|
||||
#include "winternl.h"
|
||||
|
||||
/*
|
||||
* Definitions for the file format offsets.
|
||||
|
@ -524,10 +526,29 @@ StgStreamImpl* StgStreamImpl_Construct(
|
|||
ULONG ownerProperty);
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* The StorageUtl_ functions are miscelaneous utility functions. Most of which are
|
||||
* abstractions used to read values from file buffers without having to worry
|
||||
* about bit order
|
||||
/******************************************************************************
|
||||
* Endian conversion macros
|
||||
*/
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
|
||||
#define htole32(x) RtlUlongByteSwap(x)
|
||||
#define htole16(x) RtlUshortByteSwap(x)
|
||||
#define le32toh(x) RtlUlongByteSwap(x)
|
||||
#define le16toh(x) RtlUshortByteSwap(x)
|
||||
|
||||
#else
|
||||
|
||||
#define htole32(x) (x)
|
||||
#define htole16(x) (x)
|
||||
#define le32toh(x) (x)
|
||||
#define le16toh(x) (x)
|
||||
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* The StorageUtl_ functions are miscellaneous utility functions. Most of which
|
||||
* are abstractions used to read values from file buffers without having to
|
||||
* worry about bit order
|
||||
*/
|
||||
void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
|
||||
void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
|
||||
|
|
Loading…
Reference in New Issue