diff -r 000000000000 -r 2c201484c85f securityanddataprivacytools/securitytools/certapp/utils/utils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/securityanddataprivacytools/securitytools/certapp/utils/utils.cpp Wed Jul 08 11:25:26 2009 +0100 @@ -0,0 +1,176 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "utils.h" +#include "logger.h" + +#ifndef __LINUX__ +#include +#endif + +typedef unsigned char TUint8; +typedef unsigned int TUint; + +#ifdef __LINUX__ +void OpenUtf8FStreamForRead(std::fstream &aFStream, const char *aUtf8FileName) +{ + aFStream.open(aUtf8FileName, std::ios_base::binary | std::ios_base::in); +} + +void OpenUtf8FStreamForWrite(std::fstream &aFStream, const char *aUtf8FileName) +{ + aFStream.open(aUtf8FileName, std::ios_base::binary | std::ios_base::trunc | std::ios_base::out); +} + +#else + +WCHAR *WindowsUtf8ToUtf16(const char *aUtf8) +{ + int utf8Len = strlen(aUtf8) + 1; // We want to copy the terminator to the new string + int utf16Space = MultiByteToWideChar(CP_UTF8, 0, aUtf8, utf8Len, 0, 0); + if(utf16Space <= 0) + { + dbg << Log::Indent() << "Failed to convert UTF-8 '" << aUtf8 << "' to UTF16" << Log::Endl(); + FatalError(); + return 0; + } + // prog << Log::Indent() << "utf16Space " << utf16Space << Log::Endl(); + WCHAR *utf16 = new WCHAR[utf16Space]; + (void) MultiByteToWideChar(CP_UTF8, 0, aUtf8, utf8Len, utf16, utf16Space); +#if 0 + prog << Log::Indent() << "Raw UTF16 name is (chars " << utf16Space << ")" << Log::Endl(); + for(int i=0; i