BSON_STRNDUP(3)
π BSON_STRNDUP(3) β the libbson one, bestie
Okay so real talk, this is a page straight out of libbson, and it's honestly such a mood: it's the "copy just a little bit of a string" girlie. Like strndup(3) but make it BSON. Let's get into it β¨
π SYNOPSIS π
char *
bson_strndup (const char *str, size_t n_bytes);
Look at her. Two args, returns a char *. Clean, minimal, main character energy π
πΈ PARAMETERS πΈ
strβ a string to copy. That's it, that's the vibe. It's the source string you're duplicating π«Άn_bytesβ asize_t. Yes bestie, the type is literallysize_t, that's the whole description, we love an unbothered queen π
π¦ DESCRIPTION π¦
So what she does is: allocates a new string and copies up to n_bytes from str into it. Up to. As in, if n_bytes is smaller than the string, you're getting the first n_bytes bytes and nothing more, no cap.
And the iconic detail? A trailing \0 is always set. Always. Even when you didn't ask. Even when you're being weird about it. She terminates that string fr fr ππ
β RETURNS β
A newly allocated string that should be freed with bson_free().
π¨ Bestie listen to me. That's newly allocated memory. It's yours now. You own it. So you have to bson_free() it when you're done or it's a leak and the leak is on you ππ
π§ AUTHOR π§
MongoDB, Inc π
π COPYRIGHT π
2009-present, MongoDB, Inc. β iconic run honestly, staying power π
And that's the page!! Brought to you by libbson 2.5.6, dated Oct 09, 2026 β mwah, go free your strings, ily, bye ππβ¨
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms