I am stuck with a fairly complex Python module that does not return useful error codes (it actually fails disturbingly silently). However, the underlying C library it calls
Gave up and tracked through the C headers.
import ctypes
c = ctypes.CDLL("libc.so.6")
c.__errno_location.restype = ctypes.POINTER(ctypes.c_int)
c.write(5000, "foo", 4)
print c.__errno_location().contents # -> c_long(9)
It doesn't work in the python command prompt because it resets errno to read from stdin.
Once you know the magic word of __errno_location this looks like a common pattern. But with just errno I was pretty lost.