ustrzcpy(3)

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

πŸ’– ustrzcpy β€” the Allegro manual, but make it cute πŸ’–

okay so bestie, we're talking about ustrzcpy(3) from the Allegro game programming library and honestly? she's a little string-copying icon. let's get into it πŸŽ€


✨ NAME ✨

ustrzcpy β€” copies a string into another one, but you get to say how big it is. and yes, she's from the Allegro game programming library, periodt. πŸ‘‘


✨ SYNOPSIS ✨

#include <allegro.h>

char *ustrzcpy(char *dest, int size, const char *src);

look at her. so clean. so simple. πŸ¦‹


✨ DESCRIPTION ✨

okay so here's the vibe: this function copies src β€” including the terminating null character, don't forget that part, it's giving very important πŸ’… β€” straight into dest.

the length of dest in bytes is specified by size, and the absolute slay of it all is that dest is guaranteed to be null-terminated even if src is bigger than size. like, she'll hold it down no matter what. ✨

🚨 okay but listen, this is the part where you pay attention. 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 has to reflect that. no skipping this, bestie.

and if you don't do that? it's giving consequences:

  • the debug version of Allegro will abort at an assertion 😭
  • the release version of Allegro will overrun the destination buffer πŸ’€

so yeah. respect the size. she's not asking, she's telling. πŸ™ˆ


✨ RETURN VALUE ✨

returns the value of dest. that's it, that's the whole thing. short queen behavior. 🫢


✨ SEE ALSO ✨

go read those too, i'm obsessed with them 🌸


and that's the page!! this was brought to you by Allegro version 4.4.3, mwah πŸ’œ stay safe out there and always null-terminate your strings, ily, bye!! 🧚⭐

πŸ“¦ where this page comes from