SDL_iconv(3)
π SDL_iconv(3) β the SDL3 FUNCTIONS era π
okay bestie, sit DOWN, because this is the one that takes text from one encoding and yeets it into another, reading from a buffer and writing to a buffer. it's giving translator energy. it's giving main character. π¦
β¨ NAME β¨
SDL_iconv β This function converts text between encodings, reading from and writing to a buffer.
π SYNOPSIS π
#include <SDL3/SDL_stdinc.h>
size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf,
size_t *inbytesleft, char **outbuf,
size_t *outbytesleft);
#define SDL_ICONV_ERROR (size_t)-1 /**< Generic error. Check SDL_GetError()? */
#define SDL_ICONV_E2BIG (size_t)-2 /**< Output buffer was too small. */
#define SDL_ICONV_EILSEQ (size_t)-3 /**< Invalid input sequence was encountered. */
#define SDL_ICONV_EINVAL (size_t)-4 /**< Incomplete input sequence was encountered. */
those four #defines? iconic. keep them. they're your little error-code girlies and you will be seeing them again in a sec. π
πΈ DESCRIPTION πΈ
So here's the tea: on success it returns the number of successful conversions. On error, it hands you back one of the moody little codes:
SDL_ICONV_E2BIGgets returned when the output buffer is too small π«SDL_ICONV_EILSEQgets returned when an invalid input sequence is encountered πSDL_ICONV_EINVALgets returned when an incomplete input sequence is encountered π
And then β plot twist β the pointers get mutated on exit. Not me gaslighting you, it literally rewrites your variables:
inbufwill point to the beginning of the next multibyte sequence. On error, this is the location of the problematic input sequence. On success, this is the end of the input sequence.inbytesleftwill be set to the number of bytes left to convert, which will be 0 on success.outbufwill point to the location where to store the next output byte.outbytesleftwill be set to the number of bytes left in the output buffer.
likeβ¦ it's a whole glow-up for your pointers, fr fr. β¨
π FUNCTION PARAMETERS π
cdβ The character set conversion context, created inSDL_iconv_open(). your little conversion passport πinbufβ Address of variable that points to the first character of the input sequence.inbytesleftβ The number of bytes in the input buffer.outbufβ Address of variable that points to the output buffer.outbytesleftβ The number of bytes in the output buffer.
β RETURN VALUE β
Returns the number of conversions on success, or a negative error code. that's it. that's the whole vibe check. π
π₯ THREAD SAFETY π₯
Do not use the same SDL_iconv_t from two threads at once.
bestie I am BEGGING you. one SDL_iconv_t per thread. share it and you're gonna have a bad time. no cap. π
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on anything older, this is not the moment, hun. π§
π SEE ALSO π
the whole iconv friend group. go say hi. π«Ά
and that's the page, bestie!! this lil masterpiece came to you from Simple Directmedia Layer, version SDL 3.4.18, dated SDL_iconv(3) β slay, stay encoded, and always free your SDL_iconv_t πβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms