Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / samisc.h / sa_coloff.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 <stdint.h> /* uintptr_t */
#include <limb/samisc.h>

int
sa_coloff(stralloc *sa, size_t from, size_t skip, size_t end)
{
    size_t salen = sa->len;
    int ret = 0;

    for (uintptr_t off = from; off < end; ) {
        if (!stralloc_catb(sa, (char *) &off, sizeof(off))) {
            sa->len = salen;
            return -1;
        }

        off += skip + strlen(sa->s + off + skip) + 1;
        ++ret;
    }

    return ret;
}