Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / shldata.h / shldata_predata.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <errno.h>
#include <limb/patrim.h>
#include <limb/shldata.h>
#include "shldata.h"

ssize_t
shldata_predata(char *dst, size_t dlen, shldata_ctx *ctx)
{
    if (ctx->len) {
        if (ctx->len != ctx->done)
            return (errno = EINVAL, -1);
        return 0;
    }

    int r = patrim_put(dst, dlen, 0, ID_DATA, ctx->done);
    if (r < 0) return (errno = ENOBUFS, -1);

    ctx->len = ctx->done;
    return r;
}