1STRDUP(3)                  Linux Programmer's Manual                 STRDUP(3)
2
3
4

NAME

6       strdup, strndup, strdupa, strndupa - duplicate a string
7

SYNOPSIS

9       #include <string.h>
10
11       char *strdup(const char *s);
12
13       char *strndup(const char *s, size_t n);
14       char *strdupa(const char *s);
15       char *strndupa(const char *s, size_t n);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       strdup(): _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
20       strndup(), strdupa(), strndupa(): _GNU_SOURCE
21

DESCRIPTION

23       The  strdup()  function  returns  a  pointer to a new string which is a
24       duplicate of the string s.  Memory for the new string is obtained  with
25       malloc(3), and can be freed with free(3).
26
27       The  strndup()  function  is similar, but only copies at most n charac‐
28       ters.  If s is longer than n, only n characters are copied, and a  ter‐
29       minating null byte ('\0') is added.
30
31       strdupa() and strndupa() are similar, but use alloca(3) to allocate the
32       buffer.  They are only available when using the GNU GCC suite, and suf‐
33       fer from the same limitations described in alloca(3).
34

RETURN VALUE

36       The  strdup()  function  returns a pointer to the duplicated string, or
37       NULL if insufficient memory was available.
38

ERRORS

40       ENOMEM Insufficient memory available to allocate duplicate string.
41

CONFORMING TO

43       strdup() conforms to SVr4, 4.3BSD, POSIX.1-2001.  strndup(), strdupa(),
44       and strndupa() are GNU extensions.
45

SEE ALSO

47       alloca(3), calloc(3), free(3), malloc(3), realloc(3), wcsdup(3)
48

COLOPHON

50       This  page  is  part of release 3.25 of the Linux man-pages project.  A
51       description of the project, and information about reporting  bugs,  can
52       be found at http://www.kernel.org/doc/man-pages/.
53
54
55
56GNU                               2007-07-26                         STRDUP(3)
Impressum