2000-06-10 04:42:33 +00:00
|
|
|
/*
|
|
|
|
* Code page functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2000-06-10 04:42:33 +00:00
|
|
|
#include <stdio.h>
|
2000-07-11 22:08:43 +00:00
|
|
|
#include <stdlib.h>
|
2001-01-26 20:43:40 +00:00
|
|
|
#include <string.h>
|
2000-06-10 04:42:33 +00:00
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
2000-06-10 04:42:33 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
2002-08-15 23:18:47 +00:00
|
|
|
#include "thread.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2000-06-10 04:42:33 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(string);
|
2000-06-10 04:42:33 +00:00
|
|
|
|
|
|
|
/* current code pages */
|
|
|
|
static const union cptable *ansi_cptable;
|
|
|
|
static const union cptable *oem_cptable;
|
|
|
|
static const union cptable *mac_cptable;
|
2003-07-09 04:22:57 +00:00
|
|
|
static const union cptable *unix_cptable; /* NULL if UTF8 */
|
2002-08-15 23:18:47 +00:00
|
|
|
static LCID default_lcid = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
|
2000-07-11 22:08:43 +00:00
|
|
|
|
|
|
|
/* setup default codepage info before we can get at the locale stuff */
|
|
|
|
static void init_codepages(void)
|
|
|
|
{
|
2003-03-21 21:30:51 +00:00
|
|
|
ansi_cptable = wine_cp_get_table( 1252 );
|
|
|
|
oem_cptable = wine_cp_get_table( 437 );
|
|
|
|
mac_cptable = wine_cp_get_table( 10000 );
|
2003-07-09 04:22:57 +00:00
|
|
|
unix_cptable = wine_cp_get_table( 28591 );
|
2000-07-11 22:08:43 +00:00
|
|
|
assert( ansi_cptable );
|
|
|
|
assert( oem_cptable );
|
|
|
|
assert( mac_cptable );
|
2003-07-09 04:22:57 +00:00
|
|
|
assert( unix_cptable );
|
2000-07-11 22:08:43 +00:00
|
|
|
}
|
2000-06-10 04:42:33 +00:00
|
|
|
|
|
|
|
/* find the table for a given codepage, handling CP_ACP etc. pseudo-codepages */
|
|
|
|
static const union cptable *get_codepage_table( unsigned int codepage )
|
|
|
|
{
|
|
|
|
const union cptable *ret = NULL;
|
|
|
|
|
2000-07-11 22:08:43 +00:00
|
|
|
if (!ansi_cptable) init_codepages();
|
2000-06-10 04:42:33 +00:00
|
|
|
|
|
|
|
switch(codepage)
|
|
|
|
{
|
2002-08-15 23:18:47 +00:00
|
|
|
case CP_ACP:
|
|
|
|
return ansi_cptable;
|
|
|
|
case CP_OEMCP:
|
|
|
|
return oem_cptable;
|
|
|
|
case CP_MACCP:
|
|
|
|
return mac_cptable;
|
2000-06-10 04:42:33 +00:00
|
|
|
case CP_UTF7:
|
|
|
|
case CP_UTF8:
|
|
|
|
break;
|
2002-08-15 23:18:47 +00:00
|
|
|
case CP_THREAD_ACP:
|
|
|
|
if (!(codepage = NtCurrentTeb()->code_page)) return ansi_cptable;
|
|
|
|
/* fall through */
|
2000-06-10 04:42:33 +00:00
|
|
|
default:
|
2000-07-11 22:08:43 +00:00
|
|
|
if (codepage == ansi_cptable->info.codepage) return ansi_cptable;
|
|
|
|
if (codepage == oem_cptable->info.codepage) return oem_cptable;
|
|
|
|
if (codepage == mac_cptable->info.codepage) return mac_cptable;
|
2003-03-21 21:30:51 +00:00
|
|
|
ret = wine_cp_get_table( codepage );
|
2000-06-10 04:42:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-07-11 22:08:43 +00:00
|
|
|
/* initialize default code pages from locale info */
|
|
|
|
/* FIXME: should be done in init_codepages, but it can't right now */
|
|
|
|
/* since it needs KERNEL32 to be loaded for the locale info. */
|
2003-07-09 04:22:57 +00:00
|
|
|
void CODEPAGE_Init( UINT ansi_cp, UINT oem_cp, UINT mac_cp, UINT unix_cp, LCID lcid )
|
2000-07-11 22:08:43 +00:00
|
|
|
{
|
2003-07-09 04:22:57 +00:00
|
|
|
extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp );
|
2000-07-11 22:08:43 +00:00
|
|
|
const union cptable *table;
|
|
|
|
|
2002-08-15 23:18:47 +00:00
|
|
|
default_lcid = lcid;
|
2000-07-11 22:08:43 +00:00
|
|
|
if (!ansi_cptable) init_codepages(); /* just in case */
|
2001-12-05 22:14:57 +00:00
|
|
|
|
2003-07-09 04:22:57 +00:00
|
|
|
if ((table = wine_cp_get_table( ansi_cp ))) ansi_cptable = table;
|
|
|
|
if ((table = wine_cp_get_table( oem_cp ))) oem_cptable = table;
|
|
|
|
if ((table = wine_cp_get_table( mac_cp ))) mac_cptable = table;
|
|
|
|
if (unix_cp == CP_UTF8)
|
|
|
|
unix_cptable = NULL;
|
|
|
|
else if ((table = wine_cp_get_table( unix_cp )))
|
|
|
|
unix_cptable = table;
|
|
|
|
|
2001-12-05 22:14:57 +00:00
|
|
|
__wine_init_codepages( ansi_cptable, oem_cptable );
|
2000-07-11 22:08:43 +00:00
|
|
|
|
2003-07-09 04:22:57 +00:00
|
|
|
TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
|
|
|
|
ansi_cptable->info.codepage, oem_cptable->info.codepage,
|
|
|
|
mac_cptable->info.codepage, unix_cp );
|
2000-07-11 22:08:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-10 04:42:33 +00:00
|
|
|
/******************************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* GetACP (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Current ANSI code-page identifier, default if no current defined
|
|
|
|
*/
|
|
|
|
UINT WINAPI GetACP(void)
|
|
|
|
{
|
2002-08-15 23:18:47 +00:00
|
|
|
if (!ansi_cptable) return 1252;
|
2000-07-11 22:08:43 +00:00
|
|
|
return ansi_cptable->info.codepage;
|
2000-06-10 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* GetOEMCP (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
UINT WINAPI GetOEMCP(void)
|
|
|
|
{
|
2002-08-15 23:18:47 +00:00
|
|
|
if (!oem_cptable) return 437;
|
2000-07-11 22:08:43 +00:00
|
|
|
return oem_cptable->info.codepage;
|
2000-06-10 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* IsValidCodePage (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI IsValidCodePage( UINT codepage )
|
|
|
|
{
|
2002-06-25 00:24:36 +00:00
|
|
|
switch(codepage) {
|
|
|
|
case CP_SYMBOL:
|
|
|
|
return FALSE;
|
|
|
|
case CP_UTF7:
|
|
|
|
case CP_UTF8:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
2003-03-21 21:30:51 +00:00
|
|
|
return wine_cp_get_table( codepage ) != NULL;
|
2002-06-25 00:24:36 +00:00
|
|
|
}
|
2000-06-10 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-15 23:18:47 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetUserDefaultLangID (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LANGID WINAPI GetUserDefaultLangID(void)
|
|
|
|
{
|
|
|
|
return LANGIDFROMLCID(default_lcid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetSystemDefaultLangID (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LANGID WINAPI GetSystemDefaultLangID(void)
|
|
|
|
{
|
|
|
|
return GetUserDefaultLangID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetUserDefaultLCID (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LCID WINAPI GetUserDefaultLCID(void)
|
|
|
|
{
|
|
|
|
return default_lcid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetSystemDefaultLCID (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LCID WINAPI GetSystemDefaultLCID(void)
|
|
|
|
{
|
|
|
|
return GetUserDefaultLCID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-07 18:27:06 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetUserDefaultUILanguage (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LANGID WINAPI GetUserDefaultUILanguage(void)
|
|
|
|
{
|
|
|
|
return GetUserDefaultLangID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetSystemDefaultUILanguage (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
LANGID WINAPI GetSystemDefaultUILanguage(void)
|
|
|
|
{
|
|
|
|
return GetSystemDefaultLangID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-10 04:42:33 +00:00
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* IsDBCSLeadByteEx (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI IsDBCSLeadByteEx( UINT codepage, BYTE testchar )
|
|
|
|
{
|
|
|
|
const union cptable *table = get_codepage_table( codepage );
|
|
|
|
return table && is_dbcs_leadbyte( table, testchar );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* IsDBCSLeadByte (KERNEL32.@)
|
2001-07-11 18:56:41 +00:00
|
|
|
* IsDBCSLeadByte (KERNEL.207)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI IsDBCSLeadByte( BYTE testchar )
|
|
|
|
{
|
2002-08-15 23:18:47 +00:00
|
|
|
if (!ansi_cptable) return FALSE;
|
2000-06-10 04:42:33 +00:00
|
|
|
return is_dbcs_leadbyte( ansi_cptable, testchar );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* GetCPInfo (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo )
|
|
|
|
{
|
|
|
|
const union cptable *table = get_codepage_table( codepage );
|
|
|
|
|
2002-05-31 23:06:46 +00:00
|
|
|
if (!table)
|
2000-06-10 04:42:33 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (table->info.def_char & 0xff00)
|
|
|
|
{
|
|
|
|
cpinfo->DefaultChar[0] = table->info.def_char & 0xff00;
|
|
|
|
cpinfo->DefaultChar[1] = table->info.def_char & 0x00ff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpinfo->DefaultChar[0] = table->info.def_char & 0xff;
|
|
|
|
cpinfo->DefaultChar[1] = 0;
|
|
|
|
}
|
|
|
|
if ((cpinfo->MaxCharSize = table->info.char_size) == 2)
|
|
|
|
memcpy( cpinfo->LeadByte, table->dbcs.lead_bytes, sizeof(cpinfo->LeadByte) );
|
|
|
|
else
|
|
|
|
cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* EnumSystemCodePagesA (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum, DWORD flags )
|
|
|
|
{
|
|
|
|
const union cptable *table;
|
|
|
|
char buffer[10];
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2003-03-21 21:30:51 +00:00
|
|
|
if (!(table = wine_cp_enum_table( index++ ))) break;
|
2000-06-10 04:42:33 +00:00
|
|
|
sprintf( buffer, "%d", table->info.codepage );
|
|
|
|
if (!lpfnCodePageEnum( buffer )) break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* EnumSystemCodePagesW (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags )
|
|
|
|
{
|
|
|
|
const union cptable *table;
|
|
|
|
WCHAR buffer[10], *p;
|
|
|
|
int page, index = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2003-03-21 21:30:51 +00:00
|
|
|
if (!(table = wine_cp_enum_table( index++ ))) break;
|
2000-06-10 04:42:33 +00:00
|
|
|
p = buffer + sizeof(buffer)/sizeof(WCHAR);
|
|
|
|
*--p = 0;
|
|
|
|
page = table->info.codepage;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*--p = '0' + (page % 10);
|
|
|
|
page /= 10;
|
|
|
|
} while( page );
|
|
|
|
if (!lpfnCodePageEnum( p )) break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* MultiByteToWideChar (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* page [in] Codepage character set to convert from
|
|
|
|
* flags [in] Character mapping flags
|
|
|
|
* src [in] Source string buffer
|
|
|
|
* srclen [in] Length of source string buffer
|
|
|
|
* dst [in] Destination buffer
|
|
|
|
* dstlen [in] Length of destination buffer
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The returned length includes the null terminator character.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: If dstlen > 0, number of characters written to destination
|
|
|
|
* buffer. If dstlen == 0, number of characters needed to do
|
|
|
|
* conversion.
|
|
|
|
* Failure: 0. Occurs if not enough space is available.
|
|
|
|
*
|
|
|
|
* ERRORS
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER
|
|
|
|
* ERROR_INVALID_PARAMETER
|
|
|
|
* ERROR_NO_UNICODE_TRANSLATION
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
|
|
|
|
LPWSTR dst, INT dstlen )
|
|
|
|
{
|
|
|
|
const union cptable *table;
|
|
|
|
int ret;
|
|
|
|
|
2000-07-28 23:58:48 +00:00
|
|
|
if (!src || (!dst && dstlen))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-04 17:42:27 +00:00
|
|
|
if (srclen < 0) srclen = strlen(src) + 1;
|
2000-06-10 04:42:33 +00:00
|
|
|
|
2000-08-11 00:44:33 +00:00
|
|
|
if (flags & MB_USEGLYPHCHARS) FIXME("MB_USEGLYPHCHARS not supported\n");
|
|
|
|
|
|
|
|
switch(page)
|
2000-06-10 04:42:33 +00:00
|
|
|
{
|
2000-08-11 00:44:33 +00:00
|
|
|
case CP_UTF7:
|
2003-07-09 04:22:57 +00:00
|
|
|
FIXME("UTF-7 not supported\n");
|
2000-06-10 04:42:33 +00:00
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return 0;
|
2003-07-09 04:22:57 +00:00
|
|
|
case CP_UNIXCP:
|
|
|
|
if (unix_cptable)
|
|
|
|
{
|
|
|
|
ret = wine_cp_mbstowcs( unix_cptable, flags, src, srclen, dst, dstlen );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2000-08-11 00:44:33 +00:00
|
|
|
case CP_UTF8:
|
2003-03-21 21:30:51 +00:00
|
|
|
ret = wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
|
2000-08-11 00:44:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!(table = get_codepage_table( page )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-21 21:30:51 +00:00
|
|
|
ret = wine_cp_mbstowcs( table, flags, src, srclen, dst, dstlen );
|
2000-08-11 00:44:33 +00:00
|
|
|
break;
|
2000-06-10 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
|
|
|
|
case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* WideCharToMultiByte (KERNEL32.@)
|
2000-06-10 04:42:33 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* page [in] Codepage character set to convert to
|
|
|
|
* flags [in] Character mapping flags
|
|
|
|
* src [in] Source string buffer
|
|
|
|
* srclen [in] Length of source string buffer
|
|
|
|
* dst [in] Destination buffer
|
|
|
|
* dstlen [in] Length of destination buffer
|
|
|
|
* defchar [in] Default character to use for conversion if no exact
|
|
|
|
* conversion can be made
|
|
|
|
* used [out] Set if default character was used in the conversion
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The returned length includes the null terminator character.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: If dstlen > 0, number of characters written to destination
|
|
|
|
* buffer. If dstlen == 0, number of characters needed to do
|
|
|
|
* conversion.
|
|
|
|
* Failure: 0. Occurs if not enough space is available.
|
|
|
|
*
|
|
|
|
* ERRORS
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER
|
|
|
|
* ERROR_INVALID_PARAMETER
|
|
|
|
*/
|
|
|
|
INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
|
|
|
|
LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used )
|
|
|
|
{
|
|
|
|
const union cptable *table;
|
|
|
|
int ret, used_tmp;
|
|
|
|
|
2000-07-28 23:58:48 +00:00
|
|
|
if (!src || (!dst && dstlen))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-04 17:42:27 +00:00
|
|
|
if (srclen < 0) srclen = strlenW(src) + 1;
|
2000-06-10 04:42:33 +00:00
|
|
|
|
2000-08-11 00:44:33 +00:00
|
|
|
switch(page)
|
2000-06-10 04:42:33 +00:00
|
|
|
{
|
2000-08-11 00:44:33 +00:00
|
|
|
case CP_UTF7:
|
|
|
|
FIXME("UTF-7 not supported\n");
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
2000-06-10 04:42:33 +00:00
|
|
|
return 0;
|
2003-07-09 04:22:57 +00:00
|
|
|
case CP_UNIXCP:
|
|
|
|
if (unix_cptable)
|
|
|
|
{
|
|
|
|
ret = wine_cp_wcstombs( unix_cptable, flags, src, srclen, dst, dstlen,
|
|
|
|
defchar, used ? &used_tmp : NULL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2000-08-11 00:44:33 +00:00
|
|
|
case CP_UTF8:
|
2003-03-21 21:30:51 +00:00
|
|
|
ret = wine_utf8_wcstombs( src, srclen, dst, dstlen );
|
2000-08-11 00:44:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!(table = get_codepage_table( page )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-21 21:30:51 +00:00
|
|
|
ret = wine_cp_wcstombs( table, flags, src, srclen, dst, dstlen,
|
|
|
|
defchar, used ? &used_tmp : NULL );
|
2000-08-11 00:44:33 +00:00
|
|
|
if (used) *used = used_tmp;
|
|
|
|
break;
|
2000-06-10 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|