Module: wine Branch: master Commit: 80445efa9048e885df0ad77ce1fa9825acfa7694 URL: https://source.winehq.org/git/wine.git/?a=commit;h=80445efa9048e885df0ad77ce...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Apr 6 10:16:41 2022 +0200
kernel32: Simplify Get/SetCalendarInfoA() implementation.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/kernel32/lcformat.c | 32 -------------------------------- dlls/kernel32/locale.c | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 39 deletions(-)
diff --git a/dlls/kernel32/lcformat.c b/dlls/kernel32/lcformat.c index 2c53f5dfde9..e029f328544 100644 --- a/dlls/kernel32/lcformat.c +++ b/dlls/kernel32/lcformat.c @@ -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; -} diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c index 4c815be43cc..d46a2aa1580 100644 --- a/dlls/kernel32/locale.c +++ b/dlls/kernel32/locale.c @@ -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.@) */