From 076cb982dd3c478a899e41bef315a873194f5b78 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 5 Jul 2009 08:41:47 +0000 Subject: [PATCH] check for the size of time_t and behave accordingly git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1866 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/configure.ac | 27 +++++++++++++++++++++++++++ program/src/rrd_restore.c | 11 +++++++++++ program/win32/rrd_config.h.msvc | 1 + 3 files changed, 39 insertions(+) diff --git a/program/configure.ac b/program/configure.ac index cc033195..f624a0d4 100644 --- a/program/configure.ac +++ b/program/configure.ac @@ -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 ]], + [[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 ]], + [[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) diff --git a/program/src/rrd_restore.c b/program/src/rrd_restore.c index 52c738ba..4cbc37ad 100644 --- a/program/src/rrd_restore.c +++ b/program/src/rrd_restore.c @@ -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); diff --git a/program/win32/rrd_config.h.msvc b/program/win32/rrd_config.h.msvc index 8a839239..7c55d5a0 100644 --- a/program/win32/rrd_config.h.msvc +++ b/program/win32/rrd_config.h.msvc @@ -42,6 +42,7 @@ #define snprintf _snprintf #define vsnprintf _vsnprintf #define strftime strftime_ +#define strtoll(p, e, b) _strtoi64(p, e, b) /* realloc does not support NULL as argument */ #define NO_NULL_REALLOC 1 -- 2.30.2