Source

""" This file provides some support for things like standard_c_lib anderrno access, as portable as possible"""importctypesimportctypes.utilimportsys# __________ the standard C library __________ifsys.platform=='win32':import_ffistandard_c_lib=ctypes.CDLL('msvcrt',handle=_ffi.get_libc())else:standard_c_lib=ctypes.CDLL(ctypes.util.find_library('c'))ifsys.platform=='win32':standard_c_lib._errno.restype=ctypes.POINTER(ctypes.c_int)def_where_is_errno():returnstandard_c_lib._errno()elifsys.platformin('linux2','freebsd6'):standard_c_lib.__errno_location.restype=ctypes.POINTER(ctypes.c_int)def_where_is_errno():returnstandard_c_lib.__errno_location()elifsys.platformin('darwin','freebsd7','freebsd8','freebsd9'):standard_c_lib.__error.restype=ctypes.POINTER(ctypes.c_int)def_where_is_errno():returnstandard_c_lib.__error()defget_errno():errno_p=_where_is_errno()returnerrno_p.contents.valuedefset_errno(value):errno_p=_where_is_errno()errno_p.contents.value=value