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 ππ
π¦ where this page comes from
- debian bookworm: linuxcnc-uspace-dev 2.9.0~pre1+git20230208.f1270d6ed7-1+deb12u2 Β· GFDL-1.1-or-later
- debian trixie: linuxcnc-uspace-dev 1:2.9.4-2+deb13u1 Β· GFDL-1.1-or-later
- ubuntu questing: linuxcnc-uspace-dev 1:2.9.4-2ubuntu2
- ubuntu resolute: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- ubuntu stonking: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- Copyright (c) 2018 Jeff Epler
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms