ustrzncpy(3)
π ustrzncpy(3) β the Allegro manual, but make it make sense π
okay bestie, so this is a page from the Allegro game programming library manual, and today's main character is ustrzncpy. it copies strings. carefully. with rules. let's get into it β¨
πΈ NAME πΈ
ustrzncpy β copies a string into another one, and this time you get to specify the size. part of the Allegro game programming library, obviously π
π¦ SYNOPSIS π¦
#include <allegro.h>
char *ustrzncpy(char *dest, int size, const char *src, int n);
β¨ DESCRIPTION β¨
so. this function is like ustrzcpy(), with one extra lil twist: no more than n characters from src get copied into dest. and dest's length in bytes is specified by size, and β this is the important part, the moment of the whole page β dest is guaranteed to be null-terminated even if src is bigger than size. no cap. π«Ά
and if src is shorter than n characters? then null characters get appended to dest as padding until n characters have been written. that's it. that's the padding. π
in any case β literally always, every single time β dest is guaranteed to be null-terminated. periodt. π
π¨ okay now the serious part, listen up bestie π¨ even for empty strings, your destination string must have at least enough bytes to store the terminating null character of the string, and yoursizeparameter must reflect this. i'm so serious. if you don't do that? the debug version of Allegro will abort at an assertion π and the release version of Allegro will overrun the destination buffer ππ that's a real bad time. respect thesize, bestie. it's there for a reason.
π RETURN VALUE π
the return value is the value of dest. that's it, she just hands you back your own pointer like "here u go π
"
π SEE ALSO π
iykyk, go read those too, they're all friends π¦
and that's the page!! this absolute icon is brought to you by the Allegro manual, version 4.4.3 β go build something cute with it, mwah πβ¨πΈπ«Ά
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms