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.354
1 files changed, 38 insertions, 16 deletions
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3
index 925cbf3d46..9c154c7d70 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.10 2000/04/21 15:32:15 aaron 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
@@ -29,10 +31,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
31.\" 33.\"
32.\" from: @(#)strdup.3 5.3 (Berkeley) 4/19/91 34.\" @(#)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.\" 35.\"
35.Dd April 19, 1991 36.Dd June 9, 1993
36.Dt STRDUP 3 37.Dt STRDUP 3
37.Os 38.Os
38.Sh NAME 39.Sh NAME
@@ -41,25 +42,46 @@
41.Sh SYNOPSIS 42.Sh SYNOPSIS
42.Fd #include <string.h> 43.Fd #include <string.h>
43.Ft char * 44.Ft char *
44.Fn strdup "const char *str" 45.Fn strdup "const char *s"
45.Sh DESCRIPTION 46.Sh DESCRIPTION
46The 47The
47.Fn strdup 48.Fn strdup
48function 49function allocates sufficient memory for a copy of the string
49allocates sufficient memory for a copy 50.Fa s ,
50of the string
51.Fa str ,
52does the copy, and returns a pointer to it. 51does the copy, and returns a pointer to it.
53The pointer may subsequently be used as an 52The pointer may subsequently be used as an argument to the function
54argument to the function
55.Xr free 3 . 53.Xr free 3 .
54.Pp
55If insufficient memory is available,
56.Dv NULL
57is returned.
58.Sh EXAMPLES
59The following will point
60.Va p
61to an allocated area of memory containing the null-terminated string
62.Qq foobar :
63.Bd -literal -offset indent
64char *p;
65
66if ((p = strdup("foobar")) == NULL) {
67 fprintf(stderr, "Out of memory.\en");
68 exit(1);
69}
70.Ed
71.Sh ERRORS
72The
73.Fn strdup
74function may fail and set the external variable
75.Va errno
76for any of the errors specified for the library function
77.Xr malloc 3 .
56.Sh SEE ALSO 78.Sh SEE ALSO
57.Xr free 3 , 79.Xr free 3 ,
58.Xr malloc 3 , 80.Xr malloc 3 ,
59.Xt strcpy 3 , 81.Xr strcpy 3 ,
60.Xt strlen 3 82.Xr strlen 3
61.Sh HISTORY 83.Sh HISTORY
62The 84The
63.Fn strdup 85.Fn strdup
64function 86function first appeared in
65.Ud . 87.Bx 4.4 .