printer NEW function lyd_print_path()
diff --git a/src/libyang.h.in b/src/libyang.h.in
index 7e1d333..4d43f0f 100644
--- a/src/libyang.h.in
+++ b/src/libyang.h.in
@@ -615,6 +615,7 @@
* - lys_print_mem()
* - lys_print_fd()
* - lys_print_file()
+ * - lys_print_path()
* - lys_print_clb()
*/
@@ -878,6 +879,7 @@
* - lyd_print_mem()
* - lyd_print_fd()
* - lyd_print_file()
+ * - lyd_print_path()
* - lyd_print_clb()
*/
diff --git a/src/printer.c b/src/printer.c
index 466f508..ca9b636 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -748,6 +748,29 @@
}
API int
+lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options)
+{
+ FILE *f;
+ int ret;
+
+ if (!path) {
+ LOGARG;
+ return EXIT_FAILURE;
+ }
+
+ f = fopen(path, "w");
+ if (!f) {
+ LOGERR(root->schema->module->ctx, LY_EINVAL, "Cannot open file \"%s\" for writing.", path);
+ return EXIT_FAILURE;
+ }
+
+ ret = lyd_print_file(f, root, format, options);
+
+ fclose(f);
+ return ret;
+}
+
+API int
lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options)
{
int r;
diff --git a/src/tree_data.h b/src/tree_data.h
index 09af0dd..c6eec4d 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1263,9 +1263,9 @@
/**
* @brief Print data tree in the specified format.
*
+ * @param[in] fd File descriptor where to print the data.
* @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
* node of the data tree to print the specific subtree.
- * @param[in] fd File descriptor where to print the data.
* @param[in] format Data output format.
* @param[in] options [printer flags](@ref printerflags). \p format LYD_LYB accepts only #LYP_WITHSIBLINGS option.
* @return 0 on success, 1 on failure (#ly_errno is set).
@@ -1275,9 +1275,9 @@
/**
* @brief Print data tree in the specified format.
*
+ * @param[in] f File stream where to print the data.
* @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
* node of the data tree to print the specific subtree.
- * @param[in] f File stream where to print the data.
* @param[in] format Data output format.
* @param[in] options [printer flags](@ref printerflags). \p format LYD_LYB accepts only #LYP_WITHSIBLINGS option.
* @return 0 on success, 1 on failure (#ly_errno is set).
@@ -1287,9 +1287,21 @@
/**
* @brief Print data tree in the specified format.
*
+ * @param[in] path File path where to print the data.
* @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
* node of the data tree to print the specific subtree.
+ * @param[in] format Data output format.
+ * @param[in] options [printer flags](@ref printerflags). \p format LYD_LYB accepts only #LYP_WITHSIBLINGS option.
+ * @return 0 on success, 1 on failure (#ly_errno is set).
+ */
+int lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options);
+
+/**
+ * @brief Print data tree in the specified format.
+ *
* @param[in] writeclb Callback function to write the data (see write(1)).
+ * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
+ * node of the data tree to print the specific subtree.
* @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
* @param[in] format Data output format.
* @param[in] options [printer flags](@ref printerflags). \p format LYD_LYB accepts only #LYP_WITHSIBLINGS option.