[Gnucash-changes] r14081 - gnucash/trunk - Use localtime_r only when HAVE_LOCALTIME_R is defined. Might be undefined on some weird systems out there, e.g. windows/mingw32.

Christian Stimming cstim at cvs.gnucash.org
Tue May 16 05:32:48 EDT 2006


Author: cstim
Date: 2006-05-16 05:32:47 -0400 (Tue, 16 May 2006)
New Revision: 14081
Trac: http://svn.gnucash.org/trac/changeset/14081

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/lib/libqof/qof/gnc-date.c
Log:
Use localtime_r only when HAVE_LOCALTIME_R is defined. Might be undefined on some weird systems out there, e.g. windows/mingw32.



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-05-15 22:21:06 UTC (rev 14080)
+++ gnucash/trunk/ChangeLog	2006-05-16 09:32:47 UTC (rev 14081)
@@ -1,3 +1,11 @@
+2006-05-16  Christian Stimming <stimming at tuhh.de>
+
+	* lib/libqof/qof/gnc-date.c (timespecCanonicalDayTime)
+	(qof_print_date_buff, dateSeparator, gnc_timespec_last_mday)
+	(gnc_timespec2dmy): Use localtime_r only when HAVE_LOCALTIME_R is
+	defined. Might be undefined on some weird systems out there,
+	e.g. windows/mingw32.
+
 2006-05-15  Derek Atkins  <derek at ihtfp.com>
 
 	* src/import-export/test/Makefile.am:

Modified: gnucash/trunk/lib/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.c	2006-05-15 22:21:06 UTC (rev 14080)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.c	2006-05-16 09:32:47 UTC (rev 14081)
@@ -249,9 +249,17 @@
 timespecCanonicalDayTime(Timespec t)
 {
   struct tm tm;
+#ifndef HAVE_LOCALTIME_R
+  struct tm *result;
+#endif
   Timespec retval;
   time_t t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
+#ifndef HAVE_LOCALTIME_R
+  result = localtime(&t_secs);
+  tm = *result;
+#else
   localtime_r(&t_secs, &tm);
+#endif
   gnc_tm_set_day_middle(&tm);
   retval.tv_sec = mktime(&tm);
   retval.tv_nsec = 0;
@@ -495,16 +503,24 @@
 size_t
 qof_print_date_buff (char * buff, size_t len, time_t t)
 {
-  struct tm theTime;
+#ifdef HAVE_LOCALTIME_R
+  struct tm theTime_tm; 
+#endif
+  struct tm *theTime;
 
   if (!buff) return 0 ;
 
-  localtime_r(&t, &theTime);
+#ifdef HAVE_LOCALTIME_R
+  localtime_r (&t, &theTime_tm);
+  theTime = &theTime_tm;
+#else
+  theTime = localtime (&t);
+#endif
 
   return qof_print_date_dmy_buff (buff, len,
-                   theTime.tm_mday, 
-                   theTime.tm_mon + 1,
-                   theTime.tm_year + 1900);
+                   theTime->tm_mday, 
+                   theTime->tm_mon + 1,
+                   theTime->tm_year + 1900);
 }
 
 size_t
@@ -938,13 +954,21 @@
       else
       { /* Make a guess */
         unsigned char string[256];
-        struct tm tm;
+        struct tm *tm;
+#ifdef HAVE_LOCALTIME_R
+	struct tm struct_tm;
+#endif
         time_t secs;
         unsigned char *s;
 
         secs = time(NULL);
-        localtime_r(&secs, &tm);
-        strftime(string, sizeof(string), GNC_D_FMT, &tm);
+#ifdef HAVE_LOCALTIME_R
+	localtime_r(&secs, &struct_tm);
+	tm = &struct_tm;
+#else
+        tm = localtime(&secs);
+#endif
+        strftime(string, sizeof(string), GNC_D_FMT, tm);
 
         for (s = string; s != '\0'; s++)
           if (!isdigit(*s))
@@ -1190,22 +1214,38 @@
 int
 gnc_timespec_last_mday (Timespec t)
 {
-  struct tm result;
+#ifdef HAVE_LOCALTIME_R
+  struct tm tm;
+#endif
+  struct tm *result;
   time_t t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
-  localtime_r(&t_secs, &result);
-  return date_get_last_mday (&result);
+#ifdef HAVE_LOCALTIME_R
+  localtime_r(&t_secs, &tm);
+  result = &tm;
+#else
+  result = localtime(&t_secs);
+#endif
+  return date_get_last_mday (result);
 }
 
 void
 gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)
 {
-  struct tm result;
+#ifdef HAVE_LOCALTIME_R
+  struct tm tm;
+#endif
+  struct tm *result;
   time_t t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
-  localtime_r(&t_secs, &result);
+#ifdef HAVE_LOCALTIME_R
+  localtime_r(&t_secs, &tm);
+  result = &tm;
+#else
+  result = localtime(&t_secs);
+#endif
 
-  if (day) *day = result.tm_mday;
-  if (month) *month = result.tm_mon+1;
-  if (year) *year = result.tm_year+1900;
+  if (day) *day = result->tm_mday;
+  if (month) *month = result->tm_mon+1;
+  if (year) *year = result->tm_year+1900;
 }
 
 /********************************************************************\



More information about the gnucash-changes mailing list