msvcrt: Added _strtime_s and _wstrtime_s implementation.

oldstable
Piotr Caban 2010-08-27 01:45:31 +02:00 committed by Alexandre Julliard
parent 3fec8d9e05
commit 7d0c04d31c
8 changed files with 95 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -325,6 +325,28 @@ char* CDECL _strtime(char* time)
return 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.@)
*/
@ -337,6 +359,28 @@ MSVCRT_wchar_t* CDECL _wstrtime(MSVCRT_wchar_t* time)
return 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.@)
*/

View File

@ -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); }

View File

@ -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); }