From: oetiker Date: Sun, 5 Jul 2009 08:41:47 +0000 (+0000) Subject: check for the size of time_t and behave accordingly X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=bed830e383db9d9fc563897442cc441981396504 check for the size of time_t and behave accordingly git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1866 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/configure.ac b/configure.ac index cc03319..f624a0d 100644 --- a/configure.ac +++ b/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/src/rrd_restore.c b/src/rrd_restore.c index 52c738b..4cbc37a 100644 --- a/src/rrd_restore.c +++ b/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/win32/rrd_config.h.msvc b/win32/rrd_config.h.msvc index 8a83923..7c55d5a 100644 --- a/win32/rrd_config.h.msvc +++ b/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