[cffi-devel] Unexpected return

N. Raghavendra raghu at mri.ernet.in
Wed Feb 22 18:37:43 UTC 2006


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 at mri.ernet.in> | See message headers for contact
Harish-Chandra Research Institute   | and OpenPGP details.




More information about the cffi-devel mailing list