[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] srfi-19 doesn't work with stable Chicken release
From: |
Graham Fawcett |
Subject: |
Re: [Chicken-users] srfi-19 doesn't work with stable Chicken release |
Date: |
Tue, 22 May 2007 21:32:13 -0400 |
On 5/19/07, Dan Muresan <address@hidden> wrote:
Well, I was in a rush, so I've wrapped strftime(). This might actually
be useful to others, so I'm posting it. I've used SWIG, but I'm sure
it's trivial using the Chicken FFI (which I don't know though):
You could do it like this, though it probably doesn't save much:
(define system-time
(foreign-lambda* c-string* ((c-string fmt))
#<<EOF
char *res;
time_t t;
struct tm tm;
time (& t);
localtime_r (& t, & tm);
char buf [500];
size_t ret = strftime (buf, sizeof (buf), fmt, &tm);
if (ret == 0) res = NULL;
else {
res = malloc (ret + 1);
memcpy (res, buf, ret + 1);
}
return (res);
EOF
))
The c-string* return-form will free the result-buffer after copying to
a Scheme string. The return value must be parenthesized, not sure why
exactly.
G