sdlStrdup function
Allocate a copy of a string.
This allocates enough space for a null-terminated copy of str
, using
SDL_malloc, and then makes a copy of the string into this space.
The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.
\param str the string to copy. \returns a pointer to the newly-allocated string.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
extern SDL_DECLSPEC SDL_MALLOC char * SDLCALL SDL_strdup(const char *str)
Implementation
Pointer<Int8> sdlStrdup(String? str) {
final sdlStrdupLookupFunction = libSdl3.lookupFunction<
Pointer<Int8> Function(Pointer<Utf8> str),
Pointer<Int8> Function(Pointer<Utf8> str)>('SDL_strdup');
final strPointer = str != null ? str.toNativeUtf8() : nullptr;
final result = sdlStrdupLookupFunction(strPointer);
calloc.free(strPointer);
return result;
}