'\" t .\" Copyright 1993, David Metcalfe .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .TH strdup 3 2026-08-10 "Linux man-pages 6.19" .SH NAME strdup \- string duplicate .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "char *strdup(const char *" s ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR strdup (): .nf _XOPEN_SOURCE >= 500 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE .fi .SH DESCRIPTION The .BR strdup () function returns a pointer to a new string which is a duplicate of the string .IR s . Memory for the new string is obtained with .BR malloc (3), and can be freed with .BR free (3). .SH RETURN VALUE On success, the .BR strdup () 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 strdup () T} Thread safety MT-Safe .TE .SH STANDARDS POSIX.1-2008. .SH HISTORY SVr4, 4.3BSD-Reno, POSIX.1-2001. .SH SEE ALSO .BR malloc (3), .BR string (3), .BR strdupa (3), .BR wcsdup (3)