printer CHANGE return LY_ERR in a standard way from ly_write_skipped()
Returning number of written bytes does not make sense in this case.
diff --git a/src/printer.c b/src/printer.c
index cbedb86..be367d2 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -713,12 +713,12 @@
return count;
}
-ssize_t
+LY_ERR
ly_write_skipped(struct ly_out *out, size_t position, const char *buf, size_t count)
{
- ssize_t ret = LY_SUCCESS;
+ LY_ERR ret = LY_SUCCESS;
- LYOUT_CHECK(out, -1 * out->status);
+ LYOUT_CHECK(out, out->status);
switch (out->type) {
case LY_OUT_MEMORY:
@@ -732,8 +732,7 @@
case LY_OUT_CALLBACK:
if (out->buf_len < position + count) {
out->status = LY_EMEM;
- LOGMEM(NULL);
- return -LY_EMEM;
+ LOGMEM_RET(NULL);
}
/* write into the hole */
@@ -750,13 +749,12 @@
}
break;
case LY_OUT_ERROR:
- LOGINT(NULL);
- return -LY_EINT;
+ LOGINT_RET(NULL);
}
if (out->type == LY_OUT_FILEPATH) {
/* move the original file descriptor to the end of the output file */
lseek(out->method.fdstream.fd, 0, SEEK_END);
}
- return ret < 0 ? (-1 * ret) : LY_SUCCESS;
+ return ret;
}
diff --git a/src/printer_internal.h b/src/printer_internal.h
index d32d1ad..9c926fb 100644
--- a/src/printer_internal.h
+++ b/src/printer_internal.h
@@ -171,10 +171,9 @@
* @param[in] buf Memory buffer with the data to print.
* @param[in] len Length of the data to print in the @p buf. Not that the length must correspond
* to the len value specified in the corresponding ly_write_skip() call.
- * @return The number of bytes prepared for write. The number of the printed bytes is updated in lyout::printed
- * only in case the data are really written into the output.
- * @return Negative value in case of error, absolute value of the return code maps to LY_ERR value.
+ * @return LY_SUCCESS on success.
+ * @return LY_ERR value in case of error.
*/
-ssize_t ly_write_skipped(struct ly_out *out, size_t position, const char *buf, size_t len);
+LY_ERR ly_write_skipped(struct ly_out *out, size_t position, const char *buf, size_t len);
#endif /* LY_PRINTER_INTERNAL_H_ */