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 ;;;; $Id: gettime.cl,v 1.7 2002/03/23 16:32:39 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
21 (uffi:def-foreign-type time-t :unsigned-long)
34 (uffi:def-function ("time" c-time)
38 (uffi:def-function ("localtime" c-localtime)
42 (uffi:def-type time-t :unsigned-long)
43 (uffi:def-type tm-pointer (* tm))
46 "Returns the local time"
47 (uffi:with-foreign-object (time 'time-t)
48 ;; (declare (type time-t time))
50 (let ((tm-ptr (the tm-pointer (c-localtime time))))
51 (declare (type tm-pointer tm-ptr))
52 (let ((time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
53 (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
54 (uffi:get-slot-value tm-ptr 'tm 'mday)
55 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
56 (uffi:get-slot-value tm-ptr 'tm 'hour)
57 (uffi:get-slot-value tm-ptr 'tm 'min)
58 (uffi:get-slot-value tm-ptr 'tm 'sec)
66 (format t "~&~A" (gettime))