X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=augeas-c.c;h=885b829d69ce0ee7cbe7278dad6289fdbdf60ee2;hb=05f00ac539c2cd0cf5dcbf90d031023a7e973ae7;hp=160fe34ced7ecc9786cb419aeeef883eeb851120;hpb=2ccf1e5b2a7e4ba23fc2f81e1bcdcab56e8fb9f6;p=ocaml-augeas.git diff --git a/augeas-c.c b/augeas-c.c index 160fe34..885b829 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -385,3 +385,30 @@ ocaml_augeas_transform (value tv, value lensv, value filev, value modev) CAMLreturn (Val_unit); } + +/* val source : t -> path -> path option */ +CAMLprim value +ocaml_augeas_source (value tv, value pathv) +{ + CAMLparam2 (tv, pathv); + CAMLlocal2 (optv, v); + augeas_t t = Augeas_t_val (tv); + const char *path = String_val (pathv); + char *file_path; + int r; + + r = aug_source (t, path, &file_path); + if (r == 0) { + if (file_path) { /* Return Some file_path */ + v = caml_copy_string (file_path); + optv = caml_alloc (1, 0); + Field (optv, 0) = v; + free (file_path); + } else /* Return None */ + optv = Val_int (0); + } + else /* Error */ + raise_error (t, "Augeas.source"); + + CAMLreturn (optv); +}