private unsafe NEOERR* csFileLoad(void* ctx, HDF* raw_hdf, STR* pFilename, STR** contents)
{
// Console.WriteLine("csFileLoad delegate called");
IntPtr buf = IntPtr.Zero;
try {
Hdf hdf = new Hdf(raw_hdf);
string filename = Marshal.PtrToStringAnsi((IntPtr)pFilename);
byte[] data = cur_delegate(hdf, filename);
byte[] end_null = new byte[] { 0 };
buf = NeoUtil.neo_malloc(data.Length + 1); // +1 so we can null terminate
Marshal.Copy(data, 0, buf, data.Length);
Marshal.Copy(end_null, 0, buf + data.Length, 1); // write the end_null
*contents = (STR*)buf;
} catch (Exception e) {
// Console.WriteLine("csFileLoad Thunk Exception + " + e);
// should return a neo error
if (buf != IntPtr.Zero) {
NeoUtil.neo_free(buf);
}
return NeoErr.nERR(e.ToString());
}
return (NEOERR*) IntPtr.Zero;
}