Hi all,

In Allegro CL, the only safe way to get errno after a foreign function call is to configure the foreign function definition to return it as a second value.

CFFI doesn't deal with errno. There has been some previous discussion (http://lists.common-lisp.net/pipermail/cffi-devel/2009-January/003017.html) to return errno safely, but doesn't seem like it went anywhere.

So any library that tries to get errno is potentially broken in Allegro CL. I'm seeing this in practice with lisp-zmq, for example.

I'd like to introduce a new option to defcfun and foreign-funcall called :errno.

It would look like this: (foreign-funcall ("strlen" :errno t) :string "foo" :int), or (defcfun (strlen "strlen" :errno t) :int (s :string)).

Calling (strlen) would return two values, the return value of the foreign call, and errno.

In some Lisps, the only way to get errno is to make an additional foreign call. Then perhaps that call could be made by CFFI and returns as the second value.

I've created a pull request (https://github.com/cffi/cffi/pull/28) with a very rudimentary implementation for Allegro CL.

Since CFFI delegates the handling of errno to the implementation, perhaps we could preserve the status quo and not get bugged down in grandiose plans of portability.

Thoughts and suggestions are welcome. 

Thanks,
Felix