Did you know ... Search Documentation:
Pack ffi -- prolog/cerror.pl
PublicShow source

This module provides common routines to map error codes into apropriate actions in Prolog. Below is a typical example mapping the statfs() function:

:- module(libc_files,
          [ statfs/2
          ]).
:- use_module(library(cinvoke)).

:- c_import("#include <sys/vfs.h>",
            [ libc ],
            [ statfs(+string, -struct(statfs), [-int])
            ]).

statfs(File, FsStat) :-
    statfs(File, FsStat, Status),
    posix_status(Status, statfs, file, File).
 posix_status(+Code) is det
 posix_status(+Code, +Action, +Type, +Argument) is det
These predicates may be used to map POSIX int error return status into a suitable Prolog response. If Code is non-negative the predicate simply succeeds. For other cases it retrieves the error code using c_errno/1 and translates the error into a suitable Prolog exception.
 posix_ptr_status(+Code) is det
 posix_ptr_status(+Code, +Action, +Type, +Argument) is det
Handle the return code from POSIX functions that return a NULL pointer on error.
 posix_raise_error is det
 posix_raise_error(+Action, +Type, +Argument) is det
Raise an error from a POSIX errno code.
Errors
- posix_error(Errno, String)

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 posix_status(Arg1, Arg2, Arg3, Arg4)
 posix_ptr_status(Arg1, Arg2, Arg3, Arg4)
 posix_raise_error(Arg1, Arg2, Arg3)