summaryrefslogtreecommitdiff
path: root/ext/socket/ancdata.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-01 12:11:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-01 12:11:53 +0000
commit2f8b6234cd5b5a6b1bd5e2abdd07813e81f6e0c5 (patch)
treecebf4c2f6f68db02ce863e3c6f7c31de7b3008be /ext/socket/ancdata.c
parentae9c138e2dc7723ec2c9ba6fc5fc8737f20043e2 (diff)
* include/ruby/intern.h (rb_time_num_new): declared.
* time.c (nsec2timev): extracted from time_new_internal. (time_new_internal): change argument to VALUE. (rb_time_new): follow the argument change. (rb_time_nano_new): ditto. (rb_time_num_new): new function. * ext/socket/ancdata.c (ancillary_timestamp): use rb_time_num_new to represent struct bintime preciously. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/ancdata.c')
-rw-r--r--ext/socket/ancdata.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index d30ddf6..78dcba7 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -327,14 +327,20 @@ ancillary_timestamp(VALUE self)
}
# endif
+#define add(x,y) (rb_funcall((x), '+', 1, (y)))
+#define mul(x,y) (rb_funcall((x), '*', 1, (y)))
+#define quo(x,y) (rb_funcall((x), rb_intern("quo"), 1, (y)))
+
# ifdef SCM_BINTIME
if (level == SOL_SOCKET && type == SCM_BINTIME &&
RSTRING_LEN(data) == sizeof(struct bintime)) {
struct bintime bt;
- struct timespec ts;
+ VALUE d, timev;
memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt));
- bintime2timespec(&bt, &ts);
- result = rb_time_nano_new(ts.tv_sec, ts.tv_nsec);
+ d = ULL2NUM(0x100000000UL);
+ d = mul(d,d);
+ timev = add(TIMET2NUM(bt.sec), quo(ULL2NUM(bt.frac), d));
+ result = rb_time_num_new(timev, Qnil);
}
# endif