mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
They can be close()d explicitly with close-file-descriptor, and will close() on gc, but only explicitly closing the last port on them will close the fileno. Notably needed for network sockets where we open separate input and output ports on the same socket.
78 lines
2.1 KiB
Text
78 lines
2.1 KiB
Text
|
|
(cond-expand
|
|
(plan9)
|
|
(else
|
|
(c-system-include "time.h")
|
|
(c-system-include "sys/time.h")))
|
|
|
|
(define-c-struct tm
|
|
predicate: tm?
|
|
constructor: (make-tm tm_sec tm_min tm_hour
|
|
tm_mday tm_mon tm_year tm_isdst)
|
|
(int tm_sec time-second)
|
|
(int tm_min time-minute)
|
|
(int tm_hour time-hour)
|
|
(int tm_mday time-day)
|
|
(int tm_mon time-month)
|
|
(int tm_year time-year)
|
|
(int tm_wday time-day-of-week)
|
|
(int tm_yday time-day-of-year)
|
|
(int tm_isdst time-dst?))
|
|
|
|
;;> Accessors for the \scheme{tm} struct.
|
|
;;/
|
|
|
|
(define-c-struct timeval
|
|
predicate: timeval?
|
|
constructor: (make-timeval tv_sec tv_usec)
|
|
(time_t tv_sec timeval-seconds)
|
|
(int tv_usec timeval-microseconds))
|
|
|
|
;;> Accessors for the \scheme{timeval} struct.
|
|
;;/
|
|
|
|
(define-c-struct timezone
|
|
predicate: timezone?
|
|
(int tz_minuteswest timezone-offset)
|
|
(int tz_dsttime timezone-dst-time))
|
|
|
|
;;> Accessors for the \scheme{timezone} struct.
|
|
;;/
|
|
|
|
;;> Returns the current time as an integer number
|
|
;;> of seconds since an arbitrary epoch.
|
|
|
|
(define-c time_t (current-seconds "time") ((value NULL)))
|
|
|
|
;;> Returns the current time as a list of a timeval struct
|
|
;;> and a timezone.
|
|
|
|
(define-c errno (get-time-of-day "gettimeofday")
|
|
((result timeval) (result timezone)))
|
|
|
|
;;> Set the current time from a timeval struct and
|
|
;;> and optional timezone.
|
|
|
|
(define-c errno (set-time-of-day! "settimeofday")
|
|
(timeval (maybe-null default NULL timezone)))
|
|
|
|
;;> Convert an integer number of epoch seconds to a broken-down tm struct.
|
|
|
|
(define-c non-null-pointer (seconds->time "localtime_r")
|
|
((pointer time_t) (result tm)))
|
|
|
|
;;> Convert a tm struct to an integer number of seconds.
|
|
|
|
(define-c time_t (time->seconds "mktime")
|
|
(tm))
|
|
|
|
;;> Format a datetime string from an integer number of epoch seconds.
|
|
|
|
(define-c non-null-string (seconds->string "ctime_r")
|
|
((pointer time_t) (result (array char 64))))
|
|
|
|
;;> Format a datetime string from a tm struct.
|
|
|
|
(define-c non-null-string (time->string "asctime_r")
|
|
(tm (result (array char 64))))
|
|
|