#include <string.h>
#if defined(CAFE) || defined(NN_PLATFORM_CTR)
#endif
static UniquePtr<unsigned char[]> g_olddata;
static size_t g_olddata_size;
static UniquePtr<unsigned char[]> g_newdata;
static size_t g_newdata_size;
static ReallocOutputStream::UniquePtrType g_patchdata;
static size_t g_patchdata_size;
static bool SetupOldData() {
g_olddata.reset(new(std::nothrow) unsigned char[1024 * 128]);
if (!g_olddata) return false;
for (size_t i = 0; i < 1024 * 128; ++i) {
g_olddata[i] = static_cast<unsigned char>(i % 256);
}
g_olddata_size = 1024 * 128;
return true;
}
static bool SetupNewData() {
g_newdata.reset(new(std::nothrow) unsigned char[1024 * 1024]);
if (!g_newdata) return false;
for (size_t i = 0; i < 1024 * 1024; ++i) {
g_newdata[i] = static_cast<unsigned char>(255 - i % 256);
}
g_newdata_size = 1024 * 1024;
return true;
}
static bool MakeBsDiffZ() {
ReallocOutputStream ostr;
g_olddata.get(), g_olddata_size, g_newdata.get(), g_newdata_size);
g_patchdata_size = ostr.Release(&g_patchdata);
return true;
} else {
return false;
}
}
static bool ApplyBsPatchZ() {
ReallocOutputStream ostr;
g_olddata.get(), g_olddata_size, g_patchdata.get(), g_patchdata_size);
ReallocOutputStream::UniquePtrType result;
size_t resultSize = ostr.Release(&result);
if (resultSize == g_newdata_size &&
memcmp(g_newdata.get(), result.get(), resultSize) == 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}
#if defined(CAFE) || defined(NN_PLATFORM_CTR)
#ifdef NLIB_HAS_VIRTUALMEMORY
extern "C" const NMallocSettings g_nmalloc_settings = { NULL, 1024 * 1024 * 16, 0 };
#else
const size_t heapmem_size = 1024 * 1024 * 16;
extern "C" const NMallocSettings g_nmalloc_settings = { heapmem, heapmem_size, 0 };
#endif
#endif
bool SampleMain(int, char**) {
return SetupOldData() && SetupNewData() && MakeBsDiffZ() && ApplyBsPatchZ();
}
NLIB_MAINFUNC