[cffi-devel] Unexpected return
I hope this is not OT. I am trying to learn to use CFFI. Following the CFFI manual, I wrote the following functions, which call some basic C time functions. According to gmtime(3), the function `gmtoff' below should always return 0. However, I consistently get TIMEZONE-FFI> (gmtoff) 672421260 I would appreciate any hints as to where I am erring. In case it is relevant, the environment is CMUCL 19c on FreeBSD 6.0-STABLE. TIA, Raghavendra. --- code follows --- (defpackage #:timezone-ffi (:use #:common-lisp #:cffi)) (in-package #:timezone-ffi) (defcstruct tm (sec :int) (min :int) (hour :int) (mday :int) (mon :int) (year :int) (wday :int) (yday :int) (isdst :boolean) (zone :string) (gmtoff :long)) (defctype time :int) (defcfun ("time" %time) time (tp :pointer)) (defcfun (gmtime %gmtime) :pointer (tp :pointer)) ;; Should return 0 always. (defun gmtoff () (with-foreign-object (tp 'time) (setf (mem-ref tp 'time) (%time (null-pointer))) (foreign-slot-value (%gmtime tp) 'tm 'gmtoff))) -- N. Raghavendra <raghu@mri.ernet.in> | See message headers for contact Harish-Chandra Research Institute | and OpenPGP details.
On Thu, 23 Feb 2006 00:07:43 +0530, "N. Raghavendra" <raghu@mri.ernet.in> said:
I hope this is not OT. I am trying to learn to use CFFI. Following the CFFI manual, I wrote the following functions, which call some basic C time functions. According to gmtime(3), the function `gmtoff' below should always return 0. However, I consistently get
TIMEZONE-FFI> (gmtoff) 672421260
I would appreciate any hints as to where I am erring. In case it is relevant, the environment is CMUCL 19c on FreeBSD 6.0-STABLE.
TIA, Raghavendra.
--- code follows ---
(defpackage #:timezone-ffi (:use #:common-lisp #:cffi))
(in-package #:timezone-ffi)
(defcstruct tm (sec :int) (min :int) (hour :int) (mday :int) (mon :int) (year :int) (wday :int) (yday :int) (isdst :boolean) (zone :string) (gmtoff :long))
I think you have zone and gmtoff in the wrong order (the man pages don't specify the order, so check the header files). __Martin
At 2006-02-22T22:29:27Z, Martin Simmons wrote:
(zone :string) (gmtoff :long))
I think you have zone and gmtoff in the wrong order (the man pages don't specify the order, so check the header files).
Thank you very much. That solved my problem. I took the order of the slots from the FreeBSD man page gmtime(3). Perhaps I should file a FreeBSD bug report regarding the disparity between the man page and `time.h'. Raghavendra. -- N. Raghavendra <raghu@mri.ernet.in> | See message headers for contact Harish-Chandra Research Institute | and OpenPGP details.
participants (2)
-
Martin Simmons
-
N. Raghavendra