1*695c00c9Swiz.\" $NetBSD: wcsdup.3,v 1.4 2012/12/28 13:53:12 wiz Exp $ 25b76ee5cSwiz.\" 3d37c189aSchristos.\" Copyright (c) 1990, 1991, 1993 4d37c189aSchristos.\" The Regents of the University of California. All rights reserved. 5d37c189aSchristos.\" 6d37c189aSchristos.\" Redistribution and use in source and binary forms, with or without 7d37c189aSchristos.\" modification, are permitted provided that the following conditions 8d37c189aSchristos.\" are met: 9d37c189aSchristos.\" 1. Redistributions of source code must retain the above copyright 10d37c189aSchristos.\" notice, this list of conditions and the following disclaimer. 11d37c189aSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 12d37c189aSchristos.\" notice, this list of conditions and the following disclaimer in the 13d37c189aSchristos.\" documentation and/or other materials provided with the distribution. 14d37c189aSchristos.\" 3. Neither the name of the University nor the names of its contributors 15d37c189aSchristos.\" may be used to endorse or promote products derived from this software 16d37c189aSchristos.\" without specific prior written permission. 17d37c189aSchristos.\" 18d37c189aSchristos.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19d37c189aSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20d37c189aSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21d37c189aSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22d37c189aSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23d37c189aSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24d37c189aSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25d37c189aSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26d37c189aSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27d37c189aSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28d37c189aSchristos.\" SUCH DAMAGE. 29d37c189aSchristos.\" 30d37c189aSchristos.\" from: @(#)strdup.3 8.1 (Berkeley) 6/9/93 31d37c189aSchristos.\" 32d37c189aSchristos.Dd August 25, 2006 33d37c189aSchristos.Dt WCSDUP 3 34d37c189aSchristos.Os 35d37c189aSchristos.Sh NAME 36d37c189aSchristos.Nm wcsdup 37*695c00c9Swiz.Nd save a copy of a wide string 38d37c189aSchristos.Sh LIBRARY 39d37c189aSchristos.Lb libc 40d37c189aSchristos.Sh SYNOPSIS 41d37c189aSchristos.In wchar.h 42d37c189aSchristos.Ft wchar_t * 43d37c189aSchristos.Fn wcsdup "const wchar_t *str" 44d37c189aSchristos.Sh DESCRIPTION 45d37c189aSchristosThe 46d37c189aSchristos.Fn wcsdup 47d37c189aSchristosfunction 48d37c189aSchristosallocates sufficient memory for a copy 493d3c5d42Swizof the wide-character string 50d37c189aSchristos.Fa str , 51d37c189aSchristosdoes the copy, and returns a pointer to it. 52d37c189aSchristosThe pointer may subsequently be used as an 53d37c189aSchristosargument to the function 54d37c189aSchristos.Xr free 3 . 55d37c189aSchristos.Pp 565b76ee5cSwizIf insufficient memory is available, 575b76ee5cSwiz.Dv NULL 585b76ee5cSwizis returned. 59d37c189aSchristos.Sh EXAMPLES 60d37c189aSchristosThe following will point 61d37c189aSchristos.Va p 625b76ee5cSwizto an allocated area of memory containing the nul-terminated string 63d37c189aSchristos.Qq foobar : 64d37c189aSchristos.Bd -literal -offset indent 65d37c189aSchristoswchar_t *p; 66d37c189aSchristos 67d37c189aSchristosif (p = wcsdup(L"foobar"), p == NULL) { 68d37c189aSchristos fprintf(stderr, "Out of memory.\en"); 69d37c189aSchristos exit(1); 70d37c189aSchristos} 71d37c189aSchristos.Ed 72d37c189aSchristos.Sh ERRORS 73d37c189aSchristosThe 74d37c189aSchristos.Fn wcsdup 75d37c189aSchristosfunction may fail and set the external variable 76d37c189aSchristos.Va errno 77d37c189aSchristosfor any of the errors specified for the library function 78d37c189aSchristos.Xr malloc 3 . 79d37c189aSchristos.Sh SEE ALSO 80d37c189aSchristos.Xr free 3 , 815b76ee5cSwiz.Xr malloc 3 , 825b76ee5cSwiz.Xr strdup 3 83d37c189aSchristos.Sh HISTORY 84d37c189aSchristosThe 85d37c189aSchristos.Fn wcsdup 86d37c189aSchristosfunction first appeared in 87d37c189aSchristos.Nx 4.0 . 88