Commit 80445efa authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Simplify Get/SetCalendarInfoA() implementation.

parent bf83236b
......@@ -1754,35 +1754,3 @@ int WINAPI GetCurrencyFormatEx(LPCWSTR localename, DWORD flags, LPCWSTR value,
return GetCurrencyFormatW( LocaleNameToLCID(localename, 0), flags, value, format, str, len);
}
/*********************************************************************
* GetCalendarInfoA (KERNEL32.@)
*/
int WINAPI GetCalendarInfoA( LCID lcid, CALID id, CALTYPE type, LPSTR data, int size, DWORD *val )
{
int ret, sizeW = size;
LPWSTR dataW = NULL;
if (type & CAL_RETURN_NUMBER)
return GetCalendarInfoW( lcid, id, type, (WCHAR *)data, size, val ) * sizeof(WCHAR);
if (!size) sizeW = GetCalendarInfoW( lcid, id, type, NULL, 0, NULL );
if (!(dataW = HeapAlloc(GetProcessHeap(), 0, sizeW * sizeof(WCHAR)))) return 0;
ret = GetCalendarInfoW( lcid, id, type, dataW, sizeW, val );
if(ret && dataW && data)
ret = WideCharToMultiByte( CP_ACP, 0, dataW, -1, data, size, NULL, NULL );
else if (type & CAL_RETURN_NUMBER)
ret *= sizeof(WCHAR);
HeapFree( GetProcessHeap(), 0, dataW );
return ret;
}
/*********************************************************************
* SetCalendarInfoA (KERNEL32.@)
*/
int WINAPI SetCalendarInfoA( LCID lcid, CALID id, CALTYPE type, LPCSTR data)
{
FIXME("(%08lx,%08lx,%08lx,%s): stub\n", lcid, id, type, debugstr_a(data));
return 0;
}
......@@ -63,11 +63,13 @@ extern BOOL WINAPI Internal_EnumUILanguages( UILANGUAGE_ENUMPROCW proc, DWORD fl
*
* Retrieve the ANSI codepage for a given locale.
*/
static inline UINT get_lcid_codepage( LCID lcid )
static UINT get_lcid_codepage( LCID lcid, UINT flags )
{
UINT ret;
if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
sizeof(ret)/sizeof(WCHAR) )) ret = 0;
UINT ret = 0;
if (flags & LOCALE_USE_CP_ACP) return CP_ACP;
GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&ret, sizeof(ret)/sizeof(WCHAR) );
return ret;
}
......@@ -98,13 +100,11 @@ static inline UINT get_lcid_codepage( LCID lcid )
*/
BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
{
UINT codepage = CP_ACP;
UINT codepage = get_lcid_codepage( lcid, lctype );
WCHAR *strW;
DWORD len;
BOOL ret;
if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
if (!data)
{
SetLastError( ERROR_INVALID_PARAMETER );
......@@ -376,6 +376,34 @@ BOOL WINAPI EnumUILanguagesA( UILANGUAGE_ENUMPROCA proc, DWORD flags, LONG_PTR p
}
/*********************************************************************
* GetCalendarInfoA (KERNEL32.@)
*/
int WINAPI GetCalendarInfoA( LCID lcid, CALID id, CALTYPE type, LPSTR data, int data_len, DWORD *val )
{
WCHAR buffer[256];
if (type & CAL_RETURN_NUMBER)
return GetCalendarInfoW( lcid, id, type, (WCHAR *)data, data_len, val ) * sizeof(WCHAR);
if (!GetCalendarInfoW( lcid, id, type, buffer, ARRAY_SIZE(buffer), val )) return 0;
return WideCharToMultiByte( get_lcid_codepage(lcid, type), 0, buffer, -1, data, data_len, NULL, NULL );
}
/*********************************************************************
* SetCalendarInfoA (KERNEL32.@)
*/
int WINAPI SetCalendarInfoA( LCID lcid, CALID id, CALTYPE type, LPCSTR data )
{
WCHAR buffer[256];
if (!MultiByteToWideChar( get_lcid_codepage(lcid, type), 0, data, -1, buffer, ARRAY_SIZE(buffer) ))
return 0;
return SetCalendarInfoW( lcid, id, type, buffer );
}
/******************************************************************************
* GetGeoInfoA (KERNEL32.@)
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment