Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / stralloc.h / stralloc_remove.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 <errno.h>
#include <string.h>
#include <limb/stralloc.h>

int
stralloc_remove(stralloc *sa, size_t offset, size_t len)
{
    if (offset + len > sa->len)
        return (errno = EINVAL, 0);

    if (offset + len < sa->len)
        memmove(sa->s + offset, sa->s + offset + len, sa->len - offset - len);

    sa->len -= len;
    return 1;
}