---
name: "bson_strndup"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_strndup"
---

# bson\_strndup(3)

## SYNOPSIS

```
char *
bson_strndup (const char *str, size_t n_bytes);
```

## PARAMETERS

- •

  **str**: A string to copy.

- •

  **n\_bytes**: A size\_t.

## DESCRIPTION

Allocates a new string and copies up to **n\_bytes** from **str** into it. A trailing **\\0** is always set.

## RETURNS

A newly allocated string that should be freed with bson\_free().

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
