Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / buffer.h / buffer_puthdr.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/u32.h>
#include <limb/u64.h>

ssize_t
buffer_puthdr(buffer *b, u32 magic, u64 ver)
{
    char buf[9];
    struct iovec v[2];

    u32p_be(&magic);
    v[0].iov_base = &magic;
    v[0].iov_len = sizeof(magic);

    v[1].iov_base = buf;
    v[1].iov_len = u64_pack_trim(buf, sizeof(buf), ver);

    return buffer_putv(b, v, 2);
}