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