blob: 0d2a46b3977445e2aff4389278da2adce63534e7 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
Michal Vaskoafac7822020-10-20 14:22:26 +02002 * @file out.c
Radek Krejcid3ca0632019-04-16 16:54:54 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoafac7822020-10-20 14:22:26 +02004 * @brief libyang output functions.
Radek Krejcid3ca0632019-04-16 16:54:54 +02005 *
Michal Vaskoafac7822020-10-20 14:22:26 +02006 * Copyright (c) 2015 - 2020 CESNET, z.s.p.o.
Radek Krejcid3ca0632019-04-16 16:54:54 +02007 *
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
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Michal Vaskoafac7822020-10-20 14:22:26 +020017#include "out.h"
18#include "out_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020019
20#include <assert.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020021#include <errno.h>
22#include <stdarg.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020023#include <stdio.h>
24#include <stdlib.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020025#include <string.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include <unistd.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020027
Radek Krejci535ea9f2020-05-29 16:01:05 +020028#include "common.h"
Michal Vasko5aa44c02020-06-29 11:47:02 +020029#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020030#include "log.h"
Michal Vasko9b368d32020-02-14 13:53:31 +010031#include "plugins_types.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020032#include "printer_data.h"
33#include "printer_internal.h"
34#include "tree.h"
35#include "tree_schema.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036
37/**
38 * @brief informational structure shared by printers
39 */
40struct ext_substmt_info_s ext_substmt_info[] = {
Radek Krejci0f969882020-08-21 16:56:47 +020041 {NULL, NULL, 0}, /**< LYEXT_SUBSTMT_SELF */
42 {"argument", "name", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_ARGUMENT */
43 {"base", "name", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_BASE */
44 {"belongs-to", "module", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_BELONGSTO */
45 {"contact", "text", SUBST_FLAG_YIN}, /**< LYEXT_SUBSTMT_CONTACT */
46 {"default", "value", 0}, /**< LYEXT_SUBSTMT_DEFAULT */
47 {"description", "text", SUBST_FLAG_YIN}, /**< LYEXT_SUBSTMT_DESCRIPTION */
48 {"error-app-tag", "value", 0}, /**< LYEXT_SUBSTMT_ERRTAG */
49 {"error-message", "value", SUBST_FLAG_YIN}, /**< LYEXT_SUBSTMT_ERRMSG */
50 {"key", "value", 0}, /**< LYEXT_SUBSTMT_KEY */
51 {"namespace", "uri", 0}, /**< LYEXT_SUBSTMT_NAMESPACE */
52 {"organization", "text", SUBST_FLAG_YIN}, /**< LYEXT_SUBSTMT_ORGANIZATION */
53 {"path", "value", 0}, /**< LYEXT_SUBSTMT_PATH */
54 {"prefix", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_PREFIX */
55 {"presence", "value", 0}, /**< LYEXT_SUBSTMT_PRESENCE */
56 {"reference", "text", SUBST_FLAG_YIN}, /**< LYEXT_SUBSTMT_REFERENCE */
57 {"revision-date", "date", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_REVISIONDATE */
58 {"units", "name", 0}, /**< LYEXT_SUBSTMT_UNITS */
59 {"value", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_VALUE */
60 {"yang-version", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_VERSION */
61 {"modifier", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_MODIFIER */
62 {"require-instance", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_REQINST */
63 {"yin-element", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_YINELEM */
64 {"config", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_CONFIG */
65 {"mandatory", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_MANDATORY */
66 {"ordered-by", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_ORDEREDBY */
67 {"status", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_STATUS */
68 {"fraction-digits", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_DIGITS */
69 {"max-elements", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_MAX */
70 {"min-elements", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_MIN */
71 {"position", "value", SUBST_FLAG_ID}, /**< LYEXT_SUBSTMT_POSITION */
72 {"unique", "tag", 0}, /**< LYEXT_SUBSTMT_UNIQUE */
Radek Krejcid3ca0632019-04-16 16:54:54 +020073};
74
Radek Krejci857189e2020-09-01 13:26:36 +020075ly_bool
Radek Krejci1deb5be2020-08-26 16:43:36 +020076ly_should_print(const struct lyd_node *node, uint32_t options)
Michal Vasko9b368d32020-02-14 13:53:31 +010077{
Michal Vasko56daf732020-08-10 10:57:18 +020078 const struct lyd_node *elem;
Michal Vasko9b368d32020-02-14 13:53:31 +010079
Radek Krejci7931b192020-06-25 17:05:03 +020080 if (options & LYD_PRINT_WD_TRIM) {
Michal Vasko9b368d32020-02-14 13:53:31 +010081 /* do not print default nodes */
82 if (node->flags & LYD_DEFAULT) {
83 /* implicit default node/NP container with only default nodes */
84 return 0;
85 } else if (node->schema->nodetype & LYD_NODE_TERM) {
Radek Krejci19611252020-10-04 13:54:53 +020086 if (lyd_is_default(node)) {
Michal Vasko9b368d32020-02-14 13:53:31 +010087 /* explicit default node */
88 return 0;
89 }
90 }
Radek Krejci7931b192020-06-25 17:05:03 +020091 } else if ((node->flags & LYD_DEFAULT) && !(options & LYD_PRINT_WD_MASK) && !(node->schema->flags & LYS_CONFIG_R)) {
Radek Krejci241f6b52020-05-21 18:13:49 +020092 /* LYDP_WD_EXPLICIT
Michal Vasko9b368d32020-02-14 13:53:31 +010093 * - print only if it contains status data in its subtree */
Michal Vasko56daf732020-08-10 10:57:18 +020094 LYD_TREE_DFS_BEGIN(node, elem) {
Michal Vaskodb4f9e42020-06-01 17:29:56 +020095 if ((elem->schema->nodetype != LYS_CONTAINER) || (elem->schema->flags & LYS_PRESENCE)) {
96 if (elem->schema->flags & LYS_CONFIG_R) {
97 return 1;
98 }
Michal Vasko9b368d32020-02-14 13:53:31 +010099 }
Michal Vasko56daf732020-08-10 10:57:18 +0200100 LYD_TREE_DFS_END(node, elem)
Michal Vasko9b368d32020-02-14 13:53:31 +0100101 }
102 return 0;
Radek Krejci7931b192020-06-25 17:05:03 +0200103 } else if ((node->flags & LYD_DEFAULT) && (node->schema->nodetype == LYS_CONTAINER) && !(options & LYD_PRINT_KEEPEMPTYCONT)) {
Michal Vasko9b368d32020-02-14 13:53:31 +0100104 /* avoid empty default containers */
Michal Vasko56daf732020-08-10 10:57:18 +0200105 LYD_TREE_DFS_BEGIN(node, elem) {
Michal Vasko9b368d32020-02-14 13:53:31 +0100106 if (elem->schema->nodetype != LYS_CONTAINER) {
107 return 1;
108 }
109 assert(elem->flags & LYD_DEFAULT);
Michal Vasko56daf732020-08-10 10:57:18 +0200110 LYD_TREE_DFS_END(node, elem)
Michal Vasko9b368d32020-02-14 13:53:31 +0100111 }
112 return 0;
113 }
114
115 return 1;
116}
117
Radek Krejci241f6b52020-05-21 18:13:49 +0200118API LY_OUT_TYPE
119ly_out_type(const struct ly_out *out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100120{
Radek Krejci241f6b52020-05-21 18:13:49 +0200121 LY_CHECK_ARG_RET(NULL, out, LY_OUT_ERROR);
Radek Krejcia5bba312020-01-09 15:41:20 +0100122 return out->type;
123}
124
Radek Krejci84ce7b12020-06-11 17:28:25 +0200125API LY_ERR
Michal Vaskoce2b8742020-08-24 13:20:25 +0200126ly_out_new_clb(ly_write_clb writeclb, void *user_data, struct ly_out **out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100127{
Radek Krejci84ce7b12020-06-11 17:28:25 +0200128 LY_CHECK_ARG_RET(NULL, out, writeclb, LY_EINVAL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100129
Radek Krejci84ce7b12020-06-11 17:28:25 +0200130 *out = calloc(1, sizeof **out);
131 LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
Radek Krejcia5bba312020-01-09 15:41:20 +0100132
Radek Krejci84ce7b12020-06-11 17:28:25 +0200133 (*out)->type = LY_OUT_CALLBACK;
134 (*out)->method.clb.func = writeclb;
Michal Vaskoce2b8742020-08-24 13:20:25 +0200135 (*out)->method.clb.arg = user_data;
Radek Krejcia5bba312020-01-09 15:41:20 +0100136
Radek Krejci84ce7b12020-06-11 17:28:25 +0200137 return LY_SUCCESS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100138}
139
Michal Vasko69730152020-10-09 16:30:07 +0200140API ly_write_clb
141ly_out_clb(struct ly_out *out, ly_write_clb writeclb)
Radek Krejcia5bba312020-01-09 15:41:20 +0100142{
143 void *prev_clb;
144
Radek Krejci241f6b52020-05-21 18:13:49 +0200145 LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_CALLBACK, NULL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100146
147 prev_clb = out->method.clb.func;
148
149 if (writeclb) {
150 out->method.clb.func = writeclb;
151 }
152
153 return prev_clb;
154}
155
156API void *
Radek Krejci241f6b52020-05-21 18:13:49 +0200157ly_out_clb_arg(struct ly_out *out, void *arg)
Radek Krejcia5bba312020-01-09 15:41:20 +0100158{
159 void *prev_arg;
160
Radek Krejci241f6b52020-05-21 18:13:49 +0200161 LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_CALLBACK, NULL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100162
163 prev_arg = out->method.clb.arg;
164
165 if (arg) {
166 out->method.clb.arg = arg;
167 }
168
169 return prev_arg;
170}
171
Radek Krejci84ce7b12020-06-11 17:28:25 +0200172API LY_ERR
173ly_out_new_fd(int fd, struct ly_out **out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100174{
Radek Krejci84ce7b12020-06-11 17:28:25 +0200175 LY_CHECK_ARG_RET(NULL, out, fd != -1, LY_EINVAL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100176
Radek Krejci84ce7b12020-06-11 17:28:25 +0200177 *out = calloc(1, sizeof **out);
178 LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
Radek Krejci84ce7b12020-06-11 17:28:25 +0200179 (*out)->type = LY_OUT_FD;
180 (*out)->method.fd = fd;
Radek Krejcia5bba312020-01-09 15:41:20 +0100181
Radek Krejci84ce7b12020-06-11 17:28:25 +0200182 return LY_SUCCESS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100183}
184
185API int
Radek Krejci241f6b52020-05-21 18:13:49 +0200186ly_out_fd(struct ly_out *out, int fd)
Radek Krejcia5bba312020-01-09 15:41:20 +0100187{
188 int prev_fd;
189
Radek Krejci241f6b52020-05-21 18:13:49 +0200190 LY_CHECK_ARG_RET(NULL, out, out->type <= LY_OUT_FDSTREAM, -1);
Radek Krejcia5bba312020-01-09 15:41:20 +0100191
Radek Krejci241f6b52020-05-21 18:13:49 +0200192 if (out->type == LY_OUT_FDSTREAM) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100193 prev_fd = out->method.fdstream.fd;
Radek Krejci241f6b52020-05-21 18:13:49 +0200194 } else { /* LY_OUT_FD */
Radek Krejcia5bba312020-01-09 15:41:20 +0100195 prev_fd = out->method.fd;
196 }
197
198 if (fd != -1) {
199 /* replace output stream */
Radek Krejci241f6b52020-05-21 18:13:49 +0200200 if (out->type == LY_OUT_FDSTREAM) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100201 int streamfd;
202 FILE *stream;
203
204 streamfd = dup(fd);
205 if (streamfd < 0) {
206 LOGERR(NULL, LY_ESYS, "Unable to duplicate provided file descriptor (%d) for printing the output (%s).", fd, strerror(errno));
207 return -1;
208 }
209 stream = fdopen(streamfd, "a");
210 if (!stream) {
211 LOGERR(NULL, LY_ESYS, "Unable to open provided file descriptor (%d) for printing the output (%s).", fd, strerror(errno));
212 close(streamfd);
213 return -1;
214 }
215 /* close only the internally created stream, file descriptor is returned and supposed to be closed by the caller */
216 fclose(out->method.fdstream.f);
217 out->method.fdstream.f = stream;
218 out->method.fdstream.fd = streamfd;
Radek Krejci241f6b52020-05-21 18:13:49 +0200219 } else { /* LY_OUT_FD */
Radek Krejcia5bba312020-01-09 15:41:20 +0100220 out->method.fd = fd;
221 }
222 }
223
224 return prev_fd;
225}
226
Radek Krejci84ce7b12020-06-11 17:28:25 +0200227API LY_ERR
228ly_out_new_file(FILE *f, struct ly_out **out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100229{
Radek Krejci84ce7b12020-06-11 17:28:25 +0200230 LY_CHECK_ARG_RET(NULL, out, f, LY_EINVAL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100231
Radek Krejci84ce7b12020-06-11 17:28:25 +0200232 *out = calloc(1, sizeof **out);
233 LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
Radek Krejcia5bba312020-01-09 15:41:20 +0100234
Radek Krejci84ce7b12020-06-11 17:28:25 +0200235 (*out)->type = LY_OUT_FILE;
236 (*out)->method.f = f;
Radek Krejcia5bba312020-01-09 15:41:20 +0100237
Radek Krejci84ce7b12020-06-11 17:28:25 +0200238 return LY_SUCCESS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100239}
240
241API FILE *
Radek Krejci241f6b52020-05-21 18:13:49 +0200242ly_out_file(struct ly_out *out, FILE *f)
Radek Krejcia5bba312020-01-09 15:41:20 +0100243{
244 FILE *prev_f;
245
Radek Krejci241f6b52020-05-21 18:13:49 +0200246 LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_FILE, NULL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100247
248 prev_f = out->method.f;
249
250 if (f) {
251 out->method.f = f;
252 }
253
254 return prev_f;
255}
256
Radek Krejci84ce7b12020-06-11 17:28:25 +0200257API LY_ERR
258ly_out_new_memory(char **strp, size_t size, struct ly_out **out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100259{
Radek Krejci84ce7b12020-06-11 17:28:25 +0200260 LY_CHECK_ARG_RET(NULL, out, strp, LY_EINVAL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100261
Radek Krejci84ce7b12020-06-11 17:28:25 +0200262 *out = calloc(1, sizeof **out);
263 LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
Radek Krejcia5bba312020-01-09 15:41:20 +0100264
Radek Krejci84ce7b12020-06-11 17:28:25 +0200265 (*out)->type = LY_OUT_MEMORY;
266 (*out)->method.mem.buf = strp;
Radek Krejcia5bba312020-01-09 15:41:20 +0100267 if (!size) {
268 /* buffer is supposed to be allocated */
269 *strp = NULL;
270 } else if (*strp) {
271 /* there is already buffer to use */
Radek Krejci84ce7b12020-06-11 17:28:25 +0200272 (*out)->method.mem.size = size;
Radek Krejcia5bba312020-01-09 15:41:20 +0100273 }
274
Radek Krejci84ce7b12020-06-11 17:28:25 +0200275 return LY_SUCCESS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100276}
277
278char *
Radek Krejci241f6b52020-05-21 18:13:49 +0200279ly_out_memory(struct ly_out *out, char **strp, size_t size)
Radek Krejcia5bba312020-01-09 15:41:20 +0100280{
281 char *data;
282
Radek Krejci241f6b52020-05-21 18:13:49 +0200283 LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_MEMORY, NULL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100284
285 data = *out->method.mem.buf;
286
287 if (strp) {
288 out->method.mem.buf = strp;
289 out->method.mem.len = out->method.mem.size = 0;
290 out->printed = 0;
291 if (!size) {
292 /* buffer is supposed to be allocated */
293 *strp = NULL;
294 } else if (*strp) {
295 /* there is already buffer to use */
296 out->method.mem.size = size;
297 }
298 }
299
300 return data;
301}
302
303API LY_ERR
Radek Krejci241f6b52020-05-21 18:13:49 +0200304ly_out_reset(struct ly_out *out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100305{
306 LY_CHECK_ARG_RET(NULL, out, LY_EINVAL);
307
Michal Vaskod989ba02020-08-24 10:59:24 +0200308 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200309 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100310 LOGINT(NULL);
311 return LY_EINT;
Radek Krejci241f6b52020-05-21 18:13:49 +0200312 case LY_OUT_FD:
Michal Vasko69730152020-10-09 16:30:07 +0200313 if ((lseek(out->method.fd, 0, SEEK_SET) == -1) && (errno != ESPIPE)) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100314 LOGERR(NULL, LY_ESYS, "Seeking output file descriptor failed (%s).", strerror(errno));
315 return LY_ESYS;
316 }
Michal Vasko69730152020-10-09 16:30:07 +0200317 if ((errno != ESPIPE) && (ftruncate(out->method.fd, 0) == -1)) {
Radek Krejcic5a12e12020-05-27 17:09:59 +0200318 LOGERR(NULL, LY_ESYS, "Truncating output file failed (%s).", strerror(errno));
319 return LY_ESYS;
320 }
Radek Krejcia5bba312020-01-09 15:41:20 +0100321 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200322 case LY_OUT_FDSTREAM:
323 case LY_OUT_FILE:
324 case LY_OUT_FILEPATH:
Michal Vasko69730152020-10-09 16:30:07 +0200325 if ((fseek(out->method.f, 0, SEEK_SET) == -1) && (errno != ESPIPE)) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100326 LOGERR(NULL, LY_ESYS, "Seeking output file stream failed (%s).", strerror(errno));
327 return LY_ESYS;
328 }
Michal Vasko69730152020-10-09 16:30:07 +0200329 if ((errno != ESPIPE) && (ftruncate(fileno(out->method.f), 0) == -1)) {
Radek Krejcic5a12e12020-05-27 17:09:59 +0200330 LOGERR(NULL, LY_ESYS, "Truncating output file failed (%s).", strerror(errno));
331 return LY_ESYS;
332 }
Radek Krejcia5bba312020-01-09 15:41:20 +0100333 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200334 case LY_OUT_MEMORY:
Radek Krejcic5a12e12020-05-27 17:09:59 +0200335 if (out->method.mem.buf && *out->method.mem.buf) {
336 memset(*out->method.mem.buf, 0, out->method.mem.len);
337 }
Radek Krejcia5bba312020-01-09 15:41:20 +0100338 out->printed = 0;
339 out->method.mem.len = 0;
340 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200341 case LY_OUT_CALLBACK:
Radek Krejcia5bba312020-01-09 15:41:20 +0100342 /* nothing to do (not seekable) */
343 break;
344 }
345
346 return LY_SUCCESS;
347}
348
Radek Krejci84ce7b12020-06-11 17:28:25 +0200349API LY_ERR
350ly_out_new_filepath(const char *filepath, struct ly_out **out)
Radek Krejcia5bba312020-01-09 15:41:20 +0100351{
Radek Krejci84ce7b12020-06-11 17:28:25 +0200352 LY_CHECK_ARG_RET(NULL, out, filepath, LY_EINVAL);
Radek Krejcia5bba312020-01-09 15:41:20 +0100353
Radek Krejci84ce7b12020-06-11 17:28:25 +0200354 *out = calloc(1, sizeof **out);
355 LY_CHECK_ERR_RET(!*out, LOGMEM(NULL), LY_EMEM);
Radek Krejcia5bba312020-01-09 15:41:20 +0100356
Radek Krejci84ce7b12020-06-11 17:28:25 +0200357 (*out)->type = LY_OUT_FILEPATH;
358 (*out)->method.fpath.f = fopen(filepath, "w");
359 if (!(*out)->method.fpath.f) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100360 LOGERR(NULL, LY_ESYS, "Failed to open file \"%s\" (%s).", filepath, strerror(errno));
Radek Krejcif6923e82020-07-02 16:36:53 +0200361 free(*out);
362 *out = NULL;
Radek Krejci84ce7b12020-06-11 17:28:25 +0200363 return LY_ESYS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100364 }
Radek Krejci84ce7b12020-06-11 17:28:25 +0200365 (*out)->method.fpath.filepath = strdup(filepath);
366 return LY_SUCCESS;
Radek Krejcia5bba312020-01-09 15:41:20 +0100367}
368
369API const char *
Radek Krejci241f6b52020-05-21 18:13:49 +0200370ly_out_filepath(struct ly_out *out, const char *filepath)
Radek Krejcia5bba312020-01-09 15:41:20 +0100371{
372 FILE *f;
373
Radek Krejci241f6b52020-05-21 18:13:49 +0200374 LY_CHECK_ARG_RET(NULL, out, out->type == LY_OUT_FILEPATH, filepath ? NULL : ((void *)-1));
Radek Krejcia5bba312020-01-09 15:41:20 +0100375
376 if (!filepath) {
377 return out->method.fpath.filepath;
378 }
379
380 /* replace filepath */
381 f = out->method.fpath.f;
382 out->method.fpath.f = fopen(filepath, "w");
383 if (!out->method.fpath.f) {
384 LOGERR(NULL, LY_ESYS, "Failed to open file \"%s\" (%s).", filepath, strerror(errno));
385 out->method.fpath.f = f;
Michal Vasko69730152020-10-09 16:30:07 +0200386 return (void *)-1;
Radek Krejcia5bba312020-01-09 15:41:20 +0100387 }
388 fclose(f);
389 free(out->method.fpath.filepath);
390 out->method.fpath.filepath = strdup(filepath);
391
392 return NULL;
393}
394
395API void
Radek Krejci857189e2020-09-01 13:26:36 +0200396ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), ly_bool destroy)
Radek Krejcia5bba312020-01-09 15:41:20 +0100397{
398 if (!out) {
399 return;
400 }
401
402 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200403 case LY_OUT_CALLBACK:
Radek Krejcia5bba312020-01-09 15:41:20 +0100404 if (clb_arg_destructor) {
405 clb_arg_destructor(out->method.clb.arg);
406 }
407 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200408 case LY_OUT_FDSTREAM:
Radek Krejcia5bba312020-01-09 15:41:20 +0100409 fclose(out->method.fdstream.f);
410 if (destroy) {
411 close(out->method.fdstream.fd);
412 }
413 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200414 case LY_OUT_FD:
Radek Krejcia5bba312020-01-09 15:41:20 +0100415 if (destroy) {
416 close(out->method.fd);
417 }
418 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200419 case LY_OUT_FILE:
Radek Krejcia5bba312020-01-09 15:41:20 +0100420 if (destroy) {
421 fclose(out->method.f);
422 }
423 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200424 case LY_OUT_MEMORY:
Radek Krejcia5bba312020-01-09 15:41:20 +0100425 if (destroy) {
426 free(*out->method.mem.buf);
427 }
428 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200429 case LY_OUT_FILEPATH:
Radek Krejcia5bba312020-01-09 15:41:20 +0100430 free(out->method.fpath.filepath);
Radek Krejci2aae3752020-05-27 18:16:30 +0200431 fclose(out->method.fpath.f);
Radek Krejcia5bba312020-01-09 15:41:20 +0100432 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200433 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100434 LOGINT(NULL);
435 }
436 free(out);
437}
438
Michal Vasko5233e962020-08-14 14:26:20 +0200439static LY_ERR
440ly_vprint_(struct ly_out *out, const char *format, va_list ap)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200441{
Michal Vasko5233e962020-08-14 14:26:20 +0200442 LY_ERR ret;
443 int written = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 char *msg = NULL, *aux;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200445
446 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200447 case LY_OUT_FD:
Michal Vasko5233e962020-08-14 14:26:20 +0200448 written = vdprintf(out->method.fd, format, ap);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200450 case LY_OUT_FDSTREAM:
451 case LY_OUT_FILEPATH:
452 case LY_OUT_FILE:
Michal Vasko5233e962020-08-14 14:26:20 +0200453 written = vfprintf(out->method.f, format, ap);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200454 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200455 case LY_OUT_MEMORY:
Michal Vasko5233e962020-08-14 14:26:20 +0200456 if ((written = vasprintf(&msg, format, ap)) < 0) {
Radek Krejci897ad2e2019-04-29 16:43:07 +0200457 break;
458 }
Michal Vasko5233e962020-08-14 14:26:20 +0200459 if (out->method.mem.len + written + 1 > out->method.mem.size) {
460 aux = ly_realloc(*out->method.mem.buf, out->method.mem.len + written + 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 if (!aux) {
462 out->method.mem.buf = NULL;
463 out->method.mem.len = 0;
464 out->method.mem.size = 0;
465 LOGMEM(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200466 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467 }
Radek Krejcia5bba312020-01-09 15:41:20 +0100468 *out->method.mem.buf = aux;
Michal Vasko5233e962020-08-14 14:26:20 +0200469 out->method.mem.size = out->method.mem.len + written + 1;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200470 }
Michal Vasko5233e962020-08-14 14:26:20 +0200471 memcpy(&(*out->method.mem.buf)[out->method.mem.len], msg, written);
472 out->method.mem.len += written;
Radek Krejcia5bba312020-01-09 15:41:20 +0100473 (*out->method.mem.buf)[out->method.mem.len] = '\0';
Radek Krejcid3ca0632019-04-16 16:54:54 +0200474 free(msg);
475 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200476 case LY_OUT_CALLBACK:
Michal Vasko5233e962020-08-14 14:26:20 +0200477 if ((written = vasprintf(&msg, format, ap)) < 0) {
Radek Krejci897ad2e2019-04-29 16:43:07 +0200478 break;
479 }
Michal Vasko5233e962020-08-14 14:26:20 +0200480 written = out->method.clb.func(out->method.clb.arg, msg, written);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481 free(msg);
482 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200483 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100484 LOGINT(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200485 return LY_EINT;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486 }
487
Michal Vasko5233e962020-08-14 14:26:20 +0200488 if (written < 0) {
489 LOGERR(NULL, LY_ESYS, "%s: writing data failed (%s).", __func__, strerror(errno));
490 written = 0;
491 ret = LY_ESYS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200492 } else {
Radek Krejci241f6b52020-05-21 18:13:49 +0200493 if (out->type == LY_OUT_FDSTREAM) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100494 /* move the original file descriptor to the end of the output file */
495 lseek(out->method.fdstream.fd, 0, SEEK_END);
496 }
Michal Vasko5233e962020-08-14 14:26:20 +0200497 ret = LY_SUCCESS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200498 }
Michal Vasko5233e962020-08-14 14:26:20 +0200499
500 out->printed += written;
501 out->func_printed += written;
502 return ret;
503}
504
505LY_ERR
506ly_print_(struct ly_out *out, const char *format, ...)
507{
508 LY_ERR ret;
509 va_list ap;
510
511 va_start(ap, format);
512 ret = ly_vprint_(out, format, ap);
513 va_end(ap);
514
515 return ret;
516}
517
518API LY_ERR
519ly_print(struct ly_out *out, const char *format, ...)
520{
521 LY_ERR ret;
522 va_list ap;
523
524 out->func_printed = 0;
525
526 va_start(ap, format);
527 ret = ly_vprint_(out, format, ap);
528 va_end(ap);
529
530 return ret;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531}
532
Radek Krejci2aae3752020-05-27 18:16:30 +0200533API void
Radek Krejci241f6b52020-05-21 18:13:49 +0200534ly_print_flush(struct ly_out *out)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535{
536 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200537 case LY_OUT_FDSTREAM:
Radek Krejcia5bba312020-01-09 15:41:20 +0100538 /* move the original file descriptor to the end of the output file */
539 lseek(out->method.fdstream.fd, 0, SEEK_END);
540 fflush(out->method.fdstream.f);
541 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200542 case LY_OUT_FILEPATH:
543 case LY_OUT_FILE:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200544 fflush(out->method.f);
545 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200546 case LY_OUT_FD:
Radek Krejcie7b95092019-05-15 11:03:07 +0200547 fsync(out->method.fd);
548 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200549 case LY_OUT_MEMORY:
550 case LY_OUT_CALLBACK:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200551 /* nothing to do */
552 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200553 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100554 LOGINT(NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200555 }
Radek Krejcie7b95092019-05-15 11:03:07 +0200556
557 free(out->buffered);
558 out->buf_size = out->buf_len = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200559}
560
Michal Vasko5233e962020-08-14 14:26:20 +0200561LY_ERR
562ly_write_(struct ly_out *out, const char *buf, size_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200564 LY_ERR ret = LY_SUCCESS;
565 size_t written = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200566
567 if (out->hole_count) {
568 /* we are buffering data after a hole */
Radek Krejcie7b95092019-05-15 11:03:07 +0200569 if (out->buf_len + len > out->buf_size) {
570 out->buffered = ly_realloc(out->buffered, out->buf_len + len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200571 if (!out->buffered) {
572 out->buf_len = 0;
573 out->buf_size = 0;
Radek Krejcibaeb8382020-05-27 16:44:53 +0200574 LOGMEM(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200575 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200576 }
Radek Krejcie7b95092019-05-15 11:03:07 +0200577 out->buf_size = out->buf_len + len;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200578 }
579
Radek Krejcie7b95092019-05-15 11:03:07 +0200580 memcpy(&out->buffered[out->buf_len], buf, len);
581 out->buf_len += len;
Michal Vasko5233e962020-08-14 14:26:20 +0200582
583 out->printed += len;
584 out->func_printed += len;
585 return LY_SUCCESS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200586 }
587
Radek Krejci897ad2e2019-04-29 16:43:07 +0200588repeat:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200589 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200590 case LY_OUT_MEMORY:
Radek Krejcie7b95092019-05-15 11:03:07 +0200591 if (out->method.mem.len + len + 1 > out->method.mem.size) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100592 *out->method.mem.buf = ly_realloc(*out->method.mem.buf, out->method.mem.len + len + 1);
593 if (!*out->method.mem.buf) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200594 out->method.mem.len = 0;
595 out->method.mem.size = 0;
Radek Krejcibaeb8382020-05-27 16:44:53 +0200596 LOGMEM(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200597 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200598 }
Radek Krejcie7b95092019-05-15 11:03:07 +0200599 out->method.mem.size = out->method.mem.len + len + 1;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200600 }
Radek Krejcia5bba312020-01-09 15:41:20 +0100601 memcpy(&(*out->method.mem.buf)[out->method.mem.len], buf, len);
Radek Krejcie7b95092019-05-15 11:03:07 +0200602 out->method.mem.len += len;
Radek Krejcia5bba312020-01-09 15:41:20 +0100603 (*out->method.mem.buf)[out->method.mem.len] = '\0';
Radek Krejci897ad2e2019-04-29 16:43:07 +0200604
Michal Vasko5233e962020-08-14 14:26:20 +0200605 written = len;
606 break;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200607 case LY_OUT_FD: {
608 ssize_t r;
609 r = write(out->method.fd, buf, len);
610 if (r < 0) {
611 ret = LY_ESYS;
612 } else {
613 written = (size_t)r;
614 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200615 break;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200616 }
Radek Krejci241f6b52020-05-21 18:13:49 +0200617 case LY_OUT_FDSTREAM:
618 case LY_OUT_FILEPATH:
619 case LY_OUT_FILE:
Michal Vasko63f3d842020-07-08 10:10:14 +0200620 written = fwrite(buf, sizeof *buf, len, out->method.f);
Radek Krejci1deb5be2020-08-26 16:43:36 +0200621 if (written != len) {
622 ret = LY_ESYS;
623 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200624 break;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200625 case LY_OUT_CALLBACK: {
626 ssize_t r;
627 r = out->method.clb.func(out->method.clb.arg, buf, len);
628 if (r < 0) {
629 ret = LY_ESYS;
630 } else {
631 written = (size_t)r;
632 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200633 break;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200634 }
Radek Krejci241f6b52020-05-21 18:13:49 +0200635 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100636 LOGINT(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200637 return LY_EINT;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200638 }
639
Radek Krejci1deb5be2020-08-26 16:43:36 +0200640 if (ret) {
Michal Vasko69730152020-10-09 16:30:07 +0200641 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
Radek Krejci1deb5be2020-08-26 16:43:36 +0200642 ret = LY_SUCCESS;
Radek Krejci897ad2e2019-04-29 16:43:07 +0200643 goto repeat;
644 }
Michal Vasko5233e962020-08-14 14:26:20 +0200645 LOGERR(NULL, LY_ESYS, "%s: writing data failed (%s).", __func__, strerror(errno));
646 written = 0;
Radek Krejcie7b95092019-05-15 11:03:07 +0200647 } else if ((size_t)written != len) {
Michal Vasko5233e962020-08-14 14:26:20 +0200648 LOGERR(NULL, LY_ESYS, "%s: writing data failed (unable to write %u from %u data).", __func__,
Michal Vasko69730152020-10-09 16:30:07 +0200649 len - (size_t)written, len);
Michal Vasko5233e962020-08-14 14:26:20 +0200650 ret = LY_ESYS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200651 } else {
Radek Krejci241f6b52020-05-21 18:13:49 +0200652 if (out->type == LY_OUT_FDSTREAM) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100653 /* move the original file descriptor to the end of the output file */
654 lseek(out->method.fdstream.fd, 0, SEEK_END);
655 }
Michal Vasko5233e962020-08-14 14:26:20 +0200656 ret = LY_SUCCESS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200657 }
Michal Vasko5233e962020-08-14 14:26:20 +0200658
659 out->printed += written;
660 out->func_printed += written;
661 return ret;
662}
663
664API LY_ERR
665ly_write(struct ly_out *out, const char *buf, size_t len)
666{
667 out->func_printed = 0;
668
669 return ly_write_(out, buf, len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200670}
671
Michal Vasko63f3d842020-07-08 10:10:14 +0200672API size_t
673ly_out_printed(const struct ly_out *out)
674{
675 return out->func_printed;
676}
677
Michal Vasko5233e962020-08-14 14:26:20 +0200678LY_ERR
Radek Krejci241f6b52020-05-21 18:13:49 +0200679ly_write_skip(struct ly_out *out, size_t count, size_t *position)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200680{
681 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200682 case LY_OUT_MEMORY:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200683 if (out->method.mem.len + count > out->method.mem.size) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100684 *out->method.mem.buf = ly_realloc(*out->method.mem.buf, out->method.mem.len + count);
685 if (!(*out->method.mem.buf)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200686 out->method.mem.len = 0;
687 out->method.mem.size = 0;
Michal Vasko5233e962020-08-14 14:26:20 +0200688 LOGMEM(NULL);
689 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200690 }
691 out->method.mem.size = out->method.mem.len + count;
692 }
693
694 /* save the current position */
695 *position = out->method.mem.len;
696
697 /* skip the memory */
698 out->method.mem.len += count;
699 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200700 case LY_OUT_FD:
701 case LY_OUT_FDSTREAM:
702 case LY_OUT_FILEPATH:
703 case LY_OUT_FILE:
704 case LY_OUT_CALLBACK:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200705 /* buffer the hole */
706 if (out->buf_len + count > out->buf_size) {
707 out->buffered = ly_realloc(out->buffered, out->buf_len + count);
708 if (!out->buffered) {
709 out->buf_len = 0;
710 out->buf_size = 0;
Radek Krejcibaeb8382020-05-27 16:44:53 +0200711 LOGMEM(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200712 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200713 }
714 out->buf_size = out->buf_len + count;
715 }
716
717 /* save the current position */
718 *position = out->buf_len;
719
720 /* skip the memory */
721 out->buf_len += count;
722
723 /* increase hole counter */
724 ++out->hole_count;
Radek Krejcia5bba312020-01-09 15:41:20 +0100725 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200726 case LY_OUT_ERROR:
Radek Krejcia5bba312020-01-09 15:41:20 +0100727 LOGINT(NULL);
Michal Vasko5233e962020-08-14 14:26:20 +0200728 return LY_EINT;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200729 }
730
Michal Vasko5233e962020-08-14 14:26:20 +0200731 /* update printed bytes counter despite we actually printed just a hole */
732 out->printed += count;
733 out->func_printed += count;
734 return LY_SUCCESS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200735}
736
Michal Vasko66d99972020-06-29 13:37:42 +0200737LY_ERR
Radek Krejci241f6b52020-05-21 18:13:49 +0200738ly_write_skipped(struct ly_out *out, size_t position, const char *buf, size_t count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200739{
Michal Vasko66d99972020-06-29 13:37:42 +0200740 LY_ERR ret = LY_SUCCESS;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741
742 switch (out->type) {
Radek Krejci241f6b52020-05-21 18:13:49 +0200743 case LY_OUT_MEMORY:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200744 /* write */
Radek Krejcia5bba312020-01-09 15:41:20 +0100745 memcpy(&(*out->method.mem.buf)[position], buf, count);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200746 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200747 case LY_OUT_FD:
748 case LY_OUT_FDSTREAM:
749 case LY_OUT_FILEPATH:
750 case LY_OUT_FILE:
751 case LY_OUT_CALLBACK:
Radek Krejcid3ca0632019-04-16 16:54:54 +0200752 if (out->buf_len < position + count) {
Michal Vasko5233e962020-08-14 14:26:20 +0200753 LOGMEM(NULL);
754 return LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200755 }
756
757 /* write into the hole */
758 memcpy(&out->buffered[position], buf, count);
759
760 /* decrease hole counter */
761 --out->hole_count;
762
763 if (!out->hole_count) {
Radek Krejci897ad2e2019-04-29 16:43:07 +0200764 /* all holes filled, we can write the buffer,
Michal Vasko5233e962020-08-14 14:26:20 +0200765 * printed bytes counter is updated by ly_write_() */
766 ret = ly_write_(out, out->buffered, out->buf_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200767 out->buf_len = 0;
768 }
769 break;
Radek Krejci241f6b52020-05-21 18:13:49 +0200770 case LY_OUT_ERROR:
Michal Vasko5233e962020-08-14 14:26:20 +0200771 LOGINT(NULL);
772 return LY_EINT;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773 }
774
Radek Krejci241f6b52020-05-21 18:13:49 +0200775 if (out->type == LY_OUT_FILEPATH) {
Radek Krejcia5bba312020-01-09 15:41:20 +0100776 /* move the original file descriptor to the end of the output file */
777 lseek(out->method.fdstream.fd, 0, SEEK_END);
778 }
Michal Vasko66d99972020-06-29 13:37:42 +0200779 return ret;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200780}