Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / buffer.h / buffer_puthex.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 <limb/buffer.h>
#include <limb/hex.h>

ssize_t
buffer_puthex(buffer *b, const void *data, size_t dlen, int options)
{
    size_t written = 0, r = 0;

    while (r < dlen) {
        char buf[64];
        size_t w = 0;
        hexall_fmt(buf, sizeof(buf), data, dlen, options, &w, &r);
        if (buffer_put(b, buf, w) < 0)
            return -1;
        written += w;
    }

    return written;
}