1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI test file, time, use C structures
7 ;;;; Author: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (in-package #:uffi-tests)
18 (uffi:def-foreign-type time-t :unsigned-long)
31 (uffi:def-function ("time" c-time)
35 (uffi:def-function "gmtime"
39 (uffi:def-function "asctime"
43 (uffi:def-type time-t :unsigned-long)
44 (uffi:def-type tm-pointer (* tm))
47 (uffi:with-foreign-object (time 'time-t)
48 (setf (uffi:deref-pointer time :unsigned-long) 7381)
49 (uffi:deref-pointer time :unsigned-long))
53 (uffi:with-foreign-object (time 'time-t)
54 (setf (uffi:deref-pointer time :unsigned-long) 7381)
55 (let ((tm-ptr (the tm-pointer (gmtime time))))
56 (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
57 (uffi:get-slot-value tm-ptr 'tm 'mday)
58 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
59 (uffi:get-slot-value tm-ptr 'tm 'hour)
60 (uffi:get-slot-value tm-ptr 'tm 'min)
61 (uffi:get-slot-value tm-ptr 'tm 'sec)
66 (uffi:def-struct timeval
70 (uffi:def-struct timezone
74 (uffi:def-function ("gettimeofday" c-gettimeofday)
80 (uffi:with-foreign-object (tv 'timeval)
81 (let ((res (c-gettimeofday tv (uffi:make-null-pointer 'timezone))))
83 (+ (* 1000000 (uffi:get-slot-value tv 'timeval 'secs))
84 (uffi:get-slot-value tv 'timeval 'usecs))
88 (multiple-value-bind (t1 res1) (get-utime)
89 (multiple-value-bind (t2 res2) (get-utime)
90 (and (or (= t2 t1) (> t2 t1))
97 (defun posix-time-to-asctime (secs)
98 "Converts number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)"
100 '(#\newline #\return)
101 (uffi:convert-from-cstring
102 (uffi:with-foreign-object (time 'time-t)
103 (setf (uffi:deref-pointer time :unsigned-long) secs)
104 (asctime (gmtime time))))))
107 (posix-time-to-asctime 0)
108 "Thu Jan 1 00:00:00 1970")