21 #include "android_assets.hpp" 27 Result AndroidAssetManager::readBinaryFile(
const char *pPath,
void **ppData,
size_t *pSize)
31 LOGE(
"Asset manager does not exist.");
32 return RESULT_ERROR_GENERIC;
35 AAsset *asset = AAssetManager_open(pManager, pPath, AASSET_MODE_BUFFER);
38 LOGE(
"AAssetManager_open() failed to load file: %s.", pPath);
39 return RESULT_ERROR_IO;
42 const void *buffer = AAsset_getBuffer(asset);
45 *pSize = AAsset_getLength(asset);
46 *ppData = malloc(*pSize);
49 LOGE(
"Failed to allocate buffer for asset: %s.", pPath);
51 return RESULT_ERROR_OUT_OF_MEMORY;
54 memcpy(*ppData, buffer, *pSize);
56 return RESULT_SUCCESS;
60 LOGE(
"Failed to obtain buffer for asset: %s.", pPath);
62 return RESULT_ERROR_IO;