From 3a1fbaf1ee557620901897a99d7865926f1434c9 Mon Sep 17 00:00:00 2001 From: Irfan Mohammad Date: Fri, 2 May 2025 16:33:44 +0000 Subject: [PATCH] ly_out add API for ly_out_printed_total ly_out_printed() only gives the bytes printed in the last writer function call. There are use cases where we need to know total number of bytes written as well. So, expose this with ly_out_printed_total() API --- src/out.c | 6 ++++++ src/out.h | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/out.c b/src/out.c index 451fba4813..58ebfa47ca 100644 --- a/src/out.c +++ b/src/out.c @@ -681,6 +681,12 @@ ly_out_printed(const struct ly_out *out) return out->func_printed; } +LIBYANG_API_DEF size_t +ly_out_printed_total(const struct ly_out *out) +{ + return out->printed; +} + LY_ERR ly_write_skip(struct ly_out *out, size_t count, size_t *position) { diff --git a/src/out.h b/src/out.h index ca97eff736..3110dcb241 100644 --- a/src/out.h +++ b/src/out.h @@ -63,6 +63,7 @@ extern "C" { * * - ::ly_out_type() * - ::ly_out_printed() + * - ::ly_out_printed_total() * * - ::ly_out_reset() * - ::ly_out_free() @@ -291,6 +292,14 @@ LIBYANG_API_DECL LY_ERR ly_write(struct ly_out *out, const char *buf, size_t len */ LIBYANG_API_DECL size_t ly_out_printed(const struct ly_out *out); +/** + * @brief Get the total number of printed bytes of this out structure. + * + * @param[in] out Out structure used. + * @return Number of printed bytes. + */ +LIBYANG_API_DECL size_t ly_out_printed_total(const struct ly_out *out); + /** * @brief Free the printer handler. * @param[in] out Printer handler to free.