ustrzncpy(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– 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 your size parameter 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 the size, 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