sdlUtf8strlcpy function
Copy an UTF-8 string.
This function copies up to dst_bytes
- 1 bytes from src
to dst
while
also ensuring that the string written to dst
does not end in a truncated
multi-byte sequence. Finally, it appends a null terminator.
src
and dst
must not overlap.
Note that unlike SDL_strlcpy(), this function returns the number of bytes
written, not the length of src
.
\param dst The destination buffer. Must not be NULL, and must not overlap
with src
.
\param src The null-terminated UTF-8 string to copy. Must not be NULL, and
must not overlap with dst
.
\param dst_bytes The length (in bytes) of the destination buffer. Must not
be 0.
\returns The number of bytes written, excluding the null terminator.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
\sa SDL_strlcpy
extern SDL_DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
Implementation
int sdlUtf8strlcpy(Pointer<NativeType> arg0, String? src, int dstBytes) {
final sdlUtf8strlcpyLookupFunction = libSdl3.lookupFunction<
Uint32 Function(
Pointer<NativeType> arg0, Pointer<Utf8> src, Uint32 dstBytes),
int Function(Pointer<NativeType> arg0, Pointer<Utf8> src,
int dstBytes)>('SDL_utf8strlcpy');
final srcPointer = src != null ? src.toNativeUtf8() : nullptr;
final result = sdlUtf8strlcpyLookupFunction(arg0, srcPointer, dstBytes);
calloc.free(srcPointer);
return result;
}