2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified Sun Jul 25 10:41:34 1993 by Rik Faith (faith@cs.unc.edu)
11 .\" Modified Wed Oct 17 01:12:26 2001 by John Levon <moz@compsoc.man.ac.uk>
12 .TH strdup 3 (date) "Linux man-pages (unreleased)"
14 strdup, strndup, strdupa, strndupa \- duplicate a string
17 .RI ( libc ", " \-lc )
20 .B #include <string.h>
22 .BI "char *strdup(const char *" s );
24 .BI "char *strndup(const char " s [. n "], size_t " n );
25 .BI "char *strdupa(const char *" s );
26 .BI "char *strndupa(const char " s [. n "], size_t " n );
30 Feature Test Macro Requirements for glibc (see
31 .BR feature_test_macros (7)):
37 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
38 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
39 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
45 _POSIX_C_SOURCE >= 200809L
58 function returns a pointer to a new string which
59 is a duplicate of the string
61 Memory for the new string is
69 function is similar, but copies at most
78 bytes are copied, and a terminating null byte (\[aq]\e0\[aq]) is added.
85 to allocate the buffer.
89 function returns a pointer to the duplicated
91 It returns NULL if insufficient memory was available, with
93 set to indicate the error.
97 Insufficient memory available to allocate duplicate string.
99 For an explanation of the terms used in this section, see
105 Interface Attribute Value
113 T} Thread safety MT-Safe
130 SVr4, 4.3BSD-Reno, POSIX.1-2001.