Commit ac24801d authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

Add a comment about byte order, change types to reduce casting and not

cast away constness.
parent 3475dcdb
...@@ -4064,44 +4064,46 @@ ULONG IEnumSTATSTGImpl_PopSearchNode( ...@@ -4064,44 +4064,46 @@ ULONG IEnumSTATSTGImpl_PopSearchNode(
/****************************************************************************** /******************************************************************************
** StorageUtl implementation ** 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(void* buffer, ULONG offset, WORD* value) void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value)
{ {
memcpy(value, (BYTE*)buffer+offset, sizeof(WORD)); memcpy(value, buffer+offset, sizeof(WORD));
} }
void StorageUtl_WriteWord(void* buffer, ULONG offset, WORD value) void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value)
{ {
memcpy((BYTE*)buffer+offset, &value, sizeof(WORD)); memcpy(buffer+offset, &value, sizeof(WORD));
} }
void StorageUtl_ReadDWord(void* buffer, ULONG offset, DWORD* value) void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value)
{ {
memcpy(value, (BYTE*)buffer+offset, sizeof(DWORD)); memcpy(value, buffer+offset, sizeof(DWORD));
} }
void StorageUtl_WriteDWord(void* buffer, ULONG offset, DWORD value) void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value)
{ {
memcpy((BYTE*)buffer+offset, &value, sizeof(DWORD)); memcpy(buffer+offset, &value, sizeof(DWORD));
} }
void StorageUtl_ReadGUID(void* buffer, ULONG offset, GUID* value) void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value)
{ {
StorageUtl_ReadDWord(buffer, offset, &(value->Data1)); StorageUtl_ReadDWord(buffer, offset, &(value->Data1));
StorageUtl_ReadWord(buffer, offset+4, &(value->Data2)); StorageUtl_ReadWord(buffer, offset+4, &(value->Data2));
StorageUtl_ReadWord(buffer, offset+6, &(value->Data3)); StorageUtl_ReadWord(buffer, offset+6, &(value->Data3));
memcpy(value->Data4, (BYTE*)buffer+offset+8, sizeof(value->Data4)); memcpy(value->Data4, buffer+offset+8, sizeof(value->Data4));
} }
void StorageUtl_WriteGUID(void* buffer, ULONG offset, GUID* value) void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value)
{ {
StorageUtl_WriteDWord(buffer, offset, value->Data1); StorageUtl_WriteDWord(buffer, offset, value->Data1);
StorageUtl_WriteWord(buffer, offset+4, value->Data2); StorageUtl_WriteWord(buffer, offset+4, value->Data2);
StorageUtl_WriteWord(buffer, offset+6, value->Data3); StorageUtl_WriteWord(buffer, offset+6, value->Data3);
memcpy((BYTE*)buffer+offset+8, value->Data4, sizeof(value->Data4)); memcpy(buffer+offset+8, value->Data4, sizeof(value->Data4));
} }
void StorageUtl_CopyPropertyToSTATSTG( void StorageUtl_CopyPropertyToSTATSTG(
...@@ -4789,7 +4791,7 @@ HRESULT SmallBlockChainStream_GetNextBlockInChain( ...@@ -4789,7 +4791,7 @@ HRESULT SmallBlockChainStream_GetNextBlockInChain(
if (success) if (success)
{ {
StorageUtl_ReadDWord(&buffer, 0, nextBlockInChain); StorageUtl_ReadDWord((BYTE *)&buffer, 0, nextBlockInChain);
return S_OK; return S_OK;
} }
...@@ -4816,7 +4818,7 @@ void SmallBlockChainStream_SetNextBlockInChain( ...@@ -4816,7 +4818,7 @@ void SmallBlockChainStream_SetNextBlockInChain(
offsetOfBlockInDepot.u.HighPart = 0; offsetOfBlockInDepot.u.HighPart = 0;
offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG); offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG);
StorageUtl_WriteDWord(&buffer, 0, nextBlock); StorageUtl_WriteDWord((BYTE *)&buffer, 0, nextBlock);
/* /*
* Read those bytes in the buffer from the small block file. * Read those bytes in the buffer from the small block file.
...@@ -4880,7 +4882,7 @@ ULONG SmallBlockChainStream_GetNextFreeBlock( ...@@ -4880,7 +4882,7 @@ ULONG SmallBlockChainStream_GetNextFreeBlock(
*/ */
if (success) if (success)
{ {
StorageUtl_ReadDWord(&buffer, 0, &nextBlockIndex); StorageUtl_ReadDWord((BYTE *)&buffer, 0, &nextBlockIndex);
if (nextBlockIndex != BLOCK_UNUSED) if (nextBlockIndex != BLOCK_UNUSED)
blockIndex++; blockIndex++;
......
...@@ -747,12 +747,12 @@ HRESULT WINAPI StgStreamImpl_Clone( ...@@ -747,12 +747,12 @@ HRESULT WINAPI StgStreamImpl_Clone(
* abstractions used to read values from file buffers without having to worry * abstractions used to read values from file buffers without having to worry
* about bit order * about bit order
*/ */
void StorageUtl_ReadWord(void* buffer, ULONG offset, WORD* value); void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
void StorageUtl_WriteWord(void* buffer, ULONG offset, WORD value); void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
void StorageUtl_ReadDWord(void* buffer, ULONG offset, DWORD* value); void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value);
void StorageUtl_WriteDWord(void* buffer, ULONG offset, DWORD value); void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value);
void StorageUtl_ReadGUID(void* buffer, ULONG offset, GUID* value); void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value);
void StorageUtl_WriteGUID(void* buffer, ULONG offset, GUID* value); void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value);
void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination, void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination,
StgProperty* source, StgProperty* source,
int statFlags); int statFlags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment