1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI Example file to get time, use C structures
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
18 (uffi:def-foreign-type time-t :unsigned-long)
31 (uffi:def-function ("time" c-time)
35 (uffi:def-function ("localtime" c-localtime)
39 (uffi:def-type time-t :unsigned-long)
40 (uffi:def-type tm-pointer (* tm))
43 "Returns the local time"
44 (uffi:with-foreign-object (time 'time-t)
45 ;; (declare (type time-t time))
47 (let ((tm-ptr (the tm-pointer (c-localtime time))))
48 (declare (type tm-pointer tm-ptr))
49 (let ((time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
50 (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
51 (uffi:get-slot-value tm-ptr 'tm 'mday)
52 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
53 (uffi:get-slot-value tm-ptr 'tm 'hour)
54 (uffi:get-slot-value tm-ptr 'tm 'min)
55 (uffi:get-slot-value tm-ptr 'tm 'sec)
63 (format t "~&~A" (gettime))
67 (let ((time (gettime)))
68 (util.test:test (stringp time) t :fail-info "Time is not a string")
69 (util.test:test (plusp (parse-integer time :junk-allowed t))
71 :fail-info "time string does not start with a number")))