#!/usr/bin/env python # test1.py from __future__ import division, print_function from ctypes import * import os lib = CDLL('/lib/libc.so.6', use_errno=True) STRING = c_char_p size_t = c_uint ssize_t = c_int # Variant 1: lib.getxattr.restype = ssize_t lib.getxattr.argtypes = [STRING, STRING, c_void_p, size_t] getxattr = lib.getxattr # Variant 2: #getxattr = CFUNCTYPE(ssize_t, STRING, STRING, c_void_p, size_t, use_errno=True)(lib.getxattr) bufsize = 42 path = '/does/not/exist' name = 'attribute' buf = create_string_buffer(bufsize) ret = getxattr(path, name, buf, bufsize) if ret < 0: err = get_errno() raise OSError(err, os.strerror(err), path)