[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: errno handling on sys.() and io.() functions
- From: Sean Conner <sean@...>
- Date: Wed, 30 Jan 2013 15:40:47 -0500
It was thus said that the Great Ico once stated:
> 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?
Instead of waiting for official blessing from Team Lua, I went ahead and
defined my own module  to handle errno values. A sample usage:
errno = require "org.conman.errno"
-- some code
if err == errno.EINVAL then
io.stderr:write("code returned ",errno[err])
Since I use it on both Linux and Solaris, I have conditionally included as
many error codes as I could find on both systems. Also, the use of the
org.conman.errno.strerror() function is not something I would use (I would
have removed it but I have plenty of code that requires it---the use of the
__index method is a relatively new development).
-spc (would like to see EXIT_SUCCESS and EXIT_FAILURE in the os module