Using standard wchar string functions instead of winchar_*

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6072 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-04-30 14:48:19 +00:00
parent b9a5d24705
commit f7f4d2f033
10 changed files with 72 additions and 69 deletions

View file

@ -47,8 +47,9 @@ int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
hr = LoadTypeLib(fullpath, &typeLib); hr = LoadTypeLib(fullpath, &typeLib);
#else #else
// If built without UNICODE, we still need to convert this string to a Unicode string. // If built without UNICODE, we still need to convert this string to a Unicode string.
WCHAR *ole_filename = winchar_fromTchar(fullpath); WCHAR *ole_filename = wcsdup_fromTchar(fullpath, CP_ACP);
hr = LoadTypeLib(ole_filename, &typeLib); hr = LoadTypeLib(ole_filename, &typeLib);
free(ole_filename);
#endif #endif
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {

View file

@ -59,7 +59,7 @@ void ReadVarLenArr(LPBYTE &seeker, WCHAR* &readInto, unsigned int uCodePage) {
break; break;
default: default:
{ {
readInto = winchar_strdup((WCHAR *) arr); readInto = wcsdup((WCHAR *) arr);
PWCHAR wseeker = PWCHAR(seeker); PWCHAR wseeker = PWCHAR(seeker);
while (*wseeker++); while (*wseeker++);
seeker = LPBYTE(wseeker); seeker = LPBYTE(wseeker);
@ -78,14 +78,14 @@ void ReadVarLenArr(LPBYTE &seeker, WCHAR* &readInto, unsigned int uCodePage) {
seeker += sizeof(WORD); \ seeker += sizeof(WORD); \
} \ } \
else { \ else { \
winchar_strcpy((WCHAR *) seeker, x); \ wcscpy((WCHAR *) seeker, x); \
seeker += winchar_strlen((WCHAR *) seeker) * sizeof(WCHAR) + sizeof(WCHAR); \ seeker += wcslen((WCHAR *) seeker) * sizeof(WCHAR) + sizeof(WCHAR); \
} \ } \
else \ else \
seeker += sizeof(WORD); seeker += sizeof(WORD);
// A macro that adds the size of x (which can be a string a number, or nothing) to dwSize // A macro that adds the size of x (which can be a string a number, or nothing) to dwSize
#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (winchar_strlen(x) + 1) * sizeof(WCHAR)) : sizeof(WORD) #define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (wcslen(x) + 1) * sizeof(WCHAR)) : sizeof(WORD)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Construction/Destruction // Construction/Destruction
@ -227,7 +227,7 @@ CDialogTemplate::~CDialogTemplate() {
if (m_szTitle) if (m_szTitle)
delete [] m_szTitle; delete [] m_szTitle;
if (m_szFont) if (m_szFont)
delete [] m_szFont; free(m_szFont);
for (unsigned int i = 0; i < m_vItems.size(); i++) { for (unsigned int i = 0; i < m_vItems.size(); i++) {
if (m_vItems[i]->szClass && !IS_INTRESOURCE(m_vItems[i]->szClass)) if (m_vItems[i]->szClass && !IS_INTRESOURCE(m_vItems[i]->szClass))
@ -291,8 +291,8 @@ void CDialogTemplate::SetFont(TCHAR* szFaceName, WORD wFontSize) {
} }
m_bCharset = DEFAULT_CHARSET; m_bCharset = DEFAULT_CHARSET;
m_dwStyle |= DS_SETFONT; m_dwStyle |= DS_SETFONT;
if (m_szFont) delete [] m_szFont; if (m_szFont) free(m_szFont);
m_szFont = winchar_fromTchar(szFaceName, m_uCodePage); m_szFont = wcsdup_fromTchar(szFaceName, m_uCodePage);
m_sFontSize = wFontSize; m_sFontSize = wFontSize;
} }
@ -302,10 +302,10 @@ void CDialogTemplate::AddItem(DialogItemTemplate item) {
CopyMemory(newItem, &item, sizeof(DialogItemTemplate)); CopyMemory(newItem, &item, sizeof(DialogItemTemplate));
if (item.szClass && !IS_INTRESOURCE(item.szClass)) { if (item.szClass && !IS_INTRESOURCE(item.szClass)) {
newItem->szClass = winchar_strdup(item.szClass); newItem->szClass = _wcsdup(item.szClass);
} }
if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) { if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) {
newItem->szTitle = winchar_strdup(item.szTitle); newItem->szTitle = _wcsdup(item.szTitle);
} }
if (item.wCreateDataSize) { if (item.wCreateDataSize) {
newItem->szCreationData = new char[item.wCreateDataSize]; newItem->szCreationData = new char[item.wCreateDataSize];

View file

@ -222,13 +222,13 @@ static WCHAR* ResStringToUnicode(const char *szString) {
if (IS_INTRESOURCE(szString)) if (IS_INTRESOURCE(szString))
return MAKEINTRESOURCEW((ULONG_PTR)szString); return MAKEINTRESOURCEW((ULONG_PTR)szString);
else else
return winchar_fromTchar(szString); return wcsdup_fromTchar(szString, CP_ACP);
} }
#endif #endif
static void FreeUnicodeResString(WCHAR* szwString) { static void FreeUnicodeResString(WCHAR* szwString) {
if (!IS_INTRESOURCE(szwString)) if (!IS_INTRESOURCE(szwString))
delete [] szwString; free(szwString);
} }
@ -580,7 +580,7 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
size_t nameSize = ConvertEndianness(rds->Length); size_t nameSize = ConvertEndianness(rds->Length);
szName = new WCHAR[nameSize+1]; szName = new WCHAR[nameSize+1];
winchar_strncpy(szName, rds->NameString, nameSize); wcsncpy(szName, rds->NameString, nameSize);
szName[nameSize] = 0; szName[nameSize] = 0;
} }
// Else, set the name to this entry's id // Else, set the name to this entry's id
@ -709,7 +709,7 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_ulWrittenAt)->UName.NameString.NameOffset = ConvertEndianness((DWORD) (seeker - pbRsrcSec)); PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_ulWrittenAt)->UName.NameString.NameOffset = ConvertEndianness((DWORD) (seeker - pbRsrcSec));
WCHAR* szName = cRDirE->GetName(); WCHAR* szName = cRDirE->GetName();
WORD iLen = winchar_strlen(szName) + 1; WORD iLen = wcslen(szName) + 1;
*(WORD*)seeker = ConvertEndianness(iLen); *(WORD*)seeker = ConvertEndianness(iLen);
CopyMemory(seeker + sizeof(WORD), szName, iLen*sizeof(WCHAR)); CopyMemory(seeker + sizeof(WORD), szName, iLen*sizeof(WCHAR));
@ -818,7 +818,7 @@ void CResourceDirectory::AddEntry(CResourceDirectoryEntry* entry) {
WCHAR* szEntName = entry->GetName(); WCHAR* szEntName = entry->GetName();
for (i = 0; i < m_rdDir.NumberOfNamedEntries; i++) { for (i = 0; i < m_rdDir.NumberOfNamedEntries; i++) {
WCHAR* szName = m_vEntries[i]->GetName(); WCHAR* szName = m_vEntries[i]->GetName();
int cmp = winchar_strcmp(szName, szEntName); int cmp = wcscmp(szName, szEntName);
delete [] szName; delete [] szName;
if (cmp == 0) { if (cmp == 0) {
delete [] szEntName; delete [] szEntName;
@ -870,7 +870,7 @@ int CResourceDirectory::Find(WCHAR* szName) {
continue; continue;
WCHAR* szEntName = m_vEntries[i]->GetName(); WCHAR* szEntName = m_vEntries[i]->GetName();
int cmp = winchar_strcmp(szName, szEntName); int cmp = wcscmp(szName, szEntName);
delete [] szEntName; delete [] szEntName;
if (!cmp) if (!cmp)
@ -942,7 +942,7 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDirecto
} }
else { else {
m_bHasName = true; m_bHasName = true;
m_szName = winchar_strdup(szName); m_szName = _wcsdup(szName);
} }
m_bIsDataDirectory = true; m_bIsDataDirectory = true;
m_rdSubDir = rdSubDir; m_rdSubDir = rdSubDir;
@ -956,7 +956,7 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDataEnt
} }
else { else {
m_bHasName = true; m_bHasName = true;
m_szName = winchar_strdup(szName); m_szName = _wcsdup(szName);
} }
m_bIsDataDirectory = false; m_bIsDataDirectory = false;
m_rdeData = rdeData; m_rdeData = rdeData;
@ -979,11 +979,11 @@ bool CResourceDirectoryEntry::HasName() {
WCHAR* CResourceDirectoryEntry::GetName() { WCHAR* CResourceDirectoryEntry::GetName() {
if (!m_bHasName) if (!m_bHasName)
return 0; return 0;
return winchar_strdup(m_szName); return _wcsdup(m_szName);
} }
int CResourceDirectoryEntry::GetNameLength() { int CResourceDirectoryEntry::GetNameLength() {
return winchar_strlen(m_szName); return wcslen(m_szName);
} }
WORD CResourceDirectoryEntry::GetId() { WORD CResourceDirectoryEntry::GetId() {

View file

@ -140,7 +140,7 @@ int GetVersionHeader (LPSTR &p, WORD &wLength, WORD &wValueLength, WORD &wType)
wType = *(WORD*)p; wType = *(WORD*)p;
p += sizeof(WORD); p += sizeof(WORD);
szKey = (WCHAR*)p; szKey = (WCHAR*)p;
p += (winchar_strlen(szKey) + 1) * sizeof (WCHAR); p += (wcslen(szKey) + 1) * sizeof (WCHAR);
while ( ((ULONG_PTR)p % 4) != 0 ) while ( ((ULONG_PTR)p % 4) != 0 )
p++; p++;
return p - baseP; return p - baseP;
@ -171,7 +171,7 @@ void SaveVersionHeader (GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wTy
strm.add (&wValueLength, sizeof (wValueLength)); strm.add (&wValueLength, sizeof (wValueLength));
strm.add (&wType, sizeof (wType)); strm.add (&wType, sizeof (wType));
keyLen = WORD((winchar_strlen(key) + 1) * sizeof (WCHAR)); keyLen = WORD((wcslen(key) + 1) * sizeof (WCHAR));
strm.add ((void*)key, keyLen); strm.add ((void*)key, keyLen);
PadStream(strm); PadStream(strm);
@ -210,11 +210,11 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
PadStream (stringInfoStream); PadStream (stringInfoStream);
p = stringInfoStream.getlen(); p = stringInfoStream.getlen();
KeyName = winchar_fromTchar(pChildStrings->getname(i), codepage); KeyName = wcsdup_fromTchar(pChildStrings->getname(i), codepage);
KeyValue = winchar_fromTchar(pChildStrings->getvalue(i), codepage); KeyValue = wcsdup_fromTchar(pChildStrings->getvalue(i), codepage);
SaveVersionHeader (stringInfoStream, 0, WORD(winchar_strlen(KeyValue) + 1), 1, KeyName, (void*)KeyValue); SaveVersionHeader (stringInfoStream, 0, WORD(wcslen(KeyValue) + 1), 1, KeyName, (void*)KeyValue);
delete [] KeyName; free(KeyName);
delete [] KeyValue; free(KeyValue);
wSize = WORD(stringInfoStream.getlen() - p); wSize = WORD(stringInfoStream.getlen() - p);
*(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize; *(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize;

View file

@ -22,18 +22,18 @@ class WinCharTest : public CppUnit::TestFixture {
public: public:
void testFromTchar() { void testFromTchar() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR *dyn = winchar_fromTchar("test"); WCHAR *dyn = wcsdup_fromansi("test");
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
delete [] dyn; free(dyn);
} }
void testStrCpy() { void testStrCpy() {
WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5]; WCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strcpy(b, a) ); CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcscpy(b, a) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a, b, 5) );
} }
@ -41,22 +41,22 @@ public:
WCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5]; WCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a1, 5) ); CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a1, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WCHAR)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WCHAR)) );
WCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 }; WCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 };
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a2, 5) ); CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a2, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a1, 2) ); CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) wcsncpy(b, a1, 2) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) ); CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
} }
void testStrLen() { void testStrLen() {
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 }; WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
CPPUNIT_ASSERT_EQUAL( (size_t) 4, winchar_strlen(test) ); CPPUNIT_ASSERT_EQUAL( (size_t) 4, wcslen(test) );
} }
static int simplifyNumber(int n) { static int simplifyNumber(int n) {
@ -78,7 +78,7 @@ public:
#define TEST_STR_CMP(x, y) \ #define TEST_STR_CMP(x, y) \
CPPUNIT_ASSERT_EQUAL(\ CPPUNIT_ASSERT_EQUAL(\
simplifyNumber(strcmp(x, y)), \ simplifyNumber(strcmp(x, y)), \
simplifyNumber(winchar_strcmp(w##x, w##y)) \ simplifyNumber(wcscmp(w##x, w##y)) \
) )
TEST_STR_CMP(a, b); TEST_STR_CMP(a, b);
@ -93,9 +93,9 @@ public:
void testStrDup() { void testStrDup() {
WCHAR a[] = { _x('a'), _x('b'), _x('c'), 0 }; WCHAR a[] = { _x('a'), _x('b'), _x('c'), 0 };
WCHAR *b = winchar_strdup(a); WCHAR *b = _wcsdup(a);
CPPUNIT_ASSERT_EQUAL( 0, winchar_strcmp(a, b) ); CPPUNIT_ASSERT_EQUAL( 0, wcscmp(a, b) );
delete [] b; delete [] b;
} }

View file

@ -477,7 +477,7 @@ int CEXEBuild::add_string(const TCHAR *string, int process/*=1*/, WORD codepage/
int CEXEBuild::add_intstring(const int i) // returns offset in stringblock int CEXEBuild::add_intstring(const int i) // returns offset in stringblock
{ {
TCHAR i_str[1024]; TCHAR i_str[32];
wsprintf(i_str, _T("%d"), i); wsprintf(i_str, _T("%d"), i);
return add_string(i_str); return add_string(i_str);
} }

View file

@ -1589,26 +1589,26 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_ERROR; return PS_ERROR;
} }
rewind(fp); rewind(fp);
TCHAR *data=(TCHAR*)malloc(datalen+2*sizeof(TCHAR)); char *data=(char*)malloc(datalen+2);
if (!data) if (!data)
{ {
ERROR_MSG(_T("Internal compiler error #12345: LicenseData malloc(%d) failed.\n"), datalen+2); ERROR_MSG(_T("Internal compiler error #12345: LicenseData malloc(%d) failed.\n"), datalen+2);
return PS_ERROR; return PS_ERROR;
} }
MANAGE_WITH(data, free); MANAGE_WITH(data, free);
TCHAR *ldata=data+1; char *ldata=data+1;
if (fread((void*)ldata,1,datalen,fp) != datalen) if (fread((void*)ldata,1,datalen,fp) != datalen)
{ {
ERROR_MSG(_T("LicenseLangString: can't read file.\n")); ERROR_MSG(_T("LicenseLangString: can't read file.\n"));
return PS_ERROR; return PS_ERROR;
} }
ldata[datalen/sizeof(TCHAR)]=0; ldata[datalen]='\0';
if (!strncmp((char*)ldata,"{\\rtf",sizeof("{\\rtf")-1)) if (!memcmp(ldata,"{\\rtf",6))
*data = SF_RTF; *data = SF_RTF;
else else
*data = SF_TEXT; *data = SF_TEXT;
int ret = SetLangString(name, lang, data); int ret = SetLangString(name, lang, (TCHAR*) data);
if (ret == PS_WARNING) if (ret == PS_WARNING)
warning_fl(_T("LicenseLangString \"%s\" set multiple times for %d, wasting space"), name, lang); warning_fl(_T("LicenseLangString \"%s\" set multiple times for %d, wasting space"), name, lang);
else if (ret == PS_ERROR) else if (ret == PS_ERROR)
@ -4886,11 +4886,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
case TOK_GETCURRENTADDR: case TOK_GETCURRENTADDR:
ent.which=EW_ASSIGNVAR; ent.which=EW_ASSIGNVAR;
ent.offsets[0]=GetUserVarIndex(line, 1); ent.offsets[0]=GetUserVarIndex(line, 1);
{ ent.offsets[1]=add_intstring(1+(cur_header->blocks[NB_ENTRIES].num));
TCHAR buf[32];
wsprintf(buf,_T("%d"),1+(cur_header->blocks[NB_ENTRIES].num));
ent.offsets[1]=add_string(buf);
}
if (ent.offsets[0] < 0) PRINTHELP() if (ent.offsets[0] < 0) PRINTHELP()
ent.offsets[2]=0; ent.offsets[2]=0;
ent.offsets[3]=0; ent.offsets[3]=0;
@ -5970,7 +5966,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
// next, call it // next, call it
ent.which=EW_REGISTERDLL; ent.which=EW_REGISTERDLL;
ent.offsets[0]=add_string(tempDLL);; ent.offsets[0]=add_string(tempDLL);
ent.offsets[1]=add_string(funcname.c_str()); ent.offsets[1]=add_string(funcname.c_str());
ent.offsets[2]=0; ent.offsets[2]=0;
ent.offsets[3]=nounload|build_plugin_unload; ent.offsets[3]=nounload|build_plugin_unload;

View file

@ -212,7 +212,7 @@ int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
} }
if (cchWideChar < 0) { if (cchWideChar < 0) {
cchWideChar = (int) winchar_strlen(lpWideCharStr) + 1; cchWideChar = (int) _wcslen(lpWideCharStr) + 1;
} }
if (cbMultiByte == 0) { if (cbMultiByte == 0) {
@ -546,7 +546,7 @@ static bool GetDLLVersionUsingRE(const tstring& filepath, DWORD& high, DWORD & l
{ {
// get VS_FIXEDFILEINFO from VS_VERSIONINFO // get VS_FIXEDFILEINFO from VS_VERSIONINFO
WCHAR *szKey = (WCHAR *)(ver + sizeof(WORD) * 3); WCHAR *szKey = (WCHAR *)(ver + sizeof(WORD) * 3);
int len = (winchar_strlen(szKey) + 1) * sizeof(WCHAR) + sizeof(WORD) * 3; int len = (wcslen(szKey) + 1) * sizeof(WCHAR) + sizeof(WORD) * 3;
len = (len + 3) & ~3; // align on DWORD boundry len = (len + 3) & ~3; // align on DWORD boundry
VS_FIXEDFILEINFO *verinfo = (VS_FIXEDFILEINFO *)(ver + len); VS_FIXEDFILEINFO *verinfo = (VS_FIXEDFILEINFO *)(ver + len);
if (versize > len && verinfo->dwSignature == VS_FFI_SIGNATURE) if (versize > len && verinfo->dwSignature == VS_FFI_SIGNATURE)

View file

@ -24,11 +24,8 @@
using std::runtime_error; using std::runtime_error;
WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage/*=CP_ACP*/) WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage/* = CP_ACP*/)
{ {
#ifdef _UNICODE
return _wcsdup(s); // codepage is not used in this mode
#else
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0); int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
if (l == 0) if (l == 0)
throw runtime_error("Unicode conversion failed"); throw runtime_error("Unicode conversion failed");
@ -39,10 +36,10 @@ WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage/*=CP_ACP*/)
throw runtime_error("Unicode conversion failed"); throw runtime_error("Unicode conversion failed");
return ws; return ws;
#endif
} }
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2) #if 0 // Needed by some RTL missing wchar string functions ?
WCHAR *wcscpy(WCHAR *ws1, const WCHAR *ws2)
{ {
WCHAR *ret = ws1; WCHAR *ret = ws1;
@ -56,7 +53,7 @@ WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2)
return ret; return ret;
} }
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n) WCHAR *wcsncpy(WCHAR *ws1, const WCHAR *ws2, size_t n)
{ {
WCHAR *ret = ws1; WCHAR *ret = ws1;
@ -74,7 +71,7 @@ WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n)
return ret; return ret;
} }
size_t winchar_strlen(const WCHAR *ws) size_t wcslen(const WCHAR *ws)
{ {
size_t len = 0; size_t len = 0;
@ -86,14 +83,14 @@ size_t winchar_strlen(const WCHAR *ws)
return len; return len;
} }
WCHAR *winchar_strdup(const WCHAR *ws) WCHAR *_wcsdup(const WCHAR *ws)
{ {
WCHAR *dup = new WCHAR[winchar_strlen(ws) + 1]; WCHAR *dup = (WCHAR*) malloc(sizeof(WCHAR)*(wcslen(ws)+1)];
winchar_strcpy(dup, ws); wcscpy(dup, ws);
return dup; return dup;
} }
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2) int wcscmp(const WCHAR *ws1, const WCHAR *ws2)
{ {
int diff = 0; int diff = 0;
@ -105,3 +102,4 @@ int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2)
return diff; return diff;
} }
#endif

View file

@ -18,9 +18,17 @@
#include "Platform.h" #include "Platform.h"
WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage = CP_ACP); WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage = CP_ACP);
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2); #ifdef _UNICODE
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n); #define wcsdup_fromTchar(s, codepage) _wcsdup(s) // codepage is not used in this mode
size_t winchar_strlen(const WCHAR *ws); #else
WCHAR *winchar_strdup(const WCHAR *ws); #define wcsdup_fromTchar(s, codepage) wcsdup_fromansi(s, codepage)
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2); #endif
#if 0 // Needed by some RTL missing wchar string functions ?
WCHAR *wcscpy(WCHAR *ws1, const WCHAR *ws2);
WCHAR *wcsncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
size_t wcslen(const WCHAR *ws);
WCHAR *_wcsdup(const WCHAR *ws);
int wcscmp(const WCHAR *ws1, const WCHAR *ws2);
#endif