Next: iklib time, Previous: iklib cstrings, Up: iklib [Index]
errno
Most C language system functions report errors by setting a the special
variable errno
to some predefined integer constant,
(libc)errno. The Scheme code accessing
errno
values should be agnostic with respect to the actual error
codes; for this to happen we should use the following facilities along
with bindings from (vicare platform errno)
, (vicare-libs)More
features for errno
for details.
Values for the C language variable errno
are encoded as negated
fixnum values: if EPERM
is defined to 1
at the C language
level, Vicare defines it as the fixnum -1
; at present
all the known error codes fit into fixnums range. One syntax identifier
binding for each known errno
value is exported by the library
(vicare platform errno)
and reexported by the library
(vicare platform constants)
.
If some error codes are not defined on a platform: the corresponding
binding evaluates to #t
. Notice that if no error occurred
errno
is set to the fixnum zero.
The following bindings are exported by the libraries (vicare)
and (vicare system $foreign)
and reexported by the library
(vicare ffi)
.
Interface to the C language level errno
variable to be used with
the foreign–functions interface (FFI).
When called with no values return the value of the C variable
errno
right after the last call to a C function performed by the
current process through the FFI. When called with one argument: set
the C variable errno
of the current process to code,
appropriately handling the coding of the value.
Notice that bindings exported by (vicare posix)
, (vicare
glibc)
and (vicare linux)
do not use this mechanism;
rather they raise an exception whenever an error happen.
As special cases: when the C variable errno
is set to zero,
errno
returns #f
; when code is #f
, the C
variable errno
is set to zero; when code is #t
, the C
variable errno
is set to EFAULT
.
The mechanism is such that the following form:
(let ((rv (call-foreign-function))) (values rv (errno)))
performs a foreign–function call and evaluates to two values: the
return value from the foreign function and the value of the C variable
errno
right after the foreign call.
Next: iklib time, Previous: iklib cstrings, Up: iklib [Index]