needs locale.h to compile
[rrdtool.git] / src / rrd_restore.c
index 52c738b..fc6f17b 100644 (file)
@@ -2,7 +2,9 @@
  * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2009                    
  *****************************************************************************
  * rrd_restore.c  Contains logic to parse XML input and create an RRD file
- *                initial libxml2 version of rrd_restore (c) by Florian octo Forster
+ * This file:
+ * Copyright (C) 2008  Florian octo Forster  (original libxml2 code)
+ * Copyright (C) 2008,2009 Tobias Oetiker
  *****************************************************************************
  * $Id$
  *************************************************************************** */
@@ -12,7 +14,7 @@
 #include <string.h>
 #include <libxml/parser.h>
 #include <libxml/xmlreader.h>
-
+#include <locale.h>
 
 #ifndef WIN32
 #      include <unistd.h>     /* for off_t */
@@ -241,6 +243,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 +268,8 @@ static int get_xml_llong(
     return -1;
 } /* get_xml_llong */
 
+#endif
+
 static int get_xml_double(
     xmlTextReaderPtr reader,
     double *value)
@@ -291,13 +296,14 @@ static int get_xml_double(
         }        
         errno = 0;
         temp = strtod((char *)text,NULL);
-        xmlFree(text);        
         if (errno>0){
             rrd_set_error("ling %d: get_xml_double from '%s' %s",
                           xmlTextReaderGetParserLineNumber(reader),
                           text,rrd_strerror(errno));
+            xmlFree(text);        
             return -1;
         }
+        xmlFree(text);        
         *value = temp;
         return 0;
     }
@@ -1011,6 +1017,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 +1031,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);
@@ -1200,7 +1214,7 @@ int rrd_restore(
     char **argv)
 {
     rrd_t    *rrd;
-
+    char     *old_locale;
     /* init rrd clean */
     optind = 0;
     opterr = 0;         /* initialize getopt */
@@ -1242,7 +1256,16 @@ int rrd_restore(
         return (-1);
     }
 
+#ifdef HAVE_SETLOCALE
+    old_locale = setlocale(LC_NUMERIC, "C");
+#endif
+
     rrd = parse_file(argv[optind]);
+
+#ifdef HAVE_SETLOCALE
+    setlocale(LC_NUMERIC, old_locale);
+#endif
+
     if (rrd == NULL)
         return (-1);