From a46eec6cea1ef18c4dc1d22055a3d35687e16682 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Mon, 12 Apr 2004 10:19:43 +0000 Subject: [PATCH] - RosGetTimeFormat(): replace "if (!cchTime) ; else ..." by "if (cchTime)" and adjust comment - Kohn Emil Dan : 1) RosGetTimeFormat() has a small bug. The last statement should be return nPos; and not return cchTime; 2) GetTimeFormatA() is not implemented. I have written an implementation for it, which calls GetTimeFormatW(), and converts the string parameters back and forth. (committed with adjustments for correct error handling) svn path=/trunk/; revision=9092 --- reactos/lib/kernel32/misc/lang.c | 89 ++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/reactos/lib/kernel32/misc/lang.c b/reactos/lib/kernel32/misc/lang.c index 398d64db3a9..d168a9a03de 100644 --- a/reactos/lib/kernel32/misc/lang.c +++ b/reactos/lib/kernel32/misc/lang.c @@ -1,4 +1,4 @@ -/* $Id: lang.c,v 1.12 2004/01/28 23:03:59 gdalsnes Exp $ +/* $Id: lang.c,v 1.13 2004/04/12 10:19:43 mf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT : ReactOS user mode libraries @@ -1235,18 +1235,20 @@ INT RosGetTimeFormat(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpTime, LPCWS } } - if (!cchTime) - /* We are counting */; - else if (nPos >= cchTime) + /* Are we not only counting? */ + if (cchTime) { - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return 0; + if (nPos >= cchTime) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return 0; + } + else + lpTimeStr[nPos] = '\0'; } - else - lpTimeStr[nPos] = '\0'; nPos++; - return cchTime; + return nPos; } /* @@ -1302,7 +1304,7 @@ GetTimeFormatW ( /* - * @unimplemented + * @implemented */ int STDCALL @@ -1314,10 +1316,75 @@ GetTimeFormatA ( LPSTR lpTimeStr, int cchTime ) -{ return sizeof(lpTimeStr); +{ + LPWSTR lpFormatU = NULL; + LPWSTR lpTimeStrU; + int numCharsU; + int retVal; + + if (lpFormat != NULL) { + /* First just determine the number of necessary bytes + for the unicode string */ + int numBytes = MultiByteToWideChar(CP_ACP, + MB_ERR_INVALID_CHARS, + lpFormat, + -1, + NULL, + 0); + + /* Try really hard not to fail due to format problems + If there are any problems with the format pass NULL + to GetTimeFormatW() */ + if (numBytes > 0) { + lpFormatU = HeapAlloc(GetProcessHeap(),0,numBytes); + + if (lpFormatU != NULL) + MultiByteToWideChar(CP_ACP, + 0, + lpFormat, + -1, + lpFormatU, + numBytes); + } + } + + /* Just get the number of characters needed to store the + Unicode output */ + numCharsU = GetTimeFormatW(Locale,dwFlags,lpTime,lpFormatU,NULL,0); + + if (numCharsU == 0) { + if (lpFormatU != NULL) + HeapFree(GetProcessHeap(),0,lpFormatU); + return 0; + } + + lpTimeStrU = HeapAlloc(GetProcessHeap(),0,numCharsU*sizeof(WCHAR)); + if (lpTimeStrU == NULL) { + if (lpFormatU != NULL) + HeapFree(GetProcessHeap(),0,lpFormatU); + return 0; + } + + if (GetTimeFormatW(Locale,dwFlags,lpTime,lpFormatU,lpTimeStrU,numCharsU)) + /* Convert the output string to ANSI */ + retVal = WideCharToMultiByte(CP_ACP, + 0, + lpTimeStrU, + numCharsU, + lpTimeStr, + cchTime, + NULL, + NULL); + + HeapFree(GetProcessHeap(),0,lpTimeStrU); + if (lpFormatU != NULL) + HeapFree(GetProcessHeap(),0,lpFormatU); + + return retVal; } + #ifndef _OLE2NLS_IN_BUILD_ /*