Skip to content

Instantly share code, notes, and snippets.

@silverjam
Created January 26, 2010 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverjam/286405 to your computer and use it in GitHub Desktop.
Save silverjam/286405 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import errno
import ctypes
try:
libc = ctypes.CDLL('libc.dylib')
except OSError:
libc = ctypes.CDLL('/lib/libc.so.6')
errorcode = int(sys.argv[1])
errmsg = ctypes.c_char_p(libc.strerror(errorcode)).value
print "%s (%d): %s" % (errno.errorcode[errorcode], errorcode, errmsg,)
> ./errnolookup.py 1
EPERM (1): Operation not permitted
> ./errnolookup.py 2
ENOENT (2): No such file or directory
> ./errnolookup.py 3
ESRCH (3): No such process
> ./errnolookup.py 42
ENOMSG (42): No message of desired type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment