SDL_utf8strlcpy(3)

SDL_utf8strlcpy πŸ’–

okay bestie, this is a SDL3 FUNCTIONS page, and it's genuinely one of the good ones. sit down, hydrate, let's go ✨


✨ NAME ✨

SDL_utf8strlcpy β€” copy a UTF-8 string, but make it safe πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_stdinc.h>

size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);

✨ DESCRIPTION ✨

so the way this works is: it copies up to dst_bytes - 1 bytes from src to dst, and it also makes sure the string it writes into dst doesn't end in a truncated multi-byte sequence. like, no half-characters left dangling, we don't do that here 🫢. then it appends a null terminator, as one does.

src and dst must not overlap. no cap, they just can't.

heads up bestie: unlike SDL_strlcpy(), this function returns the number of bytes written, not the length of src. it's giving "similar name, different vibe" 😭

✨ FUNCTION PARAMETERS ✨

  • dst β€” the destination buffer. must not be NULL, and must not overlap with src. πŸ’€
  • src β€” the null-terminated UTF-8 string you're copying. must not be NULL, and must not overlap with dst. πŸ¦‹
  • dst_bytes β€” the length (in bytes) of the destination buffer. must not be 0. zero is not the move, babe.

✨ RETURN VALUE ✨

returns the number of bytes written, excluding the null terminator. that's it, that's the tea πŸ“


✨ THREAD SAFETY ✨

it is safe to call this function from any thread. queen behavior, honestly πŸ‘‘


✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. if you're on something older, it's simply not there, sorry babe πŸ™ˆ


✨ SEE ALSO ✨


Simple Directmedia Layer πŸŽ€ SDL 3.4.18 β€” mwah, that's the whole page, go forth and copy your UTF-8 strings responsibly, bestie πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from