| strndup(3) | Library Functions Manual | strndup(3) |
NAME
strndup - nonstring duplicate-into-string
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h> // see memory.h(3head)
char *strndup(size_t n;
const char strn[n], size_t n);
Feature Test Macro Requirements for glibc (see
feature_test_macros(7)):
strndup():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
DESCRIPTION
This function duplicates at most n nonnull characters from the array pointed to by strn, followed by a null character, into new memory obtained with malloc(3).
RETURN VALUE
On success, the strndup() function returns a pointer to the duplicated string. It returns NULL if insufficient memory was available, with errno set to indicate the error.
ERRORS
See malloc(3).
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
| Interface | Attribute | Value |
| strndup () | Thread safety | MT-Safe |
STANDARDS
POSIX.1-2008.
HISTORY
POSIX.1-2008.
SEE ALSO
memory.h(3head), malloc(3), strndupa(3)
| 2026-08-17 | Linux man-pages 6.19 |