ustrzcpy(3alleg4)
π ustrzcpy β bestie edition π
ok so real talk, this one's from the Allegro game programming library, manual section 3alleg4, and it's the string-copying function that actually respects your boundaries. iconic behaviour tbh.
β¨ SYNOPSIS β¨
#include <allegro.h>
char *ustrzcpy(char *dest, int size, const char *src);
like yes she's one line of C, she's lowkey doing the most π
πΈ DESCRIPTION πΈ
okay so ustrzcpy copies src β and yes, including the terminating null character, she brings her whole self β into dest. and you tell her how many bytes dest has via size, and here's the slay: dest is guaranteed to be null-terminated even if src is bigger than size. no cap. she will not leave you hanging with a runaway string π«Ά
β οΈ but bestie. listen. even for empty strings, your destination string has to have at least enough bytes to store that terminating null character, and your size parameter must reflect that. don't be cute about it.
and if you ignore me:
- the debug version of Allegro will abort at an assertion π (she's dramatic but she's honest)
- the release version of Allegro will overrun the destination buffer π (that's the bad one, that's the undefined-behaviour one, do not)
π RETURN VALUE π
returns the value of dest. that's it. she gives you back what you gave her. main character energy honestly π
π¦ SEE ALSO π¦
mwah π that's the whole page. this was the Allegro manual, version 4.4.3, and yes she's old but she ate. go write some safe string copies, bestie, i'm obsessed with you πβ¨π
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms