Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1 | /** |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 2 | * @file out.h |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 4 | * @brief libyang output structures and functions |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015-2020 CESNET, z.s.p.o. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 15 | #ifndef LY_OUT_H_ |
| 16 | #define LY_OUT_H_ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 17 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
Jan Kundrát | c2b2f08 | 2022-06-14 15:23:12 +0200 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | #ifdef _MSC_VER |
| 21 | # define ssize_t SSIZE_T |
| 22 | #endif |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 23 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 24 | #include "log.h" |
| 25 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 30 | /** |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 31 | * @page howtoOutput Output Processing |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 32 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 33 | * libyang provides a mechanism to generalize work with the outputs (and [inputs](@ref howtoInput)) of |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 34 | * the different types. The ::ly_out handler can be created providing necessary information connected with the specific |
| 35 | * output type and then used throughout the printers functions. The API allows to combine output from libyang (data or schema) |
| 36 | * printers and output directly provided by the caller (via ::ly_print() or ::ly_write()). |
| 37 | * |
| 38 | * Using a generic output handler avoids need to have a set of functions for each printer functionality and results in simpler API. |
| 39 | * |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 40 | * The API allows to alter the target of the data behind the handler by another target (of the same type). Also resetting |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 41 | * a seekable output is possible with ::ly_out_reset() to re-write the output. |
| 42 | * |
| 43 | * @note |
| 44 | * This mechanism was introduced in libyang 2.0. To simplify transition from libyang 1.0 to version 2.0 and also for |
| 45 | * some simple use case where using the output handler would be an overkill, there are some basic printer functions |
| 46 | * that do not require output handler. But remember, that functionality of these function can be limited in particular cases |
| 47 | * in contrast to the functions using output handlers. |
| 48 | * |
| 49 | * Functions List |
| 50 | * -------------- |
| 51 | * - ::ly_out_new_clb() |
| 52 | * - ::ly_out_new_fd() |
| 53 | * - ::ly_out_new_file() |
| 54 | * - ::ly_out_new_filepath() |
| 55 | * - ::ly_out_new_memory() |
| 56 | * |
| 57 | * - ::ly_out_clb() |
| 58 | * - ::ly_out_clb_arg() |
| 59 | * - ::ly_out_fd() |
| 60 | * - ::ly_out_file() |
| 61 | * - ::ly_out_filepath() |
| 62 | * - ::ly_out_memory() |
| 63 | * |
| 64 | * - ::ly_out_type() |
| 65 | * - ::ly_out_printed() |
| 66 | * |
| 67 | * - ::ly_out_reset() |
| 68 | * - ::ly_out_free() |
| 69 | * |
| 70 | * - ::ly_print() |
| 71 | * - ::ly_print_flush() |
| 72 | * - ::ly_write() |
| 73 | * |
| 74 | * libyang Printers List |
| 75 | * -------------------- |
| 76 | * - @subpage howtoSchemaPrinters |
| 77 | * - @subpage howtoDataPrinters |
| 78 | */ |
| 79 | |
| 80 | /** |
| 81 | * @struct ly_out |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 82 | * @brief Printer output structure specifying where the data are printed. |
| 83 | */ |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 84 | struct ly_out; |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 85 | |
| 86 | /** |
Radek Krejci | 52f6555 | 2020-09-01 17:03:35 +0200 | [diff] [blame] | 87 | * @brief Common value for data as well as schema printers to avoid formatting indentations and new lines |
| 88 | */ |
| 89 | #define LY_PRINT_SHRINK 0x02 |
| 90 | |
| 91 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 92 | * @brief Types of the printer's output |
| 93 | */ |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 94 | typedef enum LY_OUT_TYPE { |
| 95 | LY_OUT_ERROR = -1, /**< error value to indicate failure of the functions returning LY_OUT_TYPE */ |
| 96 | LY_OUT_FD, /**< file descriptor printer */ |
| 97 | LY_OUT_FDSTREAM, /**< internal replacement for LY_OUT_FD in case vdprintf() is not available */ |
| 98 | LY_OUT_FILE, /**< FILE stream printer */ |
| 99 | LY_OUT_FILEPATH, /**< filepath printer */ |
| 100 | LY_OUT_MEMORY, /**< memory printer */ |
| 101 | LY_OUT_CALLBACK /**< callback printer */ |
| 102 | } LY_OUT_TYPE; |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * @brief Get output type of the printer handler. |
| 106 | * |
| 107 | * @param[in] out Printer handler. |
| 108 | * @return Type of the printer's output. |
| 109 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 110 | LIBYANG_API_DECL LY_OUT_TYPE ly_out_type(const struct ly_out *out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * @brief Reset the output medium to write from its beginning, so the following printer function will rewrite the current data |
| 114 | * instead of appending. |
| 115 | * |
| 116 | * Note that in case the underlying output is not seekable (stream referring a pipe/FIFO/socket or the callback output type), |
| 117 | * nothing actually happens despite the function succeeds. Also note that the medium is not returned to the state it was when |
Radek Krejci | c5a12e1 | 2020-05-27 17:09:59 +0200 | [diff] [blame] | 118 | * the handler was created. For example, file is seeked into the offset zero and truncated, the content from the time it was opened with |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 119 | * ::ly_out_new_file() is not restored. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 120 | * |
| 121 | * @param[in] out Printer handler. |
| 122 | * @return LY_SUCCESS in case of success |
| 123 | * @return LY_ESYS in case of failure |
| 124 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 125 | LIBYANG_API_DECL LY_ERR ly_out_reset(struct ly_out *out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 126 | |
| 127 | /** |
Michal Vasko | ce2b874 | 2020-08-24 13:20:25 +0200 | [diff] [blame] | 128 | * @brief Generic write callback for data printed by libyang. |
| 129 | * |
| 130 | * @param[in] user_data Optional caller-specific argument. |
| 131 | * @param[in] buf Data to write. |
| 132 | * @param[in] count Number of bytes to write. |
| 133 | * @return Number of printed bytes. |
| 134 | * @return Negative value in case of error. |
| 135 | */ |
| 136 | typedef ssize_t (*ly_write_clb)(void *user_data, const void *buf, size_t count); |
| 137 | |
| 138 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 139 | * @brief Create printer handler using callback printer function. |
| 140 | * |
| 141 | * @param[in] writeclb Pointer to the printer callback function writing the data (see write(2)). |
Michal Vasko | ce2b874 | 2020-08-24 13:20:25 +0200 | [diff] [blame] | 142 | * @param[in] user_data Optional caller-specific argument to be passed to the @p writeclb callback. |
Radek Krejci | 84ce7b1 | 2020-06-11 17:28:25 +0200 | [diff] [blame] | 143 | * @param[out] out Created printer handler supposed to be passed to different ly*_print() functions. |
| 144 | * @return LY_SUCCESS in case of success |
| 145 | * @return LY_EMEM in case allocating the @p out handler fails. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 146 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 147 | LIBYANG_API_DECL LY_ERR ly_out_new_clb(ly_write_clb writeclb, void *user_data, struct ly_out **out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * @brief Get or reset callback function associated with a callback printer handler. |
| 151 | * |
| 152 | * @param[in] out Printer handler. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 153 | * @param[in] writeclb Optional argument providing a new printer callback function for the handler. If NULL, only the current |
| 154 | * printer callback is returned. |
| 155 | * @return Previous printer callback. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 156 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 157 | LIBYANG_API_DECL ly_write_clb ly_out_clb(struct ly_out *out, ly_write_clb writeclb); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 158 | |
| 159 | /** |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 160 | * @brief Get or reset callback function's argument associated with a callback printer handler. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 161 | * |
| 162 | * @param[in] out Printer handler. |
| 163 | * @param[in] arg caller-specific argument to be passed to the callback function associated with the printer handler. |
| 164 | * If NULL, only the current file descriptor value is returned. |
| 165 | * @return The previous callback argument. |
| 166 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 167 | LIBYANG_API_DECL void *ly_out_clb_arg(struct ly_out *out, void *arg); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * @brief Create printer handler using file descriptor. |
| 171 | * |
| 172 | * @param[in] fd File descriptor to use. |
Radek Krejci | 84ce7b1 | 2020-06-11 17:28:25 +0200 | [diff] [blame] | 173 | * @param[out] out Created printer handler supposed to be passed to different ly*_print() functions. |
| 174 | * @return LY_SUCCESS in case of success |
| 175 | * @return LY_ERR value in case of failure. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 176 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 177 | LIBYANG_API_DECL LY_ERR ly_out_new_fd(int fd, struct ly_out **out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * @brief Get or reset file descriptor printer handler. |
| 181 | * |
| 182 | * @param[in] out Printer handler. |
| 183 | * @param[in] fd Optional value of a new file descriptor for the handler. If -1, only the current file descriptor value is returned. |
| 184 | * @return Previous value of the file descriptor. Note that caller is responsible for closing the returned file descriptor in case of setting new descriptor @p fd. |
| 185 | * @return -1 in case of error when setting up the new file descriptor. |
| 186 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 187 | LIBYANG_API_DECL int ly_out_fd(struct ly_out *out, int fd); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * @brief Create printer handler using file stream. |
| 191 | * |
| 192 | * @param[in] f File stream to use. |
Radek Krejci | 84ce7b1 | 2020-06-11 17:28:25 +0200 | [diff] [blame] | 193 | * @param[out] out Created printer handler supposed to be passed to different ly*_print() functions. |
| 194 | * @return LY_SUCCESS in case of success |
| 195 | * @return LY_ERR value in case of failure. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 196 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 197 | LIBYANG_API_DECL LY_ERR ly_out_new_file(FILE *f, struct ly_out **out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * @brief Get or reset file stream printer handler. |
| 201 | * |
| 202 | * @param[in] out Printer handler. |
| 203 | * @param[in] f Optional new file stream for the handler. If NULL, only the current file stream is returned. |
| 204 | * @return Previous file stream of the handler. Note that caller is responsible for closing the returned stream in case of setting new stream @p f. |
| 205 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 206 | LIBYANG_API_DECL FILE *ly_out_file(struct ly_out *out, FILE *f); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * @brief Create printer handler using memory to dump data. |
| 210 | * |
| 211 | * @param[in] strp Pointer to store the resulting data. If it points to a pointer to an allocated buffer and |
| 212 | * @p size of the buffer is set, the buffer is used (and extended if needed) to store the printed data. |
| 213 | * @param[in] size Size of the buffer provided via @p strp. In case it is 0, the buffer for the printed data |
| 214 | * is newly allocated even if @p strp points to a pointer to an existing buffer. |
Radek Krejci | 84ce7b1 | 2020-06-11 17:28:25 +0200 | [diff] [blame] | 215 | * @param[out] out Created printer handler supposed to be passed to different ly*_print() functions. |
| 216 | * @return LY_SUCCESS in case of success |
| 217 | * @return LY_ERR value in case of failure. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 218 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 219 | LIBYANG_API_DECL LY_ERR ly_out_new_memory(char **strp, size_t size, struct ly_out **out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * @brief Get or change memory where the data are dumped. |
| 223 | * |
| 224 | * @param[in] out Printer handler. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 225 | * @param[in] strp Optional new string pointer to store the resulting data, same rules as in ::ly_out_new_memory() are applied. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 226 | * @param[in] size Size of the buffer provided via @p strp. In case it is 0, the buffer for the printed data |
Radek Krejci | baeb838 | 2020-05-27 16:44:53 +0200 | [diff] [blame] | 227 | * is newly allocated even if @p strp points to a pointer to an existing buffer. In case the @p strp is NULL, this |
| 228 | * parameter is ignored. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 229 | * @return Previous dumped data. Note that the caller is responsible to free the data in case of changing string pointer @p strp. |
| 230 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 231 | LIBYANG_API_DECL char *ly_out_memory(struct ly_out *out, char **strp, size_t size); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * @brief Create printer handler file of the given filename. |
| 235 | * |
| 236 | * @param[in] filepath Path of the file where to write data. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 237 | * @param[out] out Created printer handler supposed to be passed to different ly*_print() functions. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 238 | * @return NULL in case of error. |
| 239 | * @return Created printer handler supposed to be passed to different ly*_print_*() functions. |
| 240 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 241 | LIBYANG_API_DECL LY_ERR ly_out_new_filepath(const char *filepath, struct ly_out **out); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * @brief Get or change the filepath of the file where the printer prints the data. |
| 245 | * |
| 246 | * Note that in case of changing the filepath, the current file is closed and a new one is |
| 247 | * created/opened instead of renaming the previous file. Also note that the previous filepath |
| 248 | * string is returned only in case of not changing it's value. |
| 249 | * |
| 250 | * @param[in] out Printer handler. |
| 251 | * @param[in] filepath Optional new filepath for the handler. If and only if NULL, the current filepath string is returned. |
| 252 | * @return Previous filepath string in case the @p filepath argument is NULL. |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 253 | * @return NULL if changing filepath succeeds and ((void *)-1) otherwise. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 254 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 255 | LIBYANG_API_DECL const char *ly_out_filepath(struct ly_out *out, const char *filepath); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * @brief Generic printer of the given format string into the specified output. |
| 259 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 260 | * Alternatively, ::ly_write() can be used. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 261 | * |
| 262 | * @param[in] out Output specification. |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 263 | * @param[in] format Format string to be printed. |
| 264 | * @return LY_ERR value, get number of the printed bytes using ::ly_out_printed. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 265 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 266 | LIBYANG_API_DECL LY_ERR ly_print(struct ly_out *out, const char *format, ...); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 267 | |
| 268 | /** |
Radek Krejci | 099fd21 | 2020-05-27 18:17:35 +0200 | [diff] [blame] | 269 | * @brief Flush the output from any internal buffers and clean any auxiliary data. |
| 270 | * @param[in] out Output specification. |
| 271 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 272 | LIBYANG_API_DECL void ly_print_flush(struct ly_out *out); |
Radek Krejci | 099fd21 | 2020-05-27 18:17:35 +0200 | [diff] [blame] | 273 | |
| 274 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 275 | * @brief Generic printer of the given string buffer into the specified output. |
| 276 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 277 | * Alternatively, ::ly_print() can be used. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 278 | * |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 279 | * @param[in] out Output specification. |
| 280 | * @param[in] buf Memory buffer with the data to print. |
| 281 | * @param[in] len Length of the data to print in the @p buf. |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 282 | * @return LY_ERR value, get number of the printed bytes using ::ly_out_printed. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 283 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 284 | LIBYANG_API_DECL LY_ERR ly_write(struct ly_out *out, const char *buf, size_t len); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 285 | |
| 286 | /** |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 287 | * @brief Get the number of printed bytes by the last function. |
| 288 | * |
| 289 | * @param[in] out Out structure used. |
| 290 | * @return Number of printed bytes. |
| 291 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 292 | LIBYANG_API_DECL size_t ly_out_printed(const struct ly_out *out); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 293 | |
| 294 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 295 | * @brief Free the printer handler. |
| 296 | * @param[in] out Printer handler to free. |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 297 | * @param[in] clb_arg_destructor Freeing function for printer callback (LY_OUT_CALLBACK) argument. |
| 298 | * @param[in] destroy Flag to free allocated buffer (for LY_OUT_MEMORY) or to |
| 299 | * close stream/file descriptor (for LY_OUT_FD, LY_OUT_FDSTREAM and LY_OUT_FILE) |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 300 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 301 | LIBYANG_API_DECL void ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), ly_bool destroy); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 302 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 303 | #ifdef __cplusplus |
| 304 | } |
| 305 | #endif |
| 306 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 307 | #endif /* LY_OUT_H_ */ |