'\" t .\" Copyright 1993, David Metcalfe .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .TH strndup 3 2026-08-17 "Linux man-pages 6.19" .SH NAME strndup \- nonstring duplicate-into-string .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .BR #include\~ " // see memory.h(3head)" .P .BR "char *strndup(" "size_t n;" .BI " const char " strn [ n "], size_t " n ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR strndup (): .nf Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE .fi .SH DESCRIPTION This function duplicates at most .I n nonnull characters from the array pointed to by .IR strn , followed by a null character, into new memory obtained with .BR malloc (3). .SH RETURN VALUE On success, the .BR strndup () function returns a pointer to the duplicated string. It returns NULL if insufficient memory was available, with .I errno set to indicate the error. .SH ERRORS See .BR malloc (3). .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR strndup () T} Thread safety MT-Safe .TE .SH STANDARDS POSIX.1-2008. .SH HISTORY POSIX.1-2008. .SH SEE ALSO .BR memory.h (3head), .BR malloc (3), .BR strndupa (3)