use built in VC8 time functions instead of our (almost certainly broken) ones for wxWinCE

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43076 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-11-04 23:27:15 +00:00
parent 83e8b44cc0
commit e09080ec62
3 changed files with 68 additions and 13 deletions

View File

@@ -4,8 +4,8 @@
* Missing time functions and structures for use under WinCE
*/
#ifndef __WINCE_TIME_
#define __WINCE_TIME_
#ifndef _WX_MSW_WINCE_TIME_H_
#define _WX_MSW_WINCE_TIME_H_
#ifndef _TM_DEFINED
@@ -26,23 +26,28 @@ struct tm {
extern "C"
{
struct tm * __cdecl localtime(const time_t *);
time_t __cdecl time(time_t *);
time_t __cdecl mktime(struct tm *);
// VC8 CRT provides the other functions
#if !defined(__VISUALC__) || (__VISUALC__ < 1400)
struct tm * __cdecl localtime(const time_t *);
struct tm * __cdecl gmtime(const time_t *);
#define _tcsftime wcsftime
size_t __cdecl wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *);
}
extern long timezone;
#endif // !VC8
}
#endif // !_TM_DEFINED
#endif // __WINCE_TIME_
#endif // _WX_MSW_WINCE_TIME_H_

View File

@@ -141,6 +141,13 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter<wxDateTime> , wxFromStringCon
#include <wtime.h>
#endif
// define a special symbol for VC8 instead of writing tests for 1400 repeatedly
#ifdef __VISUALC__
#if __VISUALC__ >= 1400
#define __VISUALC8__
#endif
#endif
#if !defined(WX_TIMEZONE) && !defined(WX_GMTOFF_IN_TM)
#if defined(__WXPALMOS__)
#define WX_GMTOFF_IN_TM
@@ -166,11 +173,30 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter<wxDateTime> , wxFromStringCon
#define WX_TIMEZONE wxGetTimeZone()
#elif defined(__DARWIN__)
#define WX_GMTOFF_IN_TM
#elif defined(__WXWINCE__) && defined(__VISUALC8__)
#define WX_TIMEZONE _timezone
#else // unknown platform - try timezone
#define WX_TIMEZONE timezone
#endif
#endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM
// NB: VC8 safe time functions could/should be used for wxMSW as well probably
#if defined(__WXWINCE__) && defined(__VISUALC8__)
struct tm *wxLocaltime_r(const time_t *t, struct tm* tm)
{
__time64_t t64 = *t;
return _localtime64_s(tm, &t64) == 0 ? tm : NULL;
}
struct tm *wxGmtime_r(const time_t* t, struct tm* tm)
{
__time64_t t64 = *t;
return _gmtime64_s(tm, &t64) == 0 ? tm : NULL;
}
#else // !wxWinCE with VC8
#if (!defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)) && wxUSE_THREADS && !defined(__WINDOWS__)
static wxMutex timeLock;
#endif
@@ -186,7 +212,7 @@ struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp)
memcpy(temp, localtime(ticks), sizeof(struct tm));
return temp;
}
#endif
#endif // !HAVE_LOCALTIME_R
#ifndef HAVE_GMTIME_R
struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp)
@@ -199,7 +225,9 @@ struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp)
memcpy(temp, gmtime(ticks), sizeof(struct tm));
return temp;
}
#endif
#endif // !HAVE_GMTIME_R
#endif // wxWinCE with VC8/other platforms
// ----------------------------------------------------------------------------
// macros

View File

@@ -2,7 +2,7 @@
// Name: src/msw/wince/time.cpp
// Purpose: Implements missing time functionality for WinCE
// Author: Marco Cavallini (MCK) - wx@koansoftware.com
// Modified by:
// Modified by: Vadim Zeitlin for VC8 support
// Created: 31-08-2003
// RCS-ID: $Id$
// Copyright: (c) Marco Cavallini
@@ -30,6 +30,30 @@
#include "wx/msw/wince/time.h"
#if defined(__VISUALC__) && (__VISUALC__ >= 1400)
// VC8 does provide the time functions but not the standard ones
#include <altcecrt.h>
time_t __cdecl time(time_t *t)
{
__time64_t t64;
if ( !_time64(&t64) )
return (time_t)-1;
if ( t )
*t = (time_t)t64;
return (time_t)t64;
}
time_t __cdecl mktime(struct tm *t)
{
return (time_t)_mktime64(t);
}
#else // !VC8
/////////////////////////////////////////////////////////////////////////////////////////////
// //
// strftime() - taken from OpenBSD //
@@ -499,7 +523,6 @@ extern "C"
/* Not needed in VS Studio 2005 */
#if !(__VISUALC__ >= 1400)
size_t wcsftime(wchar_t *s,
const size_t maxsize,
const wchar_t *format,
@@ -516,7 +539,6 @@ size_t wcsftime(wchar_t *s,
return sz;
}
#endif
} /* extern "C" */
@@ -737,4 +759,4 @@ time_t __cdecl mktime(struct tm *t)
} // extern "C"
#endif // VC8/!VC8