1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1996, by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /*
28 * wchar_t *m_mbstowcsdup(char *s)
29 * (per strdup, only converting at the same time.)
30 * Takes a multibyte string, figures out how long it will be in wide chars,
31 * allocates that wide char string, copies to that wide char string.
32 * returns (wchar_t *)0 on
33 * - out of memory
34 * - invalid multibyte character
35 * Caller must free returned memory by calling free.
36 *
37 * Copyright 1992 by Mortice Kern Systems Inc. All rights reserved.
38 *
39 */
40 #ifdef M_RCSID
41 #ifndef lint
42 static char rcsID[] = "$Header: /rd/src/libc/wide/rcs/m_mbstow.c 1.6 1995/09/20 19:11:56 ant Exp $";
43 #endif /*lint*/
44 #endif /*M_RCSID*/
45
46 #include <mks.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 wchar_t *
m_mbstowcsdup(const char * s)51 m_mbstowcsdup(const char *s)
52 {
53 int n;
54 wchar_t *w;
55
56 n = strlen(s) + 1;
57 if ((w = (wchar_t *)m_malloc(n * sizeof(wchar_t))) == NULL) {
58 m_error(m_textmsg(3581, "!memory allocation failure", "E"));
59 return(NULL);
60 }
61
62 if (mbstowcs(w, s, n) == -1) {
63 m_error(m_textmsg(3642, "!multibyte string", "E"));
64 return(NULL);
65 }
66 return w;
67 }
68