ustrzncpy(3alleg4)
π ustrzncpy β bestie, this is the size-aware string copier π
okay so you're in the 3alleg4 section of the manual, which means we're talking Allegro game programming library, and we're talking about a lil function called ustrzncpy. she copies a string into another one, but with size specified. she's careful. she's considerate. she has boundaries (literally, the size parameter is her boundaries). π
β¨ SYNOPSIS β¨
#include <allegro.h>
char *ustrzncpy(char *dest, int size, const char *src, int n);
that's it, that's the whole vibe. three things in, one string out. π
πΈ DESCRIPTION πΈ
so, ustrzncpy() is basically ustrzncpy()'s older sister ustr zcpy... no wait, she's literally ustr zcpy's sister: this function is like ustr zcpy() except for one thing β she will copy no more than n characters from src into dest. π
and dest? her length in bytes is specified by size, and she is guaranteed to be null-terminated even if src is bigger than size. yes bestie, even then. she always closes with a null. she always says goodbye properly. β¨
and if src is shorter than n characters? no problem, we just pad. null characters get appended to dest until n characters have been written. it's giving "filling the rest of the row with cushions so nothing wobbles." π«Ά
in any case, dest is guaranteed to be null-terminated. always. every time. no cap.
β οΈ okay this part is important and lowkey a jump scare: even for empty strings, your destination string must have at least enough bytes to store the terminating null character of the string, and your parameter size must reflect this. otherwise β and I'm not being dramatic, this is just what happens β the debug version of Allegro will abort at an assertion, and the release version of Allegro will overrun the destination buffer. π
so like. count your bytes. size matters (in the buffer sense). don't skip the null. π
π RETURN VALUE π
the return value is the value of dest. that's it. she gives you back your own pointer like a lil boomerang. πͺ iconic behavior.
π SEE ALSO π
go read those too bestie, they're all in the friend group. π
alright that's the whole page!! this was Allegro, version 4.4.3, and the manual page is ustrzncpy(3alleg4) β mwah, go write some safe strings, 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