[UFFI-Users] libc.so and UFFI why this doesn't work

Patrick X dabittweiler at gmail.com
Sat Feb 17 19:03:44 MST 2007


libc.so loaded fine but can't use stat() function from it

(defstruct timestruc
    (tv_sec  :int)
    (tv_nsec :int)
    (next :pointer-self))

(defstruct stat
    (st_dev   :unsigned-int)	
    (st_ino    :unsigned-int)
    (st_mode :unsigned-int)
    (st_nlink  :unsigned-int)
    (st_uid     :int)
    (st_gid     :int)
    (st_rdev    :unsigned-int)
    (st_atime   : timestruc)
    (st_mtime   :timestruc)
    (st_ctime   :timestruc)
    (st_size    :int)
    (st_blocks  :int)
    (st_blksize :int)
    (st_flags :unsigned-int)
    (st_gen  :unsigned-int)
    (next :pointer-self))


(def-function "stat"
  ((pname (* :char))
    (buf  (* :stat))))

(defun c-stat (path)
(let ((f-path (allocate-foreign-string path))
(buf (allocate-foreign-object  '(:pointer stat))))

(prog1 (if (not (zerop (stat f-path buf))) '()
   (list (stat-st_dev buf)
      (stat-st_ino buf)
      (stat-st_mode buf)
     (stat-st_nlink buf)
     (stat-st_uid buf)
    (stat-st_gid buf)
    (stat-st_rdev buf)
    (stat-st_size buf)
    (timestruc-tv_sec (stat-st_atime buf))
   (timestruc-tv_sec (stat-st_mtime buf))
   (timestruc-tv_sec (stat-st_ctime buf))
   (stat-st_blksize buf)
  (stat-st_blocks buf)
  (free-foreign-pointer f-path) (free-foreign-pointer buf))))


But when ever I do a (c-stat "usr")
it says that:
 The value 'usr' is not of type number
[Condition of type TYPE-ERROR]

the same things happen if I give a pathname like #p"/usr"

maybe I not using UFFI correctly I don't know but from reading the
docs this is how I thought
it should be coded.  I got the structures from NetBSD's sys/stat.h
file and copy them as I saw it.


-- 
=================================
knot in cables caused data stream to become twisted and kinked.
http://groups.google.com/group/lispstl
http://www.cwelug.org/
Patrick Pippen


More information about the UFFI-Users mailing list