sdlStrlcpy function stdinc
Copy a string.
This function copies up to maxlen - 1 characters from src to dst,
then appends a null terminator.
If maxlen is 0, no characters are copied and no null terminator is
written.
If you want to copy an UTF-8 string but need to ensure that multi-byte sequences are not truncated, consider using SDL_utf8strlcpy().
\param dst The destination buffer. Must not be NULL, and must not overlap
with src.
\param src The null-terminated string to copy. Must not be NULL, and must
not overlap with dst.
\param maxlen The length (in characters) of the destination buffer.
\returns the length (in characters, excluding the null terminator) of
src.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.2.0.
\sa SDL_strlcat \sa SDL_utf8strlcpy
extern SDL_DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
Implementation
int sdlStrlcpy(Pointer<Int8> dst, String? src, int maxlen) {
final sdlStrlcpyLookupFunction = _libSdl
.lookupFunction<
Uint32 Function(Pointer<Int8> dst, Pointer<Utf8> src, Uint32 maxlen),
int Function(Pointer<Int8> dst, Pointer<Utf8> src, int maxlen)
>('SDL_strlcpy');
final srcPointer = src != null ? src.toNativeUtf8() : nullptr;
final result = sdlStrlcpyLookupFunction(dst, srcPointer, maxlen);
calloc.free(srcPointer);
return result;
}