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)
30 ;; gmoffset present on SusE SLES9
33 (uffi:def-function ("time" c-time)
38 (uffi:def-function "gmtime"
43 (uffi:def-function "asctime"
48 (uffi:def-type time-t :unsigned-long)
49 (uffi:def-type tm-pointer (* tm))
52 (uffi:with-foreign-object (time 'time-t)
53 (setf (uffi:deref-pointer time :unsigned-long) 7381)
54 (uffi:deref-pointer time :unsigned-long))
58 (uffi:with-foreign-object (time 'time-t)
59 (setf (uffi:deref-pointer time :unsigned-long) 7381)
60 (let ((tm-ptr (the tm-pointer (gmtime time))))
61 (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
62 (uffi:get-slot-value tm-ptr 'tm 'mday)
63 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
64 (uffi:get-slot-value tm-ptr 'tm 'hour)
65 (uffi:get-slot-value tm-ptr 'tm 'min)
66 (uffi:get-slot-value tm-ptr 'tm 'sec)
71 (uffi:def-struct timeval
75 (uffi:def-struct timezone
79 (uffi:def-function ("gettimeofday" c-gettimeofday)
86 (uffi:with-foreign-object (tv 'timeval)
87 (let ((res (c-gettimeofday tv (uffi:make-null-pointer 'timezone))))
89 (+ (* 1000000 (uffi:get-slot-value tv 'timeval 'secs))
90 (uffi:get-slot-value tv 'timeval 'usecs))
94 (multiple-value-bind (t1 res1) (get-utime)
95 (multiple-value-bind (t2 res2) (get-utime)
96 (and (or (= t2 t1) (> t2 t1))
103 (defun posix-time-to-asctime (secs)
104 "Converts number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)"
106 '(#\newline #\return)
107 (uffi:convert-from-cstring
108 (uffi:with-foreign-object (time 'time-t)
109 (setf (uffi:deref-pointer time :unsigned-long) secs)
110 (asctime (gmtime time))))))
113 (posix-time-to-asctime 0)
114 "Thu Jan 1 00:00:00 1970")