[Libguestfs] [PATCH 1/4] ocaml: Add Guestfs.Errno submodule exposing useful raw errno numbers.

Richard W.M. Jones rjones at redhat.com
Mon Mar 17 12:32:22 UTC 2014


For use when calling G.last_errno.
---
 generator/ocaml.ml | 15 +++++++++++++++
 ocaml/guestfs-c.c  |  8 ++++++++
 2 files changed, 23 insertions(+)

diff --git a/generator/ocaml.ml b/generator/ocaml.ml
index 78cff89..29a9eb6 100644
--- a/generator/ocaml.ml
+++ b/generator/ocaml.ml
@@ -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 \"\");
diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c
index 98a9ba0..bd1ffb7 100644
--- a/ocaml/guestfs-c.c
+++ b/ocaml/guestfs-c.c
@@ -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);
+}
-- 
1.8.5.3




More information about the Libguestfs mailing list