From a0e3e8e4d134bc1b94d5d43d613e13606c9a94d8 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 23 Feb 2009 11:21:45 +0000 Subject: [PATCH] * ext/socket/ancdata.c (inspect_timeval_as_abstime): use time_t variable to avoid a warning on environments which use long as tv_sec as NetBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ ext/socket/ancdata.c | 12 +++++++----- test/socket/test_socket.rb | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 632bf41c67..5a1817c8d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 23 20:18:49 2009 Tanaka Akira + + * ext/socket/ancdata.c (inspect_timeval_as_abstime): use time_t + variable to avoid a warning on environments which use long as + tv_sec as NetBSD. + Mon Feb 23 15:53:30 2009 Akinori MUSHA * array.c (rb_ary_index, rb_ary_rindex): We know that argc is not diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 99c32542f4..793c7ed5df 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -705,13 +705,15 @@ static int inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret) { if (RSTRING_LEN(data) == sizeof(struct timeval)) { - struct timeval s; + struct timeval tv; + time_t time; struct tm tm; char buf[32]; - memcpy((char*)&s, RSTRING_PTR(data), sizeof(s)); - tm = *localtime(&s.tv_sec); + memcpy((char*)&tv, RSTRING_PTR(data), sizeof(tv)); + time = tv.tv_sec; + tm = *localtime(&time); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); - rb_str_catf(ret, " %s.%06ld", buf, (long)s.tv_usec); + rb_str_catf(ret, " %s.%06ld", buf, (long)tv.tv_usec); return 1; } else { @@ -790,7 +792,7 @@ ancillary_inspect(VALUE self) # if defined(SOL_SOCKET) case SOL_SOCKET: switch (type) { -# if defined(SCM_TIMESTAMP) /* GNU/Linux, MacOS X, Solaris */ +# if defined(SCM_TIMESTAMP) /* GNU/Linux, FreeBSD, NetBSD, OpenBSD, MacOS X, Solaris */ case SCM_TIMESTAMP: inspected = inspect_timeval_as_abstime(level, type, data, ret); break; # endif # if defined(SCM_RIGHTS) /* 4.4BSD */ diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index 9720656e80..f411a14b7d 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -274,12 +274,12 @@ class TestSocket < Test::Unit::TestCase end def test_timestamp - return if /linux|solaris|darwin/ !~ RUBY_PLATFORM + return if /linux|freebsd|netbsd|openbsd|solaris|darwin/ !~ RUBY_PLATFORM t1 = Time.now.strftime("%Y-%m-%d") stamp = nil Addrinfo.udp("127.0.0.1", 0).bind {|s1| Addrinfo.udp("127.0.0.1", 0).bind {|s2| - s1.setsockopt(:SOCKET, :SO_TIMESTAMP, true) + s1.setsockopt(:SOCKET, :TIMESTAMP, true) s2.send "a", 0, s1.local_address msg, addr, rflags, stamp = s1.recvmsg assert_equal("a", msg)