/* 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/buffer.h>
#include <limb/patrim.h>
int
buffer_patrim_get(buffer *b, u64 *id, u64 *u)
{
struct iovec v[2];
char buf[18];
int r;
do {
buffer_rpeek(b, v);
r = patrim_get(id, u, buf, siov_gather(buf, sizeof(buf), v, 2), 0);
} while (r < 0 && (r = buffer_fill(b)) > 0);
if (r <= 0) return (!r) ? (errno = EPIPE, 0) : 0;
buffer_rseek(b, r);
return 1;
}