1STRDUP(3P)                 POSIX Programmer's Manual                STRDUP(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       strdup, strndup — duplicate a specific number of bytes from a string
14

SYNOPSIS

16       #include <string.h>
17
18       char *strdup(const char *s);
19       char *strndup(const char *s, size_t size);
20

DESCRIPTION

22       The strdup() function shall return a pointer to a new string, which  is
23       a duplicate of the string pointed to by s.  The returned pointer can be
24       passed to free().  A null pointer is returned if the new string  cannot
25       be created.
26
27       The  strndup()  function  shall be equivalent to the strdup() function,
28       duplicating the provided s in a new block of memory allocated as if  by
29       using  malloc(), with the exception being that strndup() copies at most
30       size plus one bytes into the newly allocated  memory,  terminating  the
31       new  string  with  a  NUL  character. If the length of s is larger than
32       size, only size bytes shall be duplicated. If size is larger  than  the
33       length of s, all bytes in s shall be copied into the new memory buffer,
34       including the terminating NUL character. The newly created string shall
35       always be properly terminated.
36

RETURN VALUE

38       The  strdup()  function  shall return a pointer to a new string on suc‐
39       cess. Otherwise, it shall return a null pointer and set errno to  indi‐
40       cate the error.
41
42       Upon  successful  completion,  the  strndup()  function  shall return a
43       pointer to the newly allocated memory containing the duplicated string.
44       Otherwise, it shall return a null pointer and set errno to indicate the
45       error.
46

ERRORS

48       These functions shall fail if:
49
50       ENOMEM Storage space available is insufficient.
51
52       The following sections are informative.
53

EXAMPLES

55       None.
56

APPLICATION USAGE

58       For functions that allocate memory as if by malloc(),  the  application
59       should  release  such memory when it is no longer required by a call to
60       free().  For strdup() and strndup(), this is the return value.
61

RATIONALE

63       None.
64

FUTURE DIRECTIONS

66       None.
67

SEE ALSO

69       free(), wcsdup()
70
71       The Base Definitions volume of POSIX.1‐2008, <string.h>
72
74       Portions of this text are reprinted and reproduced in  electronic  form
75       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
76       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
77       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
78       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
79       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
80       event of any discrepancy between this version and the original IEEE and
81       The  Open Group Standard, the original IEEE and The Open Group Standard
82       is the referee document. The original Standard can be  obtained  online
83       at http://www.unix.org/online.html .
84
85       Any  typographical  or  formatting  errors that appear in this page are
86       most likely to have been introduced during the conversion of the source
87       files  to  man page format. To report such errors, see https://www.ker
88       nel.org/doc/man-pages/reporting_bugs.html .
89
90
91
92IEEE/The Open Group                  2013                           STRDUP(3P)
Impressum