[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: errno handling on sys.() and io.() functions
- From: William Ahern <william@...>
- Date: Wed, 30 Jan 2013 14:51:46 -0800
On Wed, Jan 30, 2013 at 09:05:48PM +0100, Ico wrote:
> 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
> 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.
You can install cqueues and get this table with require"cqueues.errno". Or
you can reuse the scripts in the mk/ subdirectory. mk/errno.ls selects the
E* macros, mk/macros.ls implements the preprocessor tricks needed to get
macro definitions and predefinitions (works with GCC, clang, and SunPro),
and mk/vendor.cc determines the compiler vendor.