strscpy(9)

πŸ“¦
version 6.20 Β· 3 versions
, in arch rolling, nixpkgs unstable

πŸ’– strscpy πŸ’–

okay bestie, gather round, we're talking about strscpy(9) from the Kernel Developer's Manual. yes this is kernel-land. yes it's giving serious business. but it's also giving "copying strings without setting your computer on fire", so honestly? iconic. πŸŽ€


✨ NAME ✨

strscpy β€” string safe^W truncate copy

(not the manpage doing a little backspace joke on itself 😭 the "safe" part gets deleted in real time. we love a self-aware function. πŸ’…)


πŸ“š LIBRARY πŸ“š

Linux kernel

no libc invite for this one, periodt. it lives in the kernel.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <linux/string.h>

ssize_t strscpy(size_t dsize;
                char dst[restrict dsize], const char *restrict src,
                size_t dsize);

yes you saw dsize two times. that's literally what's written, bestie. we don't edit the sacred text. πŸ’œ


🌸 DESCRIPTION 🌸

so here's the vibe: this function copies the string that src points at, into a string sitting in the buffer that dst points at.

and if the string doesn't fit in the buffer? it gets truncated. no crash, no drama, just a little snip. βœ‚οΈβœ¨


⭐ RETURN VALUE ⭐

  • On success β€” you get back the length of the new string. slay.
  • On error β€” you get back a negative error code. sad girl hours. 😭

πŸ”₯ ERRORS πŸ”₯

  • -E2BIG β€” the string was truncated.

like okay it's technically an "error" but it's really just the function telling you "i did the thing, but i had to cut some of it off, no hard feelings". 🫢


🌈 STANDARDS 🌈

Linux.

just Linux. that's the whole answer. πŸ‘‘


🧚 HISTORY 🧚

Linux.

also just Linux. the origin story is short and confident. πŸ’…


πŸ’€ CAVEATS πŸ’€

okay this is the part where we need to sit down and have a real one, bestie.

the s in the name of this function refers to safety β€” but safety is a relative term that doesn't always apply to this function. πŸ’€

a more appropriate name for this function would reflect what it actually does, which is copying a string with truncation. and ngl, some projects just call it strtcpy(). so if you see that name floating around, it's the same energy. πŸ™ˆ

and listen β€” this function is not provided by any libc. so if you're a user-space programmer and you want it, you have to implement it yourself. no cap. DIY era. πŸŽ€


🫢 SEE ALSO 🫢


and that's the whole page, bestie! go forth and copy strings responsibly. 🌸

this has been <rainbow>Linux man-pages 6.20</rainbow>, dated 2026-07-11 β€” catch you in the next one, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms