def _declare(name, *params, **kwargs): params = list(map(_to_param, params)) argtypes = tuple(param.typ for param in params) paramflags = tuple(param.paramflag for param in params) restype = kwargs.get('restype') errcheck = kwargs.get('errcheck') func = CFUNCTYPE(restype, *argtypes)((name, _lib), paramflags) func.__name__ = name if errcheck: func.errcheck = errcheck globals()[name] = func
c_int]), 'flistxattr': (c_ssize_t, [c_int, c_char_p, c_size_t, c_int]), 'fremovexattr': (c_int, [c_int, c_char_p, c_int])} errno.ENOATTR = 93 ENOATTR_LIST = (errno.ENOATTR, errno.EINVAL, errno.EPERM) XATTR_CREATE = 2 XATTR_REPLACE = 4 else: raise Exception('Xattrs not supported on this platform!') _func_types = {} for name, (restype, argtypes) in c_calls.iteritems(): _func_types[name] = CFUNCTYPE(restype, use_errno=True, *argtypes)((name, _libc)) _func_types[name].errcheck = _errcheck c_fgetxattr = _func_types['fgetxattr'] c_fsetxattr = _func_types['fsetxattr'] c_flistxattr = _func_types['flistxattr'] c_fremovexattr = _func_types['fremovexattr'] if sys.platform.startswith('linux'): def fsetxattr(fd, name, buf, options): name = _unicode_to_fs(name) return c_fsetxattr(fd, name, buf, len(buf), options) def fremovexattr(fd, name): name = _unicode_to_fs(name) return c_fremovexattr(fd, name)
syslog = _libc.syslog syslog.argtypes = [c_int, c_char_p, c_void_p] import os def errcheck(ret, func, args): if ret < 0: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) return ret func_dict = {} for name, restype, argtypes in (('inotify_init', c_int, ()), ('inotify_add_watch', c_int, (c_int, c_char_p, c_uint32)), ('inotify_rm_watch', c_int, (c_int, c_uint32))): the_func = CFUNCTYPE(c_int, use_errno=True, *argtypes)((name, _libc)) func_dict[name] = the_func the_func.errcheck = errcheck inotify_init = func_dict['inotify_init'] inotify_add_watch = func_dict['inotify_add_watch'] inotify_rm_watch = func_dict['inotify_rm_watch'] def errcheck_posix(ret, func, args): if ret != 0: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) return ret try: try: posix_fadvise = CFUNCTYPE(c_int, use_errno=True, *[c_int,
wd, mask, cookie, length = struct.unpack_from('iIII', self.__buffer, i) if i + _iIII_length + length > buffer_length: break name = self.__buffer[i + _iIII_length:i + _iIII_length + length].rstrip(b'\0') watch_path = self.__wd_to_path.get(wd) if watch_path: events.append((watch_path, mask, cookie, name)) i += _iIII_length + length self.__buffer = self.__buffer[i:] return events _inotify_init = CFUNCTYPE(c_int, use_errno=True)( ("inotify_init", _libc)) _inotify_init.errcheck = _check_error _inotify_add_watch = CFUNCTYPE(c_int, c_int, c_char_p, c_uint32, use_errno=True)( ("inotify_add_watch", _libc)) _inotify_add_watch.errcheck = _check_error _inotify_rm_watch = CFUNCTYPE(c_int, c_int, c_int, use_errno=True)( ("inotify_rm_watch", _libc)) _inotify_rm_watch.errcheck = _check_error IN_ACCESS = 0x00000001 # File was accessed IN_MODIFY = 0x00000002 # File was modified IN_ATTRIB = 0x00000004 # Metadata changed IN_CLOSE_WRITE = 0x00000008 # Writtable file was closed IN_CLOSE_NOWRITE = 0x00000010 # Unwrittable file closed IN_OPEN = 0x00000020 # File was opened