ref: 2bcadff204dac8630acc5b9c0040ed7c0e399ad4
parent: 0439392a79b0f9b402c4fb34a5b3fb914f43c99c
author: Martin Storsjö <martin@martin.st>
date: Sun Jan 26 10:04:14 EST 2014
Use WelsGetTimeOfDay and WelsStrftime instead of LOCALTIME/FTIME/strftime
--- a/codec/common/crt_util_safe_x.h
+++ b/codec/common/crt_util_safe_x.h
@@ -420,14 +420,10 @@
#if defined(WIN32) && defined(_MSC_VER)
#if _MSC_VER >= 1500 // VS2008
-#define LOCALTIME localtime_s
-#define FTIME _ftime_s
#define STRNCPY strncpy_s
#define STRCAT strcat_s
#define STRNLEN strnlen_s
#else // mainly for VC6
-#define LOCALTIME localtime
-#define FTIME _ftime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe
#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe
@@ -435,7 +431,6 @@
#else//__GNUC__
-#define LOCALTIME localtime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe
#define STRNLEN wels_strnlen_s // override s.t.r.n.l.e.n here for safe
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -140,36 +140,9 @@
int32_t iBufLeft = kiBufSize - iBufUsed;
if (pEncCtx) {
- time_t l_time;
-#if defined(_WIN32) && defined(_MSC_VER)
-#if _MSC_VER >= 1500
- struct tm t_now;
-#else//VC6
- struct tm* t_now;
-#endif//_MSC_VER >= 1500
-#else//__GNUC__
- struct tm* t_now;
-#endif//WIN32
+ SWelsTime tTime;
-#if defined( _WIN32 ) && defined(_MSC_VER)
- struct _timeb tb;
-
- time (&l_time);
-#if _MSC_VER >= 1500
- LOCALTIME (&t_now, &l_time);
-#else
- t_now = LOCALTIME (&l_time);
- if (NULL == t_now) {
- return;
- }
-#endif//_MSC_VER >= 1500
- FTIME (&tb);
-#elif defined( __GNUC__ )
- struct timeval tv;
- time (&l_time);
- t_now = (struct tm*)LOCALTIME (&l_time);
- gettimeofday (&tv, NULL);
-#endif//WIN32
+ WelsGetTimeOfDay(&tTime);
iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;
@@ -209,11 +182,7 @@
}
if (iBufLeft > 0) {
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1500)
- iCurUsed = strftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", &t_now);
-#else
- iCurUsed = strftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", t_now);
-#endif//WIN32..
+ iCurUsed = WelsStrftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", &tTime);
if (iCurUsed > 0) {
iBufUsed += iCurUsed;
iBufLeft -= iCurUsed;
@@ -223,12 +192,7 @@
}
if (iBufLeft > 0) {
-#if defined (_WIN32)
- iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
-#elif defined (__GNUC__)
- iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ",
- static_cast<unsigned int> (tv.tv_usec / 1000)); // confirmed_safe_unsafe_usage
-#endif//WIN32
+ iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tTime.millitm); // confirmed_safe_unsafe_usage
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;
iBufLeft -= iCurUsed;
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -86,37 +86,10 @@
#endif//OUTPUT_BIT_STREAM
#ifdef OUTPUT_BIT_STREAM
- time_t tTime;
+ SWelsTime tTime;
-#if defined( _WIN32 )
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
- struct tm tTimeNow;
-#else
- struct tm* tTimeNow;
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
- struct _timeb tTimeb;
+ WelsGetTimeOfDay(&tTime);
- time (&tTime);
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
- LOCALTIME (&tTimeNow, &tTime);
-#else
- tTimeNow = LOCALTIME (&tTime);
- if (NULL == tTimeNow)
- return;
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
- FTIME (&tTimeb);
-#elif defined( __GNUC__ )
- struct tm* tTimeNow;
- struct timeval tTimev;
- time (&tTime);
- tTimeNow = (struct tm*)localtime (&tTime);
- gettimeofday (&tTimev, NULL);
-#endif//WIN32
-
iCurUsed = WelsSnprintf (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
iCurUsedSize = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
@@ -126,19 +99,7 @@
iBufferLeft -= iCurUsed;
}
if (iBufferLeft > 0) {
-#if defined(_GNUC__)
- iCurUsed = strftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", tTimeNow);
-#else
-#if defined(_MSC_VER)
- iCurUsed = strftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S",
-#if _MSC_VER>=1500
- & tTimeNow
-#else
- tTimeNow
-#endif//_MSC_VER>=1500
- );
-#endif//_MSC_VER
-#endif//__GNUC__
+ iCurUsed = WelsStrftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", &tTime);
iBufferUsed += iCurUsed;
iBufferLeft -= iCurUsed;
}
@@ -148,29 +109,14 @@
iBufferLeftSize -= iCurUsedSize;
}
if (iBufferLeftSize > 0) {
-#if defined(_GNUC__)
- iCurUsedSize = strftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", tTimeNow);
-#else
-#if defined(_MSC_VER)
- iCurUsedSize = strftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S",
-#if _MSC_VER>=1500
- & tTimeNow
-#else
- tTimeNow
-#endif//_MSC_VER>=1500
- );
-#endif//_MSC_VER
-#endif//__GNUC__
+ iCurUsedSize = WelsStrftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", &tTime);
iBufferUsedSize += iCurUsedSize;
iBufferLeftSize -= iCurUsedSize;
}
if (iBufferLeft > 0) {
-#ifdef _WIN32
- iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
-#else
- iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
-#endif//WIN32
+ iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264",
+ WelsGetMillisecond(&tTime));
if (iCurUsed > 0) {
iBufferUsed += iCurUsed;
iBufferLeft -= iCurUsed;
@@ -178,11 +124,8 @@
}
if (iBufferLeftSize > 0) {
-#ifdef _WIN32
- iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
-#else
- iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
-#endif//WIN32
+ iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len",
+ WelsGetMillisecond(&tTime));
if (iCurUsedSize > 0) {
iBufferUsedSize += iCurUsedSize;
iBufferLeftSize -= iCurUsedSize;