[ocaml-ctypes] proper way of wrapping syscalls concerning (check_)errno

Jan Doms jan.doms at gmail.com
Tue Jul 7 09:57:52 BST 2015


Hi,

The documentation mentions the following in regards to check_errno:

"The value ?check_errno, which defaults to false, indicates whether
Unix.Unix_error should be raised if the C function modifies errno.
Please note that a function that succeeds is allowed to change errno.
So use this option with caution. "

According to the pread manpage http://linux.die.net/man/2/pread errno
should be checked when the return value is -1.

According to wikipedia https://en.wikipedia.org/wiki/Errno.h
"Most functions indicate that they detected an error by returning a
special value, typically NULL for functions that return pointers, and
−1 for functions that return integers."

So I was wondering: what is the proper way to wrap the pread syscall
with ctypes?

Would it make sense to replace the ~(check_errno : bool) argument with e.g.

type check_errno =
 | OnMinusOne (* raise based on errno if the return value is -1 *)
 | OnNullPointer (* raise based on errno if the return value is a null
pointer *)
 | WhenChanged (* current behaviour *)

Maybe I'm worrying for nothing, as probably the kernel doesn't change
errno when no error occured, right?

Thanks in advance,
Jan


More information about the Ctypes mailing list