From a467e365dc114868f948b8b5b18e551b42d64ddd Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 15 Sep 2017 16:42:03 +0200 Subject: [PATCH] Add Augeas.set Simple binding for aug_set, so it is possible to actually change the value of nodes. --- augeas-c.c | 20 ++++++++++++++++++++ augeas.ml | 2 ++ augeas.mli | 3 +++ 3 files changed, 25 insertions(+) diff --git a/augeas-c.c b/augeas-c.c index 4db3f6c..3952910 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -349,3 +349,23 @@ ocaml_augeas_load (value tv) CAMLreturn (Val_unit); } + +/* val set : t -> -> path -> value option -> unit */ +CAMLprim value +ocaml_augeas_set (value tv, value pathv, value valuev) +{ + CAMLparam3 (tv, pathv, valuev); + augeas_t t = Augeas_t_val (tv); + const char *path = String_val (pathv); + const char *val; + + val = + valuev == Val_int (0) + ? NULL + : String_val (Field (valuev, 0)); + + if (aug_set (t, path, val) == -1) + raise_error (t, "Augeas.set"); + + CAMLreturn (Val_unit); +} diff --git a/augeas.ml b/augeas.ml index ba3626e..974a940 100644 --- a/augeas.ml +++ b/augeas.ml @@ -70,6 +70,8 @@ external save : t -> unit = "ocaml_augeas_save" external load : t -> unit = "ocaml_augeas_load" +external set : t -> path -> value option -> unit + = "ocaml_augeas_set" let () = Callback.register_exception "Augeas.Error" (Error (AugErrInternal, "", "", "")) diff --git a/augeas.mli b/augeas.mli index a896270..ef43e43 100644 --- a/augeas.mli +++ b/augeas.mli @@ -115,3 +115,6 @@ val save : t -> unit val load : t -> unit (** [load t] loads files into the tree. *) + +val set : t -> path -> value option -> unit + (** [set t path] sets [value] as new value at [path]. *) -- 1.8.3.1