sdlLoadFile function

Pointer<NativeType> sdlLoadFile(
  1. String? file,
  2. Pointer<Uint32> datasize
)

Load all the data from a file path.

The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize.

The data should be freed with SDL_free().

Prior to SDL 2.0.10, this function was a macro wrapping around SDL_LoadFile_RW.

\param file the path to read all available data from \param datasize if not NULL, will store the number of bytes read \returns the data, or NULL if there was an error.

\since This function is available since SDL 2.0.10.

extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize)

Implementation

Pointer<NativeType> sdlLoadFile(String? file, Pointer<Uint32> datasize) {
  final sdlLoadFileLookupFunction = libSdl2.lookupFunction<
      Pointer<NativeType> Function(
          Pointer<Utf8> file, Pointer<Uint32> datasize),
      Pointer<NativeType> Function(
          Pointer<Utf8> file, Pointer<Uint32> datasize)>('SDL_LoadFile');
  final filePointer = file != null ? file.toNativeUtf8() : nullptr;
  final result = sdlLoadFileLookupFunction(filePointer, datasize);
  calloc.free(filePointer);
  return result;
}