about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-22 13:55:25 -0700
committerEric Wong <normalperson@yhbt.net>2011-06-22 14:06:04 -0700
commit7e3694c6de13fc3d635473d3150412cbda287e75 (patch)
tree7c033f5ad108ac20c0612338db8d2760780f4055
parent5979a9b113815721140058d021ecfffc5c529de4 (diff)
Some Ruby installs muck up headers/#defines and cause weirdness.
We now explicitly define _BSD_SOURCE and include #stdio.h
-rw-r--r--ext/clogger_ext/clogger.c8
-rw-r--r--ext/clogger_ext/extconf.rb2
2 files changed, 9 insertions, 1 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index eb1605b..e8cbfdc 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -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;
diff --git a/ext/clogger_ext/extconf.rb b/ext/clogger_ext/extconf.rb
index 03ecd2d..1a28319 100644
--- a/ext/clogger_ext/extconf.rb
+++ b/ext/clogger_ext/extconf.rb
@@ -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')