X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_restore.c;h=fc6f17be4ea6148755b8e45654969a1dec0d237f;hp=8f5cbcfe3196b2b07a932b1af4aab1f1a5e7df17;hb=2a7262ebb15ad48133e5a7c7f24449013661a559;hpb=9fe4a750365ff606ee6a304cc2d24f9cbf9e6f97 diff --git a/src/rrd_restore.c b/src/rrd_restore.c index 8f5cbcf..fc6f17b 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -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 #include #include - +#include #ifndef WIN32 # include /* for off_t */ @@ -241,6 +243,33 @@ 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) @@ -267,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; } @@ -986,9 +1016,24 @@ 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) { +#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 + } else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){ xmlFree(element); status = parse_tag_ds(reader, rrd); @@ -1169,7 +1214,7 @@ int rrd_restore( char **argv) { rrd_t *rrd; - + char *old_locale; /* init rrd clean */ optind = 0; opterr = 0; /* initialize getopt */ @@ -1211,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);