Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / patrim.h / patrim_get.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/patrim.h>
#include <limb/u64.h>

int
patrim_get(u64 *id, u64 *u, const char *data, size_t dlen, size_t offset)
{
    int r, n;

    if (offset >= dlen) return -1;
    r = u64_unpack_trim(id, data + offset, dlen - offset);
    if (r < 0) return -1;

    n = u64_unpack_trim(u, data + offset + r, dlen - offset - r);
    if (n < 0) return -1;

    return r + n;
}