sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : wcrtomb.cpp sl@0: // Part of : MRT LIBC sl@0: // Contains the source for the wcrtomb API implementation. sl@0: // Version : sl@0: // sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "wcharcnv.h" sl@0: sl@0: #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__))) sl@0: #include "libc_wsd_defs.h" sl@0: #endif sl@0: sl@0: #ifdef EMULATOR sl@0: sl@0: GET_STATIC_VAR_FROM_TLS(wcrtomb_mbs, mbstate_t) sl@0: #define mbs (*GET_WSD_VAR_NAME(wcrtomb_mbs, s)()) sl@0: #endif //EMULATOR sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: //Function Name : size_t wcrtomb (char * mbchar, wchar_t wc, mbstate_t* ps) sl@0: //Description : Converts a wide character to a multibyte character sl@0: //Return Value : return If mbchar is null, the return value is true (non-zero) sl@0: //if multibyte characters have state-dependent encodings, or false (zero) sl@0: //if they do not. sl@0: //----------------------------------------------------------------------------- sl@0: extern "C" { sl@0: sl@0: EXPORT_C size_t wcrtomb (char * mbchar, wchar_t wc, mbstate_t* ps) sl@0: { sl@0: #ifndef EMULATOR sl@0: static mbstate_t mbs; sl@0: #endif //EMULATOR sl@0: sl@0: if (ps == NULL) sl@0: ps = &mbs; sl@0: sl@0: mbstate_t *state = NULL; sl@0: if(ps) sl@0: { sl@0: state = ps; sl@0: } sl@0: else sl@0: { sl@0: state = &mbs; sl@0: } sl@0: if (mbchar) sl@0: { sl@0: //deal with the special null character case sl@0: if (L'\0' == wc) sl@0: { sl@0: *mbchar = '\0'; sl@0: if ( state ) sl@0: { sl@0: memset(state,0,sizeof(state)); sl@0: state->__count = _EUTF16InitialState; sl@0: } sl@0: return (1); sl@0: } sl@0: sl@0: //return value of 0 is possible if the first half of a surrogate pair seen sl@0: //crash is possible if mbchar is not at least MB_CUR_MAX bytes long sl@0: return _Utf16ToUtf8(mbchar,wc, state,MB_CUR_MAX); sl@0: } sl@0: //calling with a null dest string is used to initialise shift state sl@0: //effect is exactly as if internal dst buffer was used. sl@0: //therefore we always return 1. sl@0: else sl@0: { sl@0: if ( state ) sl@0: { sl@0: memset(state,0,sizeof(state)); sl@0: state->__count = _EUTF16InitialState; sl@0: } sl@0: return (1); sl@0: } sl@0: } //end of function sl@0: sl@0: } //extern "C"