stpcpy(9)
π stpcpy
okay so bestie, this is stpcpy from the kernel API manual, and she is that girl β but like, the risky kind of that girl. buckle up π
β¨ NAME β¨
stpcpy β copies a string from src to dest, and returns a pointer to the new end of dest, including src's %NUL-terminator. also likeβ¦ may overrun dest. π (yes that's in the official description, no I'm not being dramatic)
πΈ SYNOPSIS πΈ
char * stpcpy (char *__restrict__ dest , const char *__restrict__ src );
that's it. that's the whole signature, she's lowkey serving minimalism π
π¦ ARGUMENTS π¦
destβ pointer to the end of the string being copied into. she must be large enough to receive the whole copy, no exceptions, no vibes-based sizing πsrcβ pointer to the beginning of the string being copied from. she must not overlapdest, fr fr, don't even try it
π DESCRIPTION π
so here's the tea: stpcpy differs from strcpy in one key way β the return value is a pointer to the new NUL-terminating character in dest. (for strcpy, the return value is a pointer to the start of dest. yeah. different girl, different energy.)
this interface is considered unsafe because it doesn't perform bounds checking of the inputs. so like, no safety net, no vibe check on your buffer size, nothing. as such it's not recommended for usage β like genuinely, don't π«Ά
instead, its definition is provided in case the compiler lowers other libcalls to stpcpy. so she's basically here for the compiler's convenience, not yours. icon behavior honestly β¨
β οΈ real talk: no bounds checking means if your buffer's too small, dest gets overrun. that's not a bug note, that's just the whole personality of this function. respect it or get got π
π SEE ALSO π
kernel file ./lib/string.c β and literally all her friends:
strncasecmp(9), strcmp(9), strncmp(9), strchr(9), strchrnul(9), strnchrnul(9), strrchr(9), strnchr(9), strspn(9), strcspn(9), strpbrk(9), strsep(9), memset(9), memset16(9), memset32(9), memset64(9), memcpy(9), memmove(9), memcmp(9), bcmp(9), memscan(9), strstr(9), strnstr(9), memchr(9), memchr_inv(9)
likeβ¦ the whole group chat showed up π«Άπ
aaaand that's the page!! π this one came out of ./lib, dated October 2026 β stay safe out there with those buffers bestie, mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms