summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/strdup.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/strdup.3')
-rw-r--r--src/lib/libc/string/strdup.361
1 files changed, 40 insertions, 21 deletions
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3
index 925cbf3d46..59b77f7a16 100644
--- a/src/lib/libc/string/strdup.3
+++ b/src/lib/libc/string/strdup.3
@@ -1,5 +1,7 @@
1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 1.\" $OpenBSD: strdup.3,v 1.12 2003/06/02 20:18:38 millert Exp $
2.\" All rights reserved. 2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
3.\" 5.\"
4.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
@@ -9,11 +11,7 @@
9.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software 14.\" 3. Neither the name of the University nor the names of its contributors
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software 15.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission. 16.\" without specific prior written permission.
19.\" 17.\"
@@ -29,10 +27,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
31.\" 29.\"
32.\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 30.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
33.\" $Id: strdup.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $
34.\" 31.\"
35.Dd April 19, 1991 32.Dd June 9, 1993
36.Dt STRDUP 3 33.Dt STRDUP 3
37.Os 34.Os
38.Sh NAME 35.Sh NAME
@@ -41,25 +38,47 @@
41.Sh SYNOPSIS 38.Sh SYNOPSIS
42.Fd #include <string.h> 39.Fd #include <string.h>
43.Ft char * 40.Ft char *
44.Fn strdup "const char *str" 41.Fn strdup "const char *s"
45.Sh DESCRIPTION 42.Sh DESCRIPTION
46The 43The
47.Fn strdup 44.Fn strdup
48function 45function allocates sufficient memory for a copy of the string
49allocates sufficient memory for a copy 46.Fa s ,
50of the string
51.Fa str ,
52does the copy, and returns a pointer to it. 47does the copy, and returns a pointer to it.
53The pointer may subsequently be used as an 48The pointer may subsequently be used as an argument to the function
54argument to the function
55.Xr free 3 . 49.Xr free 3 .
50.Pp
51If insufficient memory is available,
52.Dv NULL
53is returned.
54.Sh EXAMPLES
55The following will point
56.Va p
57to an allocated area of memory containing the null-terminated string
58.Qq foobar :
59.Bd -literal -offset indent
60char *p;
61
62if ((p = strdup("foobar")) == NULL) {
63 fprintf(stderr, "Out of memory.\en");
64 exit(1);
65}
66.Ed
67.Sh ERRORS
68The
69.Fn strdup
70function may fail and set the external variable
71.Va errno
72for any of the errors specified for the library function
73.Xr malloc 3 .
56.Sh SEE ALSO 74.Sh SEE ALSO
57.Xr free 3 , 75.Xr free 3 ,
58.Xr malloc 3 , 76.Xr malloc 3 ,
59.Xt strcpy 3 , 77.Xr strcpy 3 ,
60.Xt strlen 3 78.Xr strlcpy 3 ,
79.Xr strlen 3
61.Sh HISTORY 80.Sh HISTORY
62The 81The
63.Fn strdup 82.Fn strdup
64function 83function first appeared in
65.Ud . 84.Bx 4.4 .