printer REFACTOR remove ctx and status (#1170)
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index 1d93bbb..554d6b4 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -227,7 +227,7 @@
{
LY_ARRAY_COUNT_TYPE u;
struct lyd_lyb_subtree *full, *iter;
- ssize_t r, to_write;
+ size_t to_write;
uint8_t meta_buf[LYB_META_BYTES];
while (1) {
@@ -249,41 +249,30 @@
/* we are actually writing some data, not just finishing another chunk */
if (to_write) {
- r = ly_write(out, (char *)buf, to_write);
- if (r < to_write) {
- return LY_ESYS;
- }
+ LY_CHECK_RET(ly_write_(out, (char *)buf, to_write));
LY_ARRAY_FOR(lybctx->subtrees, u) {
/* increase all written counters */
- lybctx->subtrees[u].written += r;
+ lybctx->subtrees[u].written += to_write;
assert(lybctx->subtrees[u].written <= LYB_SIZE_MAX);
}
/* decrease count/buf */
- count -= r;
- buf += r;
+ count -= to_write;
+ buf += to_write;
}
if (full) {
/* write the meta information (inner chunk count and chunk size) */
meta_buf[0] = full->written & 0xFF;
meta_buf[1] = full->inner_chunks & 0xFF;
-
- r = ly_write_skipped(out, full->position, (char *)meta_buf, LYB_META_BYTES);
- if (r < 0) {
- return LY_ESYS;
- }
- /* these bytes were already counted */
+ LY_CHECK_RET(ly_write_skipped(out, full->position, (char *)meta_buf, LYB_META_BYTES));
/* zero written and inner chunks */
full->written = 0;
full->inner_chunks = 0;
/* skip space for another chunk size */
- r = ly_write_skip(out, LYB_META_BYTES, &full->position);
- if (r < LYB_META_BYTES) {
- return LY_ESYS;
- }
+ LY_CHECK_RET(ly_write_skip(out, LYB_META_BYTES, &full->position));
/* increase inner chunk count */
for (iter = &lybctx->subtrees[0]; iter != full; ++iter) {
@@ -309,18 +298,12 @@
static LY_ERR
lyb_write_stop_subtree(struct ly_out *out, struct lylyb_ctx *lybctx)
{
- ssize_t r;
uint8_t meta_buf[LYB_META_BYTES];
/* write the meta chunk information */
meta_buf[0] = LYB_LAST_SUBTREE(lybctx).written & 0xFF;
meta_buf[1] = LYB_LAST_SUBTREE(lybctx).inner_chunks & 0xFF;
-
- r = ly_write_skipped(out, LYB_LAST_SUBTREE(lybctx).position, (char *)&meta_buf, LYB_META_BYTES);
- if (r < 0) {
- return LY_ESYS;
- }
- /* do not count these bytes */
+ LY_CHECK_RET(ly_write_skipped(out, LYB_LAST_SUBTREE(lybctx).position, (char *)&meta_buf, LYB_META_BYTES));
LY_ARRAY_DECREMENT(lybctx->subtrees);
return LY_SUCCESS;
@@ -336,7 +319,6 @@
static LY_ERR
lyb_write_start_subtree(struct ly_out *out, struct lylyb_ctx *lybctx)
{
- ssize_t r;
LY_ARRAY_COUNT_TYPE u;
if (!lybctx->subtrees) {
@@ -358,15 +340,12 @@
for (u = 0; u < LY_ARRAY_COUNT(lybctx->subtrees) - 1; ++u) {
if (lybctx->subtrees[u].inner_chunks == LYB_INCHUNK_MAX) {
LOGINT(lybctx->ctx);
- return -1;
+ return LY_EINT;
}
++lybctx->subtrees[u].inner_chunks;
}
- r = ly_write_skip(out, LYB_META_BYTES, &LYB_LAST_SUBTREE(lybctx).position);
- if (r < LYB_META_BYTES) {
- return LY_ESYS;
- }
+ LY_CHECK_RET(ly_write_skip(out, LYB_META_BYTES, &LYB_LAST_SUBTREE(lybctx).position));
return LY_SUCCESS;
}
@@ -530,7 +509,6 @@
static LY_ERR
lyb_print_magic_number(struct ly_out *out)
{
- int r;
uint32_t magic_number;
/* 'l', 'y', 'b' - 0x6c7962 */
@@ -538,10 +516,7 @@
((char *)&magic_number)[1] = 'y';
((char *)&magic_number)[2] = 'b';
- r = ly_write(out, (char *)&magic_number, 3);
- if (r < 3) {
- return LY_ESYS;
- }
+ LY_CHECK_RET(ly_write_(out, (char *)&magic_number, 3));
return LY_SUCCESS;
}
@@ -555,16 +530,12 @@
static LY_ERR
lyb_print_header(struct ly_out *out)
{
- int r;
uint8_t byte = 0;
/* version, future flags */
byte |= LYB_VERSION_NUM;
- r = ly_write(out, (char *)&byte, 1);
- if (r < 1) {
- return LY_ESYS;
- }
+ LY_CHECK_RET(ly_write_(out, (char *)&byte, 1));
return LY_SUCCESS;
}