ext: fix portability defines for some installs
authorEric Wong <normalperson@yhbt.net>
Wed, 22 Jun 2011 20:55:25 +0000 (22 13:55 -0700)
committerEric Wong <normalperson@yhbt.net>
Wed, 22 Jun 2011 21:06:04 +0000 (22 14:06 -0700)
Some Ruby installs muck up headers/#defines and cause weirdness.
We now explicitly define _BSD_SOURCE and include #stdio.h

ext/clogger_ext/clogger.c
ext/clogger_ext/extconf.rb

index eb1605b..e8cbfdc 100644 (file)
@@ -18,6 +18,7 @@
 #endif
 #include <time.h>
 #include <stdlib.h>
+#include <stdio.h>             /* snprintf */
 #include "ruby_1_9_compat.h"
 #include "broken_system_compat.h"
 #include "blocking_helpers.h"
@@ -453,7 +454,12 @@ static long local_gmtoffset(struct tm *tm)
 
        tzset();
        localtime_r(&t, tm);
-#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
+
+/*
+ * HAVE_STRUCT_TM_TM_GMTOFF may be defined in Ruby headers
+ * HAVE_ST_TM_GMTOFF is defined ourselves.
+ */
+#if defined(HAVE_STRUCT_TM_TM_GMTOFF) || defined(HAVE_ST_TM_GMTOFF)
        return tm->tm_gmtoff / 60;
 #else
        return -(tm->tm_isdst ? timezone - 3600 : timezone) / 60;
index 03ecd2d..1a28319 100644 (file)
@@ -1,5 +1,6 @@
 begin
   require 'mkmf'
+  $CPPFLAGS += " -D_BSD_SOURCE=1 "
 
   # XXX let me know if this works for you...
   if ! defined?(RUBY_VERSION) || RUBY_VERSION !~ /\A1\.[89]\./
@@ -21,6 +22,7 @@ begin
   have_func('clock_gettime', 'time.h')
   have_func('localtime_r', 'time.h') or raise "localtime_r needed"
   have_func('gmtime_r', 'time.h') or raise "gmtime_r needed"
+  have_struct_member('struct tm', 'tm_gmtoff', 'time.h')
   have_func('rb_str_set_len', 'ruby.h')
   have_func('rb_thread_blocking_region', 'ruby.h')
   have_func('rb_thread_io_blocking_region', 'ruby.h')