Code

be more careful when converting to string to time_t ... test if time_t is long long
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 4 Jul 2009 14:51:01 +0000 (14:51 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 4 Jul 2009 14:51:01 +0000 (14:51 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1863 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_restore.c

index 8f5cbcfe3196b2b07a932b1af4aab1f1a5e7df17..52c738ba5a1f36264cef2333fd12e42781dcfddd 100644 (file)
@@ -241,6 +241,30 @@ static int get_xml_ulong(
     return -1;
 } /* get_xml_ulong */
 
+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 */
+
 static int get_xml_double(
     xmlTextReaderPtr reader,
     double *value)
@@ -986,9 +1010,16 @@ static int parse_tag_rrd(
         else if (xmlStrcasecmp(element, (const xmlChar *) "step") == 0)
             status = get_xml_ulong(reader,
                                         &rrd->stat_head->pdp_step);
-        else if (xmlStrcasecmp(element, (const xmlChar *) "lastupdate") == 0)
-            status = get_xml_long(reader,
-                                        &rrd->live_head->last_up);
+        else if (xmlStrcasecmp(element, (const xmlChar *) "lastupdate") == 0) {
+            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); 
+            }
+        }
         else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){            
             xmlFree(element);
             status = parse_tag_ds(reader, rrd);