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
10 ;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
12 ;;;; *************************************************************************
16 (uffi:def-foreign-type time-t :unsigned-long)
29 (uffi:def-function ("time" c-time)
33 (uffi:def-function ("localtime" c-localtime)
37 (uffi:def-type time-t :unsigned-long)
38 (uffi:def-type tm-pointer (* tm))
41 "Returns the local time"
42 (uffi:with-foreign-object (time 'time-t)
43 ;; (declare (type time-t time))
45 (let ((tm-ptr (the tm-pointer (c-localtime time))))
46 (declare (type tm-pointer tm-ptr))
47 (let ((time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
48 (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
49 (uffi:get-slot-value tm-ptr 'tm 'mday)
50 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
51 (uffi:get-slot-value tm-ptr 'tm 'hour)
52 (uffi:get-slot-value tm-ptr 'tm 'min)
53 (uffi:get-slot-value tm-ptr 'tm 'sec)
61 (format t "~&~A" (gettime))
65 (let ((time (gettime)))
66 (util.test:test (stringp time) t :fail-info "Time is not a string")
67 (util.test:test (plusp (parse-integer time :junk-allowed t))
69 :fail-info "time string does not start with a number")))