sdlStrlcpy function
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.1.3.
\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<NativeType> arg0, String? src, int maxlen) {
final sdlStrlcpyLookupFunction = libSdl3.lookupFunction<
Uint32 Function(
Pointer<NativeType> arg0, Pointer<Utf8> src, Uint32 maxlen),
int Function(Pointer<NativeType> arg0, Pointer<Utf8> src,
int maxlen)>('SDL_strlcpy');
final srcPointer = src != null ? src.toNativeUtf8() : nullptr;
final result = sdlStrlcpyLookupFunction(arg0, srcPointer, maxlen);
calloc.free(srcPointer);
return result;
}