BSON_STRNCPY(3)

πŸ’… BSON_STRNCPY(3) πŸ’…

okay so bestie, welcome to BSON_STRNCPY(3) β€” it's a libbson page and it's literally about copying strings safely. no cap, this one's a little icon. ✨


✨ SYNOPSIS ✨

void
bson_strncpy (char *dst, const char *src, size_t size);

πŸŽ€ PARAMETERS πŸŽ€

  • dst β€” the destination buffer. the place stuff gets copied into, the main character of the operation πŸ’–
  • src β€” the src buffer. the source, the origin story, the vibe provider 🌸
  • size β€” the number of bytes to copy into dst, which must be at least that size. so dst has to actually be big enough, no squeezing, we don't do that here 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

So what it does: it copies up to size bytes from src into dst. simple. and dst must be at least size bytes in size β€” that's not a suggestion, that's the whole deal. after all that copying, a trailing \0 is always set. always always. πŸŽ€

it does nothing if size is zero. like, zero work, zero drama, zero bytes. πŸ’€

here's the tea though: bson_strncpy matches the behavior of the C11 standard strncpy_s, rather than strncpy. lowkey important distinction!! this means bson_strncpy always writes a null terminator to dst, even if dst is too short to fit the entire string from src. it's showing up and doing the job no matter what 😭

and if there's additional space left in dst after copying src, bson_strncpy does not fill the remaining space with null characters. nope! it just leaves it. no padding, no filler, no extra nulls. periodt. πŸ’…

bestie don't confuse it with plain strncpy β€” the whole point is that it always null-terminates, so πŸ‘ keep πŸ‘ that πŸ‘ in πŸ‘ mind πŸ‘

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the legends themselves 🫢


2009-present, MongoDB, Inc. β€” iconic, copyrighted, and thriving since 2009 ⭐


and that's the whole page, bestie!! πŸ¦‹ you're now a bson_strncpy girly fr fr πŸ’œ this was libbson 2.5.6, dated Oct 09, 2026 β€” catch you on the next manpage, mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from