[m-users.] io.error type
Fabrice Nicol
fabrnicol at gmail.com
Fri Feb 4 22:54:42 AEDT 2022
>
> But those platforms are all POSIX, aren't they? Linux, MacOS,
> Windows... Why not hand over the POSIX error codes, like it is done
> in the "posix" library, which is distributed in the "extras" directory
> in the Mercury source tree?
>
OK, I now better see what you mean. Yes, you have a point there.
Looking at the io implementation, those error codes are actually C errno
codes, set after fopen was called and returned NULL (in C grades). (Save
in the rare cases when fopen does not return null, and fstat is called
to check whether you tried to open a directory).
Now these errno codes are buried in the implementation and lost as
out-mode arguments to open_input. The "burial" takes place in line 12710
of io.m (implementation predicate is_error, errno codes are in the first
argument, wrapped in system_error types).
This is clearly by design as Julien wrote. is_error is defined in a
private interface (line 2102) but a few lines above you can read:
:- implementation.
% Everything below here is not intended to be part of the public
interface,
% and will not be included in the Mercury library reference manual.
%---------------------------------------------------------------------------%
:- interface.
%---------------------------------------------------------------------------%
%
% For use by library.m.
%
So yes, errno codes could have been returned, if is_error had been
publicly visible, but design decisions went against this.
F.
More information about the users
mailing list