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 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * wchar_t *m_mbstowcsdup(char *s) 31 * (per strdup, only converting at the same time.) 32 * Takes a multibyte string, figures out how long it will be in wide chars, 33 * allocates that wide char string, copies to that wide char string. 34 * returns (wchar_t *)0 on 35 * - out of memory 36 * - invalid multibyte character 37 * Caller must free returned memory by calling free. 38 * 39 * Copyright 1992 by Mortice Kern Systems Inc. All rights reserved. 40 * 41 */ 42 #ifdef M_RCSID 43 #ifndef lint 44 static char rcsID[] = "$Header: /rd/src/libc/wide/rcs/m_mbstow.c 1.6 1995/09/20 19:11:56 ant Exp $"; 45 #endif /*lint*/ 46 #endif /*M_RCSID*/ 47 48 #include <mks.h> 49 #include <stdlib.h> 50 #include <string.h> 51 52 wchar_t * 53 m_mbstowcsdup(const char *s) 54 { 55 int n; 56 wchar_t *w; 57 58 n = strlen(s) + 1; 59 if ((w = (wchar_t *)m_malloc(n * sizeof(wchar_t))) == NULL) { 60 m_error(m_textmsg(3581, "!memory allocation failure", "E")); 61 return(NULL); 62 } 63 64 if (mbstowcs(w, s, n) == -1) { 65 m_error(m_textmsg(3642, "!multibyte string", "E")); 66 return(NULL); 67 } 68 return w; 69 } 70