we are using a comparison with sizeof(long) to figure the size of time_t this is...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 11 Jan 2010 09:06:59 +0000 (09:06 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 11 Jan 2010 09:06:59 +0000 (09:06 +0000)
since on freebsd in 64bit mode time_t is 32 bit while long is 64 bit

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1997 a5681a0c-68f1-0310-ab6d-d61299d08faa

configure.ac
src/rrd_restore.c

index b90e189..a4e9383 100644 (file)
@@ -459,26 +459,26 @@ 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])
+dnl is time_t 32 of 64 bit ?
+AC_DEFINE([TIME_T_IS_32BIT], [], [time_t is 32bit])
+AC_DEFINE([TIME_T_IS_64BIT], [], [time_t is 64bit])
 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; ]]
+        [[if (sizeof(time_t) != 32) return 1; ]]
         ),
-    [ AC_MSG_RESULT([time_t is long])
-      AC_DEFINE([TIME_T_IS_LONG])
+    [ AC_MSG_RESULT([time_t is 32 bit])
+      AC_DEFINE([TIME_T_IS_32BIT])
     ],
     [ AC_RUN_IFELSE(
         AC_LANG_PROGRAM(
         [[#include <time.h>]],
-        [[if (sizeof(long long) != sizeof(time_t)) return 1; ]]
+        [[if (sizeof(time_t) != 64) return 1; ]]
         ),
         [
-          AC_MSG_RESULT([time_t is long long])
-          AC_DEFINE([TIME_T_IS_LONG_LONG])
+          AC_MSG_RESULT([time_t is 64 bit])
+          AC_DEFINE([TIME_T_IS_64BIT])
         ],
         [AC_MSG_ERROR([can not figure type of time_t])]
       )
index 2f671a1..8cde6f1 100644 (file)
@@ -219,17 +219,29 @@ static int get_xml_string(
 }
 
  
-static int get_xml_long(
+static int get_xml_time_t(
     xmlTextReaderPtr reader,
-    long *value)
+    time_t *value)
 {    
     xmlChar *text;
-    long temp;    
+    time_t temp;    
     if ((text = get_xml_text(reader)) != NULL){
         errno = 0;        
+#ifdef TIME_T_IS_32BIT
         temp = strtol((char *)text,NULL, 0);
+#else
+#ifdef TIME_T_IS_64BIT
+        temp = strtoll((char *)text,NULL, 0);        
+#else
+        if (sizeof(time_t) == 32){
+            temp = strtol((char *)text,NULL, 0);
+        } else {
+            temp = strtoll((char *)text,NULL, 0);
+        }
+#endif
+#endif    
         if (errno>0){
-            rrd_set_error("ling %d: get_xml_long from '%s' %s",
+            rrd_set_error("ling %d: get_xml_time_t from '%s' %s",
                           xmlTextReaderGetParserLineNumber(reader),
                           text,rrd_strerror(errno));
             xmlFree(text);            
@@ -240,7 +252,7 @@ static int get_xml_long(
         return 0;
     }
     return -1;
-} /* get_xml_long */
+} /* get_xml_time_t */
 
 static int get_xml_ulong(
     xmlTextReaderPtr reader,
@@ -266,33 +278,6 @@ 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)
-{
-    
-    xmlChar *text;
-    long long temp;    
-    if ((text = get_xml_text(reader)) != NULL){
-        errno = 0;        
-        temp = strtoll((char *)text,NULL, 0);        
-        if (errno>0){
-            rrd_set_error("ling %d: get_xml_llong from '%s' %s",
-                          xmlTextReaderGetParserLineNumber(reader),
-                          text,rrd_strerror(errno));
-            xmlFree(text);            
-            return -1;
-        }
-        xmlFree(text);
-        *value = temp;        
-        return 0;
-    }
-    return -1;
-} /* get_xml_llong */
-
-#endif
-
 static int get_xml_double(
     xmlTextReaderPtr reader,
     double *value)
@@ -1040,22 +1025,7 @@ 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);
-            }
-            else if (sizeof(time_t) == sizeof(long long)) {
-                status = get_xml_llong(reader,
-                                        (long long *)&rrd->live_head->last_up); 
-            }
-#endif
-#endif
+                status = get_xml_time_t(reader, &rrd->live_head->last_up);
         }
         else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){            
             xmlFree(element);