sdlStrndup function

Pointer<Int8> sdlStrndup(
  1. String? str,
  2. int maxlen
)
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strndup(const char *str, size_t maxlen)

Implementation

Pointer<Int8> sdlStrndup(String? str, int maxlen) {
  final sdlStrndupLookupFunction = libSdl3.lookupFunction<
      Pointer<Int8> Function(Pointer<Utf8> str, Uint32 maxlen),
      Pointer<Int8> Function(Pointer<Utf8> str, int maxlen)>('SDL_strndup');
  final strPointer = str != null ? str.toNativeUtf8() : nullptr;
  final result = sdlStrndupLookupFunction(strPointer, maxlen);
  calloc.free(strPointer);
  return result;
}