ocamllabs/ocaml-ctypes — pull request #194 by fdopen (2014-10-17 12:01:11+00:00)
Title: check_errno is not helpful

My manpage says:
####
The header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong. Its value is significant only when the return value of the call indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions); **a function that succeeds is allowed to change errno.**
[...]
A common mistake is to do
```
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ... }
}
```
where errno no longer needs to have the value it had upon return from somecall()
####

So the current approach to throw an error, if `errno <> 0` is not helpful. Even worse, if `somecall()` allocated a ressource, the user has no chance to free it.

This commit documents this behaviour and fixes a minor issue.
A better solution would require an interface change. The user needs access to both: the return value and the errno value.