ocaml: Add Guestfs.Errno submodule exposing useful raw errno numbers.

For use when calling G.last_errno.
This commit is contained in:
Richard W.M. Jones
2014-03-17 12:10:15 +00:00
parent 996c0a2868
commit 0563405d2e
2 changed files with 23 additions and 0 deletions

View File

@@ -121,10 +121,20 @@ val last_errno : t -> int
(or [0] if there was no errno). Note that the returned integer is the
raw errno number, and it is {i not} related to the {!Unix.error} type.
Some raw errno numbers are exposed by the {!Guestfs.Errno} submodule,
and we can add more as required.
[last_errno] can be overwritten by subsequent operations on a handle,
so if you want to capture the errno correctly, you must call this
in the {!Error} exception handler, before any other operation on [g]. *)
(** The [Guestfs.Errno] submodule exposes some raw errno numbers,
which you can use to test the return value of {!Guestfs.last_errno}. *)
module Errno : sig
val errno_ENOTSUP : int
end
";
generate_ocaml_structure_decls ();
@@ -253,6 +263,11 @@ external event_to_string : event list -> string
external last_errno : t -> int = \"ocaml_guestfs_last_errno\"
module Errno = struct
external enotsup : unit -> int = \"ocaml_guestfs_get_ENOTSUP\" \"noalloc\"
let errno_ENOTSUP = enotsup ()
end
(* Give the exceptions names, so they can be raised from the C code. *)
let () =
Callback.register_exception \"ocaml_guestfs_error\" (Error \"\");

View File

@@ -63,6 +63,7 @@ value ocaml_guestfs_set_event_callback (value gv, value closure, value events);
value ocaml_guestfs_delete_event_callback (value gv, value eh);
value ocaml_guestfs_event_to_string (value events);
value ocaml_guestfs_last_errno (value gv);
value ocaml_guestfs_get_ENOTSUP (value unitv);
/* Allocate handles and deal with finalization. */
static void
@@ -438,3 +439,10 @@ ocaml_guestfs_last_errno (value gv)
rv = Val_int (r);
CAMLreturn (rv);
}
/* NB: "noalloc" function. */
value
ocaml_guestfs_get_ENOTSUP (value unitv)
{
return Val_int (ENOTSUP);
}