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       #define _GNU_SOURCE
14       #include <string.h>
15
16       char *strndup(const char *s, size_t n);
17       char *strdupa(const char *s);
18       char *strndupa(const char *s, size_t n);
19
20

DESCRIPTION

22       The  strdup()  function  returns  a  pointer to a new string which is a
23       duplicate of the string s.  Memory for the new string is obtained  with
24       malloc(3), and can be freed with free(3).
25
26       The  strndup()  function  is similar, but only copies at most n charac‐
27       ters. If s is longer than n, only n characters are copied, and a termi‐
28       nating null byte ('\0') is added.
29
30       strdupa() and strndupa() are similar, but use alloca(3) to allocate the
31       buffer. They are only available when using the GNU GCC suite, and  suf‐
32       fer from the same limitations described in alloca(3).
33
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), fea‐
48       ture_test_macros(7)
49
50
51
52GNU                               1993-04-12                         STRDUP(3)
Impressum