]> pd.if.org Git - pdclib/blob - man3/strdup.3
Manual pages: renmae man->man3 to follow existing conventions. Add files _Exit.3...
[pdclib] / man3 / strdup.3
1 .\" This file is part of the Public Domain C Library (PDCLib).\r
2 .\" Permission is granted to use, modify, and / or redistribute at will.\r
3 .\"\r
4 .Dd\r
5 .Dt strdup 3\r
6 .Os\r
7 \r
8 .Sh NAME\r
9 .Nm strdup\r
10 .Nd string duplication\r
11 \r
12 .Sh SYNOPSIS\r
13 .Sy #define _XOPEN_SOURCE || _POSIX_C_SOURCE >= 200809L\r
14 .In string.h\r
15 .Fn "char *strdup" "const char *str"\r
16 .Pp\r
17 .Sy #define _POSIX_C_SOURCE >= 200809L\r
18 .In string.h\r
19 .Fn "char *strndup" "const char *str" "size_t len"\r
20 \r
21 .Sh DESCRIPTION\r
22 .Fn strdup\r
23 allocates a new buffer of sufficient size as to be able to hold the entirety of\r
24 .Va str ,\r
25 including the terminating character, and copies the contents of\r
26 .Va str\r
27 into it.\r
28 \r
29 .Pp\r
30 .Fn strndup\r
31 allocates a buffer large enough to contain\r
32 .Va len\r
33 characters, plus a trailing null character, or sufficient to contain the \r
34 entirety of\r
35 .Va str\r
36 including the trailing null character, whichever is smaller. The first \r
37 .Va len\r
38 characters of \r
39 .Va str\r
40 are then copied into it, and a null character appended.\r
41 \r
42 .Pp\r
43 The buffers returned by these functions must be released by a call to\r
44 .Fn free .\r
45 \r
46 .Sh SEE ALSO\r
47 .Xr free 3\r
48 .Xr malloc 3\r
49 .Xr strcpy 3\r
50 .Xr strncpy 3\r
51 \r
52 .Sh STANDARDS\r
53 .Fn strdup\r
54 first specified in \r
55 .St -xpg3 .\r
56 Moved into POSIX, and\r
57 .Fn strndup\r
58 added, with\r
59 .St -p1003.1-2008 .