[Turqstat-commits] [SCM] Turquoise SuperStat - http://www.softwolves.pp.se/sw/software/turquoise branch, xturqstat-win32, updated. release-3.0-2-24-g32a20f2

Peter Karlsson peter at softwolves.pp.se
Mon Jun 2 19:17:55 UTC 2008


The following commit has been merged in the xturqstat-win32 branch:
commit 47bdb8282956972fc2414725f88e7f3c32839530
Author: Peter Karlsson <peter at softwolves.pp.se>
Date:   Mon Jun 2 21:01:20 2008 +0200

    Use the proper locale date formatter in the main UI.
    
    strftime() does not work properly on MSCRT, so use the localetimestring()
    function, if available.
    
    There is currently a problem with the GetDateFormatA() call, it seems,
    so check for error returns from it to avoid non-terminated strings.

diff --git a/ChangeLog b/ChangeLog
index 8132b4b..c6df20b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,13 @@
 2008-06-02 - Peter Karlsson <peter at softwolves.pp.se>
+  qtgui.cpp
   qtlist.cpp
   qtlist.h
   qtreport.cpp
     Porting to Qt 4.
 
+  utility.cpp
+    Workaround for WinAPI problems.
+
 2008-04-18 - Peter Karlsson <peter at softwolves.pp.se>
   visualc/
     Split project files so that common files reside in a common project.
diff --git a/qtgui.cpp b/qtgui.cpp
index a2e637c..e9658a4 100644
--- a/qtgui.cpp
+++ b/qtgui.cpp
@@ -536,12 +536,20 @@ void InfoWindow::update()
     char timebuf[64];
 	time_t earliest = m_engine_p->GetEarliestWritten();
     struct tm *p1 = localtime(&earliest);
+#if defined(HAVE_LOCALE_H) || defined(HAVE_OS2_COUNTRYINFO) || defined(HAVE_WIN32_LOCALEINFO)
+	localetimestring(p1, sizeof (timebuf), timebuf);
+#else
     strftime(timebuf, 64, "%x", p1);
+#endif
 	m_earliestwritten_p->setText(timebuf);
 
 	time_t latest = m_engine_p->GetLastWritten();
     struct tm *p2 = localtime(&latest);
+#if defined(HAVE_LOCALE_H) || defined(HAVE_OS2_COUNTRYINFO) || defined(HAVE_WIN32_LOCALEINFO)
+	localetimestring(p2, sizeof (timebuf), timebuf);
+#else
     strftime(timebuf, 64, "%x", p2);
+#endif
 	m_latestwritten_p->setText(timebuf);
 }
 
diff --git a/utility.cpp b/utility.cpp
index edf3d97..17f9b95 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -409,6 +409,7 @@ void localetimestring(const struct tm *time, size_t len, char *out)
     wintime.wDay        = time->tm_mday;
 
     // First print date
+	out[0] = 0;
     int usedlength =
 		GetDateFormatA(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &wintime, NULL,
 		               out, static_cast<int>(len));
@@ -423,7 +424,13 @@ void localetimestring(const struct tm *time, size_t len, char *out)
     }
 
     // Then print time
-    GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &wintime, NULL, out, static_cast<int>(len));
+    int usedlength2 =
+		GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &wintime, NULL, out, static_cast<int>(len));
+	if (usedlength && usedlength2)
+	{
+		// If GetTimeFormat() fails, we do need a null-terminated string
+		out[-1] = 0;
+	}
 }
 #elif defined(HAVE_LOCALE_H)
 void localetimestring(const struct tm *time, size_t len, char *out)

-- 
Turquoise SuperStat - http://www.softwolves.pp.se/sw/software/turquoise



More information about the Turqstat-commits mailing list