I'd like to point out that when calling a function that might set errno in C, it's usually good practice to set errno to zero immediately before the call, so as to be sure that any subsequent non-zero errno value was actually a consequence of the function call:   errno = 0; /* clear errno before the function call */ rtnval = my_func(...); if (errno != 0) {...}   This should probably be taken into account if you're extending the FFI to provide access to errno.