NNG_STRDUP(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– NNG_STRDUP πŸ’–

okay bestie, welcome to the NNG Reference Manual β€” today's main character is nng_strdup, the lil function that copies a string for you so you don't have to think about it πŸ’…


✨ NAME ✨

nng_strdup β€” duplicate string πŸ¦‹


🌸 SYNOPSIS 🌸

#include <nng/nng.h>

char *nng_strdup(const char *src);

πŸŽ€ DESCRIPTION πŸŽ€

so nng_strdup() takes your string src, duplicates it, and hands it right back to you. it's giving copy-paste but ✨allocated✨

like, logically it's the exact same thing as calling nng_alloc() to allocate a chunk of memory that's strlen(s) + 1 bytes big, and then using strcpy() to copy the string into that destination before returning it. no cap, that's literally the whole deal πŸ’€

the string you get back should be deallocated with nng_strfree(), or it may be deallocated using nng_free() β€” in which case you use the length of the returned string plus one (that's the NUL terminating byte, bestie, don't forget it 🫢).

πŸ”΄ Important πŸ”΄ do NOT use the system free() or similar functions to deallocate the string, because those may use a different memory arena! that's a whole different friend group and they will not recognize your pointer 😭

🌈 RETURN VALUES 🌈

  • on success: it returns the new string, slay πŸ‘‘
  • on failure: it returns NULL πŸ’€

⭐ ERRORS ⭐

no errors are returned, but if you get a NULL return value you should treat it the same as NNG_ENOMEM. periodt.


🧚 SEE ALSO 🧚


that's the whole vibe check, bestie πŸ’œ this was the NNG Reference Manual, page NNG_STRDUP(3), dated 2026-06-30 β€” go forth and duplicate responsibly, and remember: only nng_strfree() or nng_free(), never the system free(). mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from