Code

check for the size of time_t and behave accordingly
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 5 Jul 2009 08:41:47 +0000 (08:41 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 5 Jul 2009 08:41:47 +0000 (08:41 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1866 a5681a0c-68f1-0310-ab6d-d61299d08faa

configure.ac
src/rrd_restore.c
win32/rrd_config.h.msvc

index cc033195802179a2722266e7c4b60698e518e319..f624a0d45755408f98eef4afbacd9748874c4f39 100644 (file)
@@ -449,6 +449,33 @@ AC_LINK_IFELSE(
       )
     ]  
 )
+
+dnl is time_t long or long long ?
+AC_DEFINE([TIME_T_IS_LONG], [], [time_t is long])
+AC_DEFINE([TIME_T_IS_LONG_LONG], [], [time_t is long long])
+AC_MSG_CHECKING([the type of time_t])
+AC_RUN_IFELSE(
+    AC_LANG_PROGRAM(
+        [[#include <time.h>]],
+        [[if (sizeof(long) != sizeof(time_t)) return 1; ]]
+        ),
+    [ AC_MSG_RESULT([time_t is long])
+      AC_DEFINE([TIME_T_IS_LONG])
+    ],
+    [ AC_RUN_IFELSE(
+        AC_LANG_PROGRAM(
+        [[#include <time.h>]],
+        [[if (sizeof(long long) != sizeof(time_t)) return 1; ]]
+        ),
+        [
+          AC_MSG_RESULT([time_t is long long])
+          AC_DEFINE([TIME_T_IS_LONG_LONG])
+        ],
+        [AC_MSG_ERROR([can not figure type of time_t])]
+      )
+    ]  
+)
+
 AC_LANG_POP(C)
 
 CONFIGURE_PART(Find 3rd-Party Libraries)
index 52c738ba5a1f36264cef2333fd12e42781dcfddd..4cbc37adc45ebc08de59ab2fb80822055d2c7cfd 100644 (file)
@@ -241,6 +241,7 @@ static int get_xml_ulong(
     return -1;
 } /* get_xml_ulong */
 
+#ifndef TIME_T_IS_LONG
 static int get_xml_llong(
     xmlTextReaderPtr reader,
     long long *value)
@@ -265,6 +266,8 @@ static int get_xml_llong(
     return -1;
 } /* get_xml_llong */
 
+#endif
+
 static int get_xml_double(
     xmlTextReaderPtr reader,
     double *value)
@@ -1011,6 +1014,12 @@ static int parse_tag_rrd(
             status = get_xml_ulong(reader,
                                         &rrd->stat_head->pdp_step);
         else if (xmlStrcasecmp(element, (const xmlChar *) "lastupdate") == 0) {
+#ifdef TIME_T_IS_LONG
+                status = get_xml_long(reader, &rrd->live_head->last_up);
+#else
+#ifdef TIME_T_IS_LONG_LONG
+                status = get_xml_llong(reader, &rrd->live_head->last_up); 
+#else
             if (sizeof(time_t) == sizeof(long)) {
                 status = get_xml_long(reader,
                                         (long *)&rrd->live_head->last_up);
@@ -1019,6 +1028,8 @@ static int parse_tag_rrd(
                 status = get_xml_llong(reader,
                                         (long long *)&rrd->live_head->last_up); 
             }
+#endif
+#endif
         }
         else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){            
             xmlFree(element);
index 8a839239cec8726f00b32a717d828a500af5d161..7c55d5a0ce1ca39dc57cd76da8f9ce342d7d8328 100644 (file)
@@ -42,6 +42,7 @@
 #define snprintf _snprintf\r
 #define vsnprintf _vsnprintf\r
 #define strftime strftime_ \r
+#define strtoll(p, e, b) _strtoi64(p, e, b)\r
 \r
 /* realloc does not support NULL as argument */\r
 #define NO_NULL_REALLOC 1\r