lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Jan 30, 2013 at 02:51:46PM -0800, William Ahern wrote:
> On Wed, Jan 30, 2013 at 09:05:48PM +0100, Ico wrote:
> <snip>
> > This still leaves the problem of handling the actual errno values. ANSI C does
> > not define any of the real world cases like ENOENT or EACCESS, although the
> > POSIX errno list is pretty much standard on a lot of platforms supporting the
> > ANSI C stream functions. It is trivial to add a list of constants to any
> > program, but it might be handy if the io library offers constants available on
> > the current platform (since there's already LUA_USE_POSIX). 
> > 
> > I'd love to be able to write something poratble like
> > 
> >   local fd, _, errno = io.open("file")
> >   if errno == io.EACCESS then
> >      ...
> >   end
> >   
> > Any thoughts on this?
> 
> For my cqueues* library I scan the CPP output of <errno.h> for E* macros at
> build-time. The techniques work natively on Linux, *BSD, OS X, and Solaris,
> which are the platforms on which I maintain cqueues.

FWIW, POSIX also enumerates many macros in the specification for <errno.h>,
most of which are mandatory (but for which you can test with #ifdef anyhow).

This won't get all the possible errno macros on the local system, but covers
most of the useful ones. I include these along with the one I've discovered
at built-time, per chance there's a bug in the way I generate and scan the
preprocessor output.

The SUSv4 Issue 7 specification is available at:

	http://pubs.opengroup.org/onlinepubs/9699919799/

The errno.h frame page is at

	http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html