printers CHANGE reset (clean) output content by ly_out_reset()
diff --git a/src/printer.c b/src/printer.c
index 4eb6b74..1fd8047 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -374,6 +374,10 @@
LOGERR(NULL, LY_ESYS, "Seeking output file descriptor failed (%s).", strerror(errno));
return LY_ESYS;
}
+ if (errno != ESPIPE && ftruncate(out->method.fd, 0) == -1) {
+ LOGERR(NULL, LY_ESYS, "Truncating output file failed (%s).", strerror(errno));
+ return LY_ESYS;
+ }
break;
case LY_OUT_FDSTREAM:
case LY_OUT_FILE:
@@ -382,8 +386,15 @@
LOGERR(NULL, LY_ESYS, "Seeking output file stream failed (%s).", strerror(errno));
return LY_ESYS;
}
+ if (errno != ESPIPE && ftruncate(fileno(out->method.f), 0) == -1) {
+ LOGERR(NULL, LY_ESYS, "Truncating output file failed (%s).", strerror(errno));
+ return LY_ESYS;
+ }
break;
case LY_OUT_MEMORY:
+ if (out->method.mem.buf && *out->method.mem.buf) {
+ memset(*out->method.mem.buf, 0, out->method.mem.len);
+ }
out->printed = 0;
out->method.mem.len = 0;
break;
diff --git a/src/printer.h b/src/printer.h
index b0c188b..2614bad 100644
--- a/src/printer.h
+++ b/src/printer.h
@@ -52,8 +52,8 @@
*
* Note that in case the underlying output is not seekable (stream referring a pipe/FIFO/socket or the callback output type),
* nothing actually happens despite the function succeeds. Also note that the medium is not returned to the state it was when
- * the handler was created. For example, file is seeked into the offset zero, not to the offset where it was opened when
- * ly_out_new_file() was called.
+ * the handler was created. For example, file is seeked into the offset zero and truncated, the content from the time it was opened with
+ * ly_out_new_file() is not restored.
*
* @param[in] out Printer handler.
* @return LY_SUCCESS in case of success