Hi all,
While working through my fancy gettimeofday CFFI example, I've added a type translator used as the return type for standard C functions that return a negative integer on error and set 'errno'.
Since errno is often a macro expanding to a function, I can't very well define it as a foreign global. Most CL implementations seem to have a function used internally to safely get errno for the current thread. I propose adding such an interface to CFFI-SYS to safely get 'errno'.
Here's what I added to CFFI-SYS for SBCL:
(defun errno-value () (sb-alien:get-errno))
This should be equally simple for CMUCL, OpenMCL, and LispWorks. I haven't found anything in Allegro CL or CLISP (Jörg?) for this yet.
I don't intend to do anything with the return value except call 'strerror' on it, since the values themselves are also defined as macros and not introspectable from Lisp either...argh!
(I know errno isn't _completely_ portable---at least one OS I use regularly, Windows CE, doesn't have it at all, even though some functions are documented as setting it! I'm willing to put that off until we run into the problem though...)
James