NNG_STRDUP(3)
π 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
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms