xref: /openbsd/lib/libc/string/wcsdup.3 (revision 8c40de08)
1.\"	$OpenBSD: wcsdup.3,v 1.4 2011/07/25 00:38:53 schwarze Exp $
2.\"	$NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
3.\"
4.\" Copyright (c) 1990, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)strdup.3	8.1 (Berkeley) 6/9/93
32.\"
33.Dd $Mdocdate: July 25 2011 $
34.Dt WCSDUP 3
35.Os
36.Sh NAME
37.Nm wcsdup
38.Nd save a copy of a wide string
39.Sh SYNOPSIS
40.In wchar.h
41.Ft wchar_t *
42.Fn wcsdup "const wchar_t *str"
43.Sh DESCRIPTION
44The
45.Fn wcsdup
46function
47allocates sufficient memory for a copy
48of the wide-character string
49.Fa str ,
50does the copy, and returns a pointer to it.
51The pointer may subsequently be used as an
52argument to the function
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 nul-terminated string
62.Qq foobar :
63.Bd -literal -offset indent
64const char	*o = "foobar";
65wchar_t		*p, b[32];
66size_t		 blen;
67
68blen = sizeof(b) / sizeof(b[0]);
69if (mbstowcs(b, o, blen) == (size_t)-1)
70	err(1, NULL);
71b[blen - 1] = 0;
72if ((p = wcsdup(b)) == NULL)
73	err(1, NULL);
74.Ed
75.Sh ERRORS
76The
77.Fn wcsdup
78function may fail and set the external variable
79.Va errno
80for any of the errors specified for the library function
81.Xr malloc 3 .
82.Sh SEE ALSO
83.Xr free 3 ,
84.Xr malloc 3 ,
85.Xr strdup 3
86.Sh STANDARDS
87The
88.Fn wcsdup
89function conforms to
90.St -p1003.1-2008 .
91.Sh HISTORY
92The
93.Fn wcsdup
94function was ported from
95.Nx
96and first appeared in
97.Ox 5.0 .
98