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" c-gmtime)
39 (uffi:def-type time-t :unsigned-long)
40 (uffi:def-type tm-pointer (* tm))
43 (uffi:with-foreign-object (time 'time-t)
44 (setf (uffi:deref-pointer time :unsigned-long) 7381)
45 (uffi:deref-pointer time :unsigned-long))
49 (uffi:with-foreign-object (time 'time-t)
50 (setf (uffi:deref-pointer time :unsigned-long) 7381)
51 (let ((tm-ptr (the tm-pointer (c-gmtime time))))
52 (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
53 (uffi:get-slot-value tm-ptr 'tm 'mday)
54 (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
55 (uffi:get-slot-value tm-ptr 'tm 'hour)
56 (uffi:get-slot-value tm-ptr 'tm 'min)
57 (uffi:get-slot-value tm-ptr 'tm 'sec)
62 (uffi:def-struct timeval
66 (uffi:def-struct timezone
70 (uffi:def-function ("gettimeofday" c-gettimeofday)
76 (uffi:with-foreign-object (tv 'timeval)
77 (let ((res (c-gettimeofday tv (uffi:make-null-pointer 'timezone))))
79 (+ (* 1000000 (uffi:get-slot-value tv 'timeval 'secs))
80 (uffi:get-slot-value tv 'timeval 'usecs))
84 (multiple-value-bind (t1 res1) (get-utime)
85 (multiple-value-bind (t2 res2) (get-utime)
86 (and (or (= t2 t1) (> t2 t1))
93 (defun posix-time-to-localtime-string (secs)
94 "Converts number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)"
97 (uffi:convert-from-cstring
98 (uffi:with-foreign-object (time 'time-t)
99 (setf (uffi:deref-pointer time :unsigned-long)