---
name: "strndup"
section: "3pub"
platform: "linux"
package: "publib-dev"
version: "0.40-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/strndup/3pub"
---

# strndup(3pub)

duplicate part of a string

## NAME

strndup - duplicate part of a string

## SYNOPSIS

```
#include <publib.h>
char *strndup(const char *str, size_t n);
```

## DESCRIPTION

*strndup* will make a duplicate of the *n* first characters of *str*, using [*malloc*(3)](/malloc/3.md) to allocate memory for the duplicate.  The caller is supposed to free the duplicate's memory when no longer needed.

## RETURN VALUE

*strndup* will return a pointer to the duplicate, or NULL if no memory could be allocated.

## SEE ALSO

publib(3), [strdup(3)](/strdup/3.md)

## AUTHOR

Lars Wirzenius (lars.wirzenius@helsinki.fi)
