Piotr Caban : msvcrt: Added _strtime_s and _wstrtime_s implementation.
Alexandre Julliard
julliard at winehq.org
Fri Aug 27 11:11:18 CDT 2010
Module: wine
Branch: master
Commit: 7d0c04d31c1288ed38bb71afb3d054edf06849d2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=7d0c04d31c1288ed38bb71afb3d054edf06849d2
Author: Piotr Caban <piotr at codeweavers.com>
Date: Fri Aug 27 01:45:31 2010 +0200
msvcrt: Added _strtime_s and _wstrtime_s implementation.
---
dlls/msvcr100/msvcr100.spec | 4 +-
dlls/msvcr80/msvcr80.spec | 4 +-
dlls/msvcr90/msvcr90.spec | 4 +-
dlls/msvcrt/msvcrt.spec | 4 +-
dlls/msvcrt/tests/time.c | 46 +++++++++++++++++++++++++++++++++++++-----
dlls/msvcrt/time.c | 44 +++++++++++++++++++++++++++++++++++++++++
include/msvcrt/time.h | 2 +
include/msvcrt/wchar.h | 1 +
8 files changed, 95 insertions(+), 14 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 771b2e0..c9c248b 100644
--- a/dlls/msvcr100/msvcr100.spec
+++ b/dlls/msvcr100/msvcr100.spec
@@ -1156,7 +1156,7 @@
@ cdecl _strset(str long) msvcrt._strset
@ stub _strset_s
@ cdecl _strtime(ptr) msvcrt._strtime
-@ stub _strtime_s
+@ cdecl _strtime_s(ptr long) msvcrt._strtime_s
@ cdecl _strtod_l(str ptr ptr) msvcrt._strtod_l
@ cdecl _strtoi64(str ptr long) msvcrt._strtoi64
@ cdecl _strtoi64_l(str ptr long ptr) msvcrt._strtoi64_l
@@ -1400,7 +1400,7 @@
@ cdecl _wstrdate(ptr) msvcrt._wstrdate
@ stub _wstrdate_s
@ cdecl _wstrtime(ptr) msvcrt._wstrtime
-@ stub _wstrtime_s
+@ cdecl _wstrtime_s(ptr long) msvcrt._wstrtime_s
@ cdecl _wsystem(wstr) msvcrt._wsystem
@ cdecl _wtempnam(wstr wstr) msvcrt._wtempnam
@ stub _wtmpnam
diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec
index 02ba355..de58182 100644
--- a/dlls/msvcr80/msvcr80.spec
+++ b/dlls/msvcr80/msvcr80.spec
@@ -1010,7 +1010,7 @@
@ cdecl _strset(str long) msvcrt._strset
@ stub _strset_s
@ cdecl _strtime(ptr) msvcrt._strtime
-@ stub _strtime_s
+@ cdecl _strtime_s(ptr long) msvcrt._strtime_s
@ cdecl _strtod_l(str ptr ptr) msvcrt._strtod_l
@ cdecl _strtoi64(str ptr long) msvcrt._strtoi64
@ cdecl _strtoi64_l(str ptr long ptr) msvcrt._strtoi64_l
@@ -1256,7 +1256,7 @@
@ cdecl _wstrdate(ptr) msvcrt._wstrdate
@ stub _wstrdate_s
@ cdecl _wstrtime(ptr) msvcrt._wstrtime
-@ stub _wstrtime_s
+@ cdecl _wstrtime_s(ptr long) msvcrt._wstrtime_s
@ cdecl _wsystem(wstr) msvcrt._wsystem
@ cdecl _wtempnam(wstr wstr) msvcrt._wtempnam
@ stub _wtmpnam
diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec
index a5c50b1..b3f3801 100644
--- a/dlls/msvcr90/msvcr90.spec
+++ b/dlls/msvcr90/msvcr90.spec
@@ -996,7 +996,7 @@
@ cdecl _strset(str long) msvcrt._strset
@ stub _strset_s
@ cdecl _strtime(ptr) msvcrt._strtime
-@ stub _strtime_s
+@ cdecl _strtime_s(ptr long) msvcrt._strtime_s
@ cdecl _strtod_l(str ptr ptr) msvcrt._strtod_l
@ cdecl _strtoi64(str ptr long) msvcrt._strtoi64
@ cdecl _strtoi64_l(str ptr long ptr) msvcrt._strtoi64_l
@@ -1240,7 +1240,7 @@
@ cdecl _wstrdate(ptr) msvcrt._wstrdate
@ stub _wstrdate_s
@ cdecl _wstrtime(ptr) msvcrt._wstrtime
-@ stub _wstrtime_s
+@ cdecl _wstrtime_s(ptr long) msvcrt._wstrtime_s
@ cdecl _wsystem(wstr) msvcrt._wsystem
@ cdecl _wtempnam(wstr wstr) msvcrt._wtempnam
@ stub _wtmpnam
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 254f967..753ca7a 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -931,7 +931,7 @@
@ cdecl _strset(str long)
# stub _strset_s
@ cdecl _strtime(ptr)
-# stub _strtime_s
+@ cdecl _strtime_s(ptr long)
@ cdecl _strtod_l(str ptr ptr) MSVCRT_strtod_l
@ cdecl _strtoi64(str ptr long) MSVCRT_strtoi64
@ cdecl _strtoi64_l(str ptr long ptr) MSVCRT_strtoi64_l
@@ -1170,7 +1170,7 @@
@ cdecl _wstrdate(ptr)
# stub _wstrdate_s
@ cdecl _wstrtime(ptr)
-# stub _wstrtime_s
+@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr)
# stub _wtempnam_dbg
diff --git a/dlls/msvcrt/tests/time.c b/dlls/msvcrt/tests/time.c
index 7f0a80b..4dfeb64 100644
--- a/dlls/msvcrt/tests/time.c
+++ b/dlls/msvcrt/tests/time.c
@@ -25,6 +25,7 @@
#include <stdlib.h> /*setenv*/
#include <stdio.h> /*printf*/
+#include <errno.h>
#define SECSPERDAY 86400
#define SECSPERHOUR 3600
@@ -32,6 +33,19 @@
#define MINSPERHOUR 60
#define HOURSPERDAY 24
+static __time32_t (__cdecl *p_mkgmtime32)(struct tm*);
+static struct tm* (__cdecl *p_gmtime32)(__time32_t*);
+static errno_t (__cdecl *p_strtime_s)(char*,size_t);
+
+static void init(void)
+{
+ HMODULE hmod = GetModuleHandleA("msvcrt.dll");
+
+ p_gmtime32 = (void*)GetProcAddress(hmod, "_gmtime32");
+ p_mkgmtime32 = (void*)GetProcAddress(hmod, "_mkgmtime32");
+ p_strtime_s = (void*)GetProcAddress(hmod, "_strtime_s");
+}
+
static int get_test_year(time_t *start)
{
time_t now = time(NULL);
@@ -54,14 +68,9 @@ static void test_ctime(void)
}
static void test_gmtime(void)
{
- static __time32_t (__cdecl *p_mkgmtime32)(struct tm*);
- static struct tm* (__cdecl *p_gmtime32)(__time32_t*);
-
- HMODULE hmod = GetModuleHandleA("msvcrt.dll");
__time32_t valid, gmt;
struct tm* gmt_tm;
- p_gmtime32 = (void*)GetProcAddress(hmod, "_gmtime32");
if(!p_gmtime32) {
win_skip("Skipping _gmtime32 tests\n");
return;
@@ -81,7 +90,6 @@ static void test_gmtime(void)
gmt_tm->tm_year, gmt_tm->tm_mon, gmt_tm->tm_yday, gmt_tm->tm_mday, gmt_tm->tm_wday,
gmt_tm->tm_hour, gmt_tm->tm_min, gmt_tm->tm_sec, gmt_tm->tm_isdst);
- p_mkgmtime32 = (void*)GetProcAddress(hmod, "_mkgmtime32");
if(!p_mkgmtime32) {
win_skip("Skipping _mkgmtime32 tests\n");
return;
@@ -300,6 +308,7 @@ static void test_strtime(void)
{
char time[16], * result;
int hour, minute, second, count, len;
+ errno_t err;
result = _strtime(time);
ok(result == time, "Wrong return value\n");
@@ -307,6 +316,29 @@ static void test_strtime(void)
ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
count = sscanf(time, "%02d:%02d:%02d", &hour, &minute, &second);
ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
+
+ if(!p_strtime_s) {
+ win_skip("Skipping _strtime_s tests\n");
+ return;
+ }
+
+ errno = 0;
+ err = p_strtime_s(NULL, 0);
+ ok(err == EINVAL, "err = %d\n", err);
+ ok(errno == EINVAL, "errno = %d\n", errno);
+
+ err = p_strtime_s(NULL, 1);
+ ok(err == EINVAL, "err = %d\n", err);
+ ok(errno == EINVAL, "errno = %d\n", errno);
+
+ time[0] = 'x';
+ err = p_strtime_s(time, 8);
+ ok(err == ERANGE, "err = %d\n", err);
+ ok(errno == ERANGE, "errno = %d\n", errno);
+ ok(time[0] == '\0', "time[0] != '\\0'\n");
+
+ err = p_strtime_s(time, 9);
+ ok(err == 0, "err = %x\n", err);
}
static void test_wstrdate(void)
@@ -339,6 +371,8 @@ static void test_wstrtime(void)
START_TEST(time)
{
+ init();
+
test_ctime();
test_gmtime();
test_mktime();
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 2e8828c..b0ad20d 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -326,6 +326,28 @@ char* CDECL _strtime(char* time)
}
/*********************************************************************
+ * _strtime_s (MSVCRT.@)
+ */
+int CDECL _strtime_s(char* time, MSVCRT_size_t size)
+{
+ if(time && size)
+ time[0] = '\0';
+
+ if(!time) {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return MSVCRT_EINVAL;
+ }
+
+ if(size < 9) {
+ *MSVCRT__errno() = MSVCRT_ERANGE;
+ return MSVCRT_ERANGE;
+ }
+
+ _strtime(time);
+ return 0;
+}
+
+/*********************************************************************
* _wstrtime (MSVCRT.@)
*/
MSVCRT_wchar_t* CDECL _wstrtime(MSVCRT_wchar_t* time)
@@ -338,6 +360,28 @@ MSVCRT_wchar_t* CDECL _wstrtime(MSVCRT_wchar_t* time)
}
/*********************************************************************
+ * _wstrtime_s (MSVCRT.@)
+ */
+int CDECL _wstrtime_s(MSVCRT_wchar_t* time, MSVCRT_size_t size)
+{
+ if(time && size)
+ time[0] = '\0';
+
+ if(!time) {
+ *MSVCRT__errno() = MSVCRT_EINVAL;
+ return MSVCRT_EINVAL;
+ }
+
+ if(size < 9) {
+ *MSVCRT__errno() = MSVCRT_ERANGE;
+ return MSVCRT_ERANGE;
+ }
+
+ _wstrtime(time);
+ return 0;
+}
+
+/*********************************************************************
* clock (MSVCRT.@)
*/
MSVCRT_clock_t CDECL MSVCRT_clock(void)
diff --git a/include/msvcrt/time.h b/include/msvcrt/time.h
index 4c44c7b..2175526 100644
--- a/include/msvcrt/time.h
+++ b/include/msvcrt/time.h
@@ -90,6 +90,7 @@ unsigned __cdecl _getsystime(struct tm*);
unsigned __cdecl _setsystime(struct tm*,unsigned);
char* __cdecl _strdate(char*);
char* __cdecl _strtime(char*);
+errno_t __cdecl _strtime_s(char*,size_t);
void __cdecl _tzset(void);
char* __cdecl asctime(const struct tm*);
@@ -130,6 +131,7 @@ wchar_t* __cdecl _wctime32(const __time32_t*);
wchar_t* __cdecl _wctime64(const __time64_t*);
wchar_t* __cdecl _wstrdate(wchar_t*);
wchar_t* __cdecl _wstrtime(wchar_t*);
+errno_t __cdecl _wstrtime_s(wchar_t*,size_t);
#ifndef _USE_32BIT_TIME_T
static inline wchar_t* _wctime(const time_t *t) { return _wctime64(t); }
diff --git a/include/msvcrt/wchar.h b/include/msvcrt/wchar.h
index 41ff3ff..c9b12fb 100644
--- a/include/msvcrt/wchar.h
+++ b/include/msvcrt/wchar.h
@@ -397,6 +397,7 @@ wchar_t* __cdecl _wctime32(const __time32_t*);
wchar_t* __cdecl _wctime64(const __time64_t*);
wchar_t* __cdecl _wstrdate(wchar_t*);
wchar_t* __cdecl _wstrtime(wchar_t*);
+errno_t __cdecl _wstrtime_s(wchar_t*,size_t);
#ifndef _USE_32BIT_TIME_T
static inline wchar_t* _wctime(const time_t *t) { return _wctime64(t); }
More information about the wine-cvs
mailing list