---
name: "strndupa"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/strndupa"
---

# strndupa(3)

nonstring duplicate-into-string using-alloca

## NAME

strndupa - nonstring duplicate-into-string using-alloca

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#define _GNU_SOURCE  /* See feature_test_macros(7) */
#include <string.h>  // see memory.h(3head)
```

**char \*strndupa(**size\_t n;               **const char** *strn***\[***n***\], size\_t** *n***);**

## DESCRIPTION

**strndupa**() is similar to [**strndup**(3)](/strndup/3.md), but uses [**alloca**(3)](/alloca/3.md) to allocate the buffer.

It is equivalent to

```
strncat(strcpy(alloca(n + 1), ""), strn, n)
```

## RETURN VALUE

On success, this macro returns a pointer to the duplicated string.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **strndupa**() | Thread safety | MT-Safe |

## STANDARDS

GNU.

## HISTORY

GNU.

## SEE ALSO

[**memory.h**(3head)](/memory.h/3head.md), [**alloca**(3)](/alloca/3.md), [**strndup**(3)](/strndup/3.md)
