Code

test for tm.tm_gmtoff presence in configure.ac fix for #330
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Tue, 24 Jan 2012 08:18:37 +0000 (08:18 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Tue, 24 Jan 2012 08:18:37 +0000 (08:18 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2265 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/configure.ac
program/m4/acinclude.m4
program/src/rrd_fetch_libdbi.c

index 17c988070a9f6e2c98616143b4d8ed6cc31e4406..b789a52f48ccf29d8acc5d2112cbbf39433fa88d 100644 (file)
@@ -353,6 +353,8 @@ AC_FULL_IEEE
 
 CONFIGURE_PART(Resolve Portability Issues)
 
+GC_TIMEZONE()
+
 CHECK_FOR_WORKING_MS_ASYNC
 
 dnl do we have nl_langinfo(_NL_TIME_WEEK_1STDAY)
index 4ada91974bbb9dd25a6f883a18e4b6f4f770e55a..e12477f29738cf30c8c0f18a43808a5cd34ef5d0 100644 (file)
@@ -545,3 +545,68 @@ fi
 
 ])
 
+dnl idea taken from the autoconf mailing list, posted by
+dnl Timur I. Bakeyev  timur@gnu.org, 
+dnl http://mail.gnu.org/pipermail/autoconf/1999-October/008311.html
+dnl partly rewritten by Peter Stamfest <peter@stamfest.at>
+
+dnl This determines, if struct tm containes tm_gmtoff field
+dnl or we should use extern long int timezone.
+
+dnl Add the following to your acconfig.h:
+
+dnl /* Define if your struct tm has tm_gmtoff.  */
+dnl #undef HAVE_TM_GMTOFF
+dnl #undef TM_GMTOFF
+dnl
+dnl /* Define if you don't have tm_gmtoff but do have the external timezone. */
+dnl #undef HAVE_TIMEZONE
+
+AC_DEFUN([GC_TIMEZONE], [
+        AC_REQUIRE([AC_STRUCT_TM])
+        AC_CACHE_CHECK([tm_gmtoff in struct tm], gq_cv_have_tm_gmtoff,
+                gq_cv_have_tm_gmtoff=no
+                AC_TRY_COMPILE([#include <time.h>
+                                #include <$ac_cv_struct_tm>
+                                ],
+                               [struct tm t;
+                                t.tm_gmtoff = 0;
+                                exit(0);
+                                ],
+                               gq_cv_have_tm_gmtoff=yes
+                        )
+        )
+
+        AC_CACHE_CHECK([__tm_gmtoff in struct tm], gq_cv_have___tm_gmtoff,
+                gq_cv_have___tm_gmtoff=no
+                AC_TRY_COMPILE([#include <time.h>
+                                #include <$ac_cv_struct_tm>
+                                ],
+                               [struct tm t;
+                                t.__tm_gmtoff = 0;
+                                exit(0);
+                                ],
+                               gq_cv_have___tm_gmtoff=yes
+                        )
+        )
+
+        if test "$gq_cv_have_tm_gmtoff" = yes ; then
+                AC_DEFINE(HAVE_TM_GMTOFF,1,[does tm have a tm_gmtoff member])
+                AC_DEFINE(TM_GMTOFF, tm_gmtoff,[the real name of tm_gmtoff])
+        elif test "$gq_cv_have___tm_gmtoff" = yes ; then
+                AC_DEFINE(HAVE_TM_GMTOFF)
+                AC_DEFINE(TM_GMTOFF, __tm_gmtoff)
+        else
+                AC_CACHE_CHECK(for timezone, ac_cv_var_timezone,
+                               [AC_TRY_LINK([
+                                             #include <time.h>
+                                             extern long int timezone;
+                                ],
+                               [long int l = timezone;], 
+                                ac_cv_var_timezone=yes, 
+                                ac_cv_var_timezone=no)])
+                if test $ac_cv_var_timezone = yes; then
+                        AC_DEFINE(HAVE_TIMEZONE,1,[is there an external timezone variable instead ?])
+                fi
+        fi
+])
index 71a6bcac8eb7e89e6370e9ae9fefe620e2aa9064..fdd10c49b9ddaf9210374a2793b0d387d5b9de6f 100644 (file)
@@ -1,6 +1,6 @@
 #include "rrd_tool.h"
 #include "unused.h"
-#include <dbi/dbi.h>
+// #include <dbi/dbi.h>
 #include <time.h>
 
 /* the structures */
@@ -462,9 +462,18 @@ rrd_fetch_fn_libdbi(
   /* if we have leading '*', then we have a TIMEDATE Field*/
   if (table_help.timestamp[0]=='*') {
     struct tm tm;
+#ifdef HAVE_TIMEZONE
+    extern long timezone;
+#endif
     time_t t=time(NULL);
     localtime_r(&t,&tm);
-    gmt_offset=tm.tm_gmtoff;
+#ifdef HAVE_TM_GMTOFF
+    gmt_offset=tm.TM_GMTOFF;
+#else
+#ifdef HAVE_TIMEZONE
+    gmt_offset=timezone;
+#endif
+#endif
     isunixtime=0; table_help.timestamp++;
   }
   /* hex-unescape the value */