Suppose there’s a third party library function CoolFunction(FILE* cfile)
taking a C style FILE*
, and there’s a file in the ResourceCache
that we can get at pretty easily in the form of an Urho3D::File*
. Is there any direct way to get at an underlying C style FILE
from the Urho3D::File*
?
I started to do it as below (which has bugs, but the approach is clear), then began to figure the approach I was using was probably pointless, since if I need to be copying array values like that, I would probably be better off to just create the FILE
directly from the name of the resource … but that way we can’t take advantage of the fact that the resource is loaded in the cache already. Any tips?
void CoolFunctionWrapper(Urho3D::File* ufile)
{
PODVector<unsigned char> buffer = ufile->ReadBuffer();
size_t n = (size_t)buffer.Size();
unsigned char* array = new unsigned char[n];
for (size_t i = 0; i < (size_t)buffer.Size(); ++i) {
array[i] = buffer[i];
}
FILE* cfile = fopen("tmp_name", "w");
fwrite(array, sizeof(unsigned char), n, cfile);
delete array;
CoolFunction(cfile);
}
(Also there is this File as an std::istream which looks relevant, but I still have to digest it.)