Alexandre Julliard : kernelbase: Reimplement GetDateFormatA().

Alexandre Julliard julliard at winehq.org
Wed May 4 16:14:43 CDT 2022


Module: wine
Branch: master
Commit: fc26407e8eb5016627cd238f4ff562732d5aeb0c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fc26407e8eb5016627cd238f4ff562732d5aeb0c

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed May  4 08:55:45 2022 +0200

kernelbase: Reimplement GetDateFormatA().

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/kernel32.spec     |  2 +-
 dlls/kernel32/lcformat.c        | 53 -----------------------------------------
 dlls/kernelbase/kernelbase.spec |  2 +-
 dlls/kernelbase/locale.c        | 29 ++++++++++++++++++++++
 4 files changed, 31 insertions(+), 55 deletions(-)

diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec
index ebe5559d615..bc292f62faa 100644
--- a/dlls/kernel32/kernel32.spec
+++ b/dlls/kernel32/kernel32.spec
@@ -640,7 +640,7 @@
 @ stdcall -norelay GetCurrentThreadId() KERNEL32_GetCurrentThreadId
 @ stdcall -import GetCurrentThreadStackLimits(ptr ptr)
 @ stdcall -arch=x86_64 GetCurrentUmsThread()
-@ stdcall GetDateFormatA(long long ptr str ptr long)
+@ stdcall -import GetDateFormatA(long long ptr str ptr long)
 @ stdcall -import GetDateFormatEx(wstr long ptr wstr ptr long wstr)
 @ stdcall -import GetDateFormatW(long long ptr wstr ptr long)
 @ stdcall GetDaylightFlag()
diff --git a/dlls/kernel32/lcformat.c b/dlls/kernel32/lcformat.c
index 21d14328449..8cadaf42246 100644
--- a/dlls/kernel32/lcformat.c
+++ b/dlls/kernel32/lcformat.c
@@ -727,59 +727,6 @@ static INT NLS_GetDateTimeFormatA(LCID lcid, DWORD dwFlags,
   return iRet;
 }
 
-/******************************************************************************
- * GetDateFormatA [KERNEL32.@]
- *
- * Format a date for a given locale.
- *
- * PARAMS
- *  lcid      [I] Locale to format for
- *  dwFlags   [I] LOCALE_ and DATE_ flags from "winnls.h"
- *  lpTime    [I] Date to format
- *  lpFormat  [I] Format string, or NULL to use the system defaults
- *  lpDateStr [O] Destination for formatted string
- *  cchOut    [I] Size of lpDateStr, or 0 to calculate the resulting size
- *
- * NOTES
- *  - If lpFormat is NULL, lpDateStr will be formatted according to the format
- *    details returned by GetLocaleInfoA() and modified by dwFlags.
- *  - lpFormat is a string of characters and formatting tokens. Any characters
- *    in the string are copied verbatim to lpDateStr, with tokens being replaced
- *    by the date values they represent.
- *  - The following tokens have special meanings in a date format string:
- *|  Token  Meaning
- *|  -----  -------
- *|  d      Single digit day of the month (no leading 0)
- *|  dd     Double digit day of the month
- *|  ddd    Short name for the day of the week
- *|  dddd   Long name for the day of the week
- *|  M      Single digit month of the year (no leading 0)
- *|  MM     Double digit month of the year
- *|  MMM    Short name for the month of the year
- *|  MMMM   Long name for the month of the year
- *|  y      Double digit year number (no leading 0)
- *|  yy     Double digit year number
- *|  yyyy   Four digit year number
- *|  gg     Era string, for example 'AD'.
- *  - To output any literal character that could be misidentified as a token,
- *    enclose it in single quotes.
- *  - The ANSI version of this function fails if lcid is Unicode only.
- *
- * RETURNS
- *  Success: The number of character written to lpDateStr, or that would
- *           have been written, if cchOut is 0.
- *  Failure: 0. Use GetLastError() to determine the cause.
- */
-INT WINAPI GetDateFormatA( LCID lcid, DWORD dwFlags, const SYSTEMTIME* lpTime,
-                           LPCSTR lpFormat, LPSTR lpDateStr, INT cchOut)
-{
-  TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",lcid, dwFlags, lpTime,
-        debugstr_a(lpFormat), lpDateStr, cchOut);
-
-  return NLS_GetDateTimeFormatA(lcid, dwFlags | DATE_DATEVARSONLY, lpTime,
-                                lpFormat, lpDateStr, cchOut);
-}
-
 /******************************************************************************
  *		GetTimeFormatA	[KERNEL32.@]
  *
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec
index 06744a79b1f..2ca7a036916 100644
--- a/dlls/kernelbase/kernelbase.spec
+++ b/dlls/kernelbase/kernelbase.spec
@@ -499,7 +499,7 @@
 @ stdcall -norelay GetCurrentThread() kernelbase_GetCurrentThread
 @ stdcall -norelay GetCurrentThreadId() kernelbase_GetCurrentThreadId
 @ stdcall GetCurrentThreadStackLimits(ptr ptr)
-@ stdcall GetDateFormatA(long long ptr str ptr long) kernel32.GetDateFormatA
+@ stdcall GetDateFormatA(long long ptr str ptr long)
 @ stdcall GetDateFormatEx(wstr long ptr wstr ptr long wstr)
 @ stdcall GetDateFormatW(long long ptr wstr ptr long)
 @ stdcall GetDeviceDriverBaseNameA(ptr ptr long)
diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c
index 01ccd3cc6b6..4057c462b89 100644
--- a/dlls/kernelbase/locale.c
+++ b/dlls/kernelbase/locale.c
@@ -7158,6 +7158,35 @@ int WINAPI GetCurrencyFormatEx( const WCHAR *name, DWORD flags, const WCHAR *val
 }
 
 
+/******************************************************************************
+ *           GetDateFormatA (KERNEL32.@)
+ */
+int WINAPI GetDateFormatA( LCID lcid, DWORD flags, const SYSTEMTIME *time,
+                           const char *format, char *buffer, int len )
+{
+    UINT cp = get_lcid_codepage( lcid, flags );
+    WCHAR formatW[128], output[128];
+    int ret;
+
+    TRACE( "(0x%04lx,0x%08lx,%p,%s,%p,%d)\n", lcid, flags, time, debugstr_a(format), buffer, len );
+
+    if (len < 0 || (len && !buffer))
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return 0;
+    }
+    if (format)
+    {
+        MultiByteToWideChar( cp, 0, format, -1, formatW, ARRAY_SIZE(formatW) );
+        ret = GetDateFormatW( lcid, flags, time, formatW, output, ARRAY_SIZE(output) );
+    }
+    else ret = GetDateFormatW( lcid, flags, time, NULL, output, ARRAY_SIZE(output) );
+
+    if (ret) ret = WideCharToMultiByte( cp, 0, output, -1, buffer, len, 0, 0 );
+    return ret;
+}
+
+
 /***********************************************************************
  *	GetDateFormatW  (kernelbase.@)
  */




More information about the wine-cvs mailing list