Utility Functions
LZNV Tester CPP File Contents
Utility Functions
There are many utility functions in LZNV Tester CPP
These functions are designed to perform OS dependent jobs and may be of help.
wchar_t* _getLastErrorString()
{
static wchar_t message[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message, (sizeof(message) / sizeof(wchar_t)), NULL);
return message;
}
int compareFile(FILE* f1, FILE* f2)
{
if ((f1 == NULL) && (f2 == NULL)) {
return -1;
}
const int _max_N = 10240;
uint8_t pBuf1[_max_N + 1];
uint8_t pBuf2[_max_N + 1];
ASSERT(pBuf1 && pBuf2);
if (!pBuf1 || !pBuf2)
{
wprintf(L"\n Some memory issue!");
abort();
}
size_t read1 = 0;
size_t read2 = 0;
do
{
read1 = fread(pBuf1, 1, _max_N, f1);
read2 = fread(pBuf2, 1, _max_N, f2);
if (read1 != read2)
{
wprintf(L"\n Files have different size!");
return _LZNV_ERROR_COMPARE_RESULTS_DIFFERENT_SIZES; // or use your own non-zero value
}
if (memcmp(pBuf1, pBuf2, read1) != 0)
{
wprintf(L"\n Files have different content!");
return _LZNV_ERROR_COMPARE_RESULTS_DIFFERENT_CONTENT; // or use your own non-zero value
}
} while (read1 == _max_N);
return _LZNV_NO_ERROR_; // all OK
}