1*8c40de08Sschwarze.\" $OpenBSD: wcsdup.3,v 1.4 2011/07/25 00:38:53 schwarze Exp $ 22dcf140dSnicm.\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $ 32dcf140dSnicm.\" 42dcf140dSnicm.\" Copyright (c) 1990, 1991, 1993 52dcf140dSnicm.\" The Regents of the University of California. All rights reserved. 62dcf140dSnicm.\" 72dcf140dSnicm.\" Redistribution and use in source and binary forms, with or without 82dcf140dSnicm.\" modification, are permitted provided that the following conditions 92dcf140dSnicm.\" are met: 102dcf140dSnicm.\" 1. Redistributions of source code must retain the above copyright 112dcf140dSnicm.\" notice, this list of conditions and the following disclaimer. 122dcf140dSnicm.\" 2. Redistributions in binary form must reproduce the above copyright 132dcf140dSnicm.\" notice, this list of conditions and the following disclaimer in the 142dcf140dSnicm.\" documentation and/or other materials provided with the distribution. 152dcf140dSnicm.\" 3. Neither the name of the University nor the names of its contributors 162dcf140dSnicm.\" may be used to endorse or promote products derived from this software 172dcf140dSnicm.\" without specific prior written permission. 182dcf140dSnicm.\" 192dcf140dSnicm.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 202dcf140dSnicm.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 212dcf140dSnicm.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 222dcf140dSnicm.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 232dcf140dSnicm.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 242dcf140dSnicm.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 252dcf140dSnicm.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 262dcf140dSnicm.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 272dcf140dSnicm.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 282dcf140dSnicm.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 292dcf140dSnicm.\" SUCH DAMAGE. 302dcf140dSnicm.\" 31*8c40de08Sschwarze.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 322dcf140dSnicm.\" 33*8c40de08Sschwarze.Dd $Mdocdate: July 25 2011 $ 342dcf140dSnicm.Dt WCSDUP 3 352dcf140dSnicm.Os 362dcf140dSnicm.Sh NAME 372dcf140dSnicm.Nm wcsdup 38*8c40de08Sschwarze.Nd save a copy of a wide string 392dcf140dSnicm.Sh SYNOPSIS 402dcf140dSnicm.In wchar.h 412dcf140dSnicm.Ft wchar_t * 422dcf140dSnicm.Fn wcsdup "const wchar_t *str" 432dcf140dSnicm.Sh DESCRIPTION 442dcf140dSnicmThe 452dcf140dSnicm.Fn wcsdup 462dcf140dSnicmfunction 472dcf140dSnicmallocates sufficient memory for a copy 482dcf140dSnicmof the wide-character string 492dcf140dSnicm.Fa str , 502dcf140dSnicmdoes the copy, and returns a pointer to it. 512dcf140dSnicmThe pointer may subsequently be used as an 522dcf140dSnicmargument to the function 532dcf140dSnicm.Xr free 3 . 542dcf140dSnicm.Pp 552dcf140dSnicmIf insufficient memory is available, 562dcf140dSnicm.Dv NULL 572dcf140dSnicmis returned. 582dcf140dSnicm.Sh EXAMPLES 592dcf140dSnicmThe following will point 602dcf140dSnicm.Va p 612dcf140dSnicmto an allocated area of memory containing the nul-terminated string 622dcf140dSnicm.Qq foobar : 632dcf140dSnicm.Bd -literal -offset indent 64e2c7916aSnicmconst char *o = "foobar"; 65e2c7916aSnicmwchar_t *p, b[32]; 66e2c7916aSnicmsize_t blen; 672dcf140dSnicm 68e2c7916aSnicmblen = sizeof(b) / sizeof(b[0]); 69*8c40de08Sschwarzeif (mbstowcs(b, o, blen) == (size_t)-1) 70*8c40de08Sschwarze err(1, NULL); 71e2c7916aSnicmb[blen - 1] = 0; 72*8c40de08Sschwarzeif ((p = wcsdup(b)) == NULL) 73*8c40de08Sschwarze err(1, NULL); 742dcf140dSnicm.Ed 752dcf140dSnicm.Sh ERRORS 762dcf140dSnicmThe 772dcf140dSnicm.Fn wcsdup 782dcf140dSnicmfunction may fail and set the external variable 792dcf140dSnicm.Va errno 802dcf140dSnicmfor any of the errors specified for the library function 812dcf140dSnicm.Xr malloc 3 . 822dcf140dSnicm.Sh SEE ALSO 832dcf140dSnicm.Xr free 3 , 842dcf140dSnicm.Xr malloc 3 , 852dcf140dSnicm.Xr strdup 3 86*8c40de08Sschwarze.Sh STANDARDS 87*8c40de08SschwarzeThe 88*8c40de08Sschwarze.Fn wcsdup 89*8c40de08Sschwarzefunction conforms to 90*8c40de08Sschwarze.St -p1003.1-2008 . 912dcf140dSnicm.Sh HISTORY 922dcf140dSnicmThe 932dcf140dSnicm.Fn wcsdup 94*8c40de08Sschwarzefunction was ported from 95*8c40de08Sschwarze.Nx 96*8c40de08Sschwarzeand first appeared in 972dcf140dSnicm.Ox 5.0 . 98