Piotr Caban : msvcrt: Rewrite wasctime function.

Alexandre Julliard julliard at winehq.org
Wed Apr 11 12:56:47 CDT 2012


Module: wine
Branch: master
Commit: 2ca9a73a319585f71d8b09657ffd8d0affeeac0f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2ca9a73a319585f71d8b09657ffd8d0affeeac0f

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Apr 11 15:21:48 2012 +0200

msvcrt: Rewrite wasctime function.

---

 dlls/msvcrt/time.c |   46 +++++++++++++++++++++++-----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 90dc790..882b7bb 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -954,19 +954,20 @@ int CDECL MSVCRT_asctime_s(char* time, MSVCRT_size_t size, const struct MSVCRT_t
 MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm)
 {
     thread_data_t *data = msvcrt_get_thread_data();
-    struct tm tm;
-    char buffer[30];
+    char buffer[26];
 
-    msvcrt_tm_to_unix( &tm, mstm );
+    if(!data->wasctime_buffer) {
+        data->wasctime_buffer = MSVCRT_malloc(26*sizeof(MSVCRT_wchar_t));
+        if(!data->wasctime_buffer) {
+            *MSVCRT__errno() = MSVCRT_ENOMEM;
+            return NULL;
+        }
+    }
 
-    if (!data->wasctime_buffer)
-        data->wasctime_buffer = MSVCRT_malloc( 30*sizeof(MSVCRT_wchar_t) ); /* ought to be enough */
-#ifdef HAVE_ASCTIME_R
-    asctime_r( &tm, buffer );
-#else
-    strcpy( buffer, asctime(&tm) );
-#endif
-    MultiByteToWideChar( CP_UNIXCP, 0, buffer, -1, data->wasctime_buffer, 30 );
+    if(!asctime_buf(buffer, mstm))
+        return NULL;
+
+    MultiByteToWideChar(CP_ACP, 0, buffer, -1, data->wasctime_buffer, 26);
     return data->wasctime_buffer;
 }
 
@@ -975,23 +976,22 @@ MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm)
  */
 int CDECL MSVCRT__wasctime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size, const struct MSVCRT_tm *mstm)
 {
-    WCHAR* asc;
-    unsigned int len;
+    char buffer[26];
+    int ret;
 
-    if (!MSVCRT_CHECK_PMT(time != NULL) || !MSVCRT_CHECK_PMT(mstm != NULL)) {
+    if(!MSVCRT_CHECK_PMT(time != NULL)
+            || !MSVCRT_CHECK_PMT(mstm != NULL)
+            || !MSVCRT_CHECK_PMT(size >= 26)) {
+        if(time && size)
+            time[0] = 0;
         *MSVCRT__errno() = MSVCRT_EINVAL;
         return MSVCRT_EINVAL;
     }
 
-    asc = MSVCRT__wasctime(mstm);
-    len = (strlenW(asc) + 1) * sizeof(WCHAR);
-
-    if(!MSVCRT_CHECK_PMT(size >= len)) {
-        *MSVCRT__errno() = MSVCRT_ERANGE;
-        return MSVCRT_ERANGE;
-    }
-
-    strcpyW(time, asc);
+    ret = MSVCRT_asctime_s(buffer, sizeof(buffer), mstm);
+    if(!ret)
+        return ret;
+    MultiByteToWideChar(CP_ACP, 0, buffer, -1, time, size);
     return 0;
 }
 




More information about the wine-cvs mailing list