E
Eric Hodel
--Apple-Mail-17--324655868
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed
I'm trying to wrap localtime from libc, and am having no luck.
Here's what I've got:
require "dl"
require "dl/import"
require "dl/struct"
module LIBC
extend DL::Importable
begin
dlload "libc.so"
rescue
dlload "libc.dylib" # Mac
end
typealias "const time_t *clock", "long ref" # teach DL about const
time_t * clock
##
# I know this isn't necessary, but just so you can see it in
c_localtime below
StructTm = struct [
"int tm_sec", # seconds (0 - 60)
"int tm_min", # minutes (0 - 59)
"int tm_hour", # hours (0 - 23)
"int tm_mday", # day of month (1 - 31)
"int tm_mon", # month of year (0 - 11)
"int tm_year", # year - 1900
"int tm_wday", # day of week (Sunday = 0)
"int tm_yday", # day of year (0 - 365)
"int tm_isdst", # is summer time in effect?
"long tm_gmtoff", # offset from UTC in seconds
"char *tm_zone", # abbreviation of timezone name
]
extern "struct tm * localtime(const time_t *clock)"
def self.c_localtime(clock)
tm = LIBC.localtime(clock)
return tm.to_a('IIIIIIIIILc') # should match StructTm above
end
end
p LIBC.c_localtime(Time.now.to_i) # => []
If I add p tm before calling to_a, I see that its a pointer of size 0,
which makes me think I've got something wrong.
--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
--Apple-Mail-17--324655868
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCOnICMypVHHlsnwQRAndeAKCjL+7uYdHmnZsdFsKSJ16c/hfA6gCgjHWA
dxiVylAiwqvTdsioo/1IGCQ=
=1lcc
-----END PGP SIGNATURE-----
--Apple-Mail-17--324655868--
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed
I'm trying to wrap localtime from libc, and am having no luck.
Here's what I've got:
require "dl"
require "dl/import"
require "dl/struct"
module LIBC
extend DL::Importable
begin
dlload "libc.so"
rescue
dlload "libc.dylib" # Mac
end
typealias "const time_t *clock", "long ref" # teach DL about const
time_t * clock
##
# I know this isn't necessary, but just so you can see it in
c_localtime below
StructTm = struct [
"int tm_sec", # seconds (0 - 60)
"int tm_min", # minutes (0 - 59)
"int tm_hour", # hours (0 - 23)
"int tm_mday", # day of month (1 - 31)
"int tm_mon", # month of year (0 - 11)
"int tm_year", # year - 1900
"int tm_wday", # day of week (Sunday = 0)
"int tm_yday", # day of year (0 - 365)
"int tm_isdst", # is summer time in effect?
"long tm_gmtoff", # offset from UTC in seconds
"char *tm_zone", # abbreviation of timezone name
]
extern "struct tm * localtime(const time_t *clock)"
def self.c_localtime(clock)
tm = LIBC.localtime(clock)
return tm.to_a('IIIIIIIIILc') # should match StructTm above
end
end
p LIBC.c_localtime(Time.now.to_i) # => []
If I add p tm before calling to_a, I see that its a pointer of size 0,
which makes me think I've got something wrong.
--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
--Apple-Mail-17--324655868
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCOnICMypVHHlsnwQRAndeAKCjL+7uYdHmnZsdFsKSJ16c/hfA6gCgjHWA
dxiVylAiwqvTdsioo/1IGCQ=
=1lcc
-----END PGP SIGNATURE-----
--Apple-Mail-17--324655868--