funct(3rtapi)

πŸ’– funct(3rtapi) β€” bestie's guide to RTAPI string stuff πŸ’–

okay so like. this is a page from the RTAPI manual, and it's all about the string manipulation functions. yes, the whole page is literally called rtapi_strlcpy but it's secretly a lil squad of four functions who always show up together. group chat energy. let's go πŸ¦‹


✨ NAME ✨

rtapi_strlcpy β€” RTAPI string manipulation functions


✨ SYNTAX ✨

#include <rtapi_string.h>

size_t rtapi_strlcpy(char *dst, const char *src, size_t sz); #define
       rtapi_strxcpy(dst, src) ...  size_t rtapi_strlcat(char *dst,
       const char *src, size_t sz); #define rtapi_strxcat(dst, src) ...

like, copy it exactly bestie, i'm not touching a single character of this πŸ’…


✨ DESCRIPTION ✨

πŸŽ€ rtapi_strlcpy

she will copy at most 'sz' chars from 'src' to 'dst'. that's it, that's the vibe.

and the important part: she always leaves 'dst' NUL-terminated β€” except if sz is 0. (sz = 0 is giving nothing-to-work-with energy, okay? don't be shocked.) 🫢

πŸŽ€ rtapi_strxcpy(dst, src)

this one is the responsible friend. she checks that dst is an array with known size, and then calls rtapi_strlcpy(dst, src, sizeof(dst)).

but bestie… if it is not an array with a known size? it's a (possibly cryptic!) syntax error. like the compiler is gonna yell at you in a language you don't speak. 😭 iconic behavior honestly.

πŸŽ€ rtapi_strlcat

she appends characters from 'src' to 'dst', and she stops when either the end of 'src' is reached, or 'dst' uses 'sz' bytes of storage including the trialing nul.

(yes the page says "trialing", i'm quoting it verbatim, i do not make the rules πŸ’€)

πŸŽ€ rtapi_strxcat(dst, src)

same deal as her sister: she checks that dst is an array with known size and calls rtapi_strlcat(dst, src, sizeof(dst)).

and again β€” if it's not an array with a known size, it's a (possibly cryptic!) syntax error. no cap. πŸ™ˆ


✨ RETURN VALUE ✨

she returns the total length of the string that strlcpy or strlcat tried to create. for strlcpy() that means the length of src.

and here's the tea, bestie: if the return value is greater than or equal to sz, the result was truncated. so like, if the number coming back is too big, you got cut off. vibe check failed. ⭐


✨ SEE ALSO ✨


and that's the whole page, you ate it πŸ“

the source of all this wisdom: the LinuxCNC Documentation, and the page lives at funct(3rtapi) in the RTAPI manual.** go forth and never overflow a buffer again, queen πŸ‘‘πŸ’œ