Re: [PATCH 2/4] tools/nolibc: Fix strlcat() return code and size usage

From: Rodrigo Campos
Date: Wed Feb 14 2024 - 17:03:21 EST


On 2/14/24 16:34, Rodrigo Campos wrote:
size_t strlcat_rata(char *dst, const char *src, size_t size)
{
        const char *orig_src = src;
        size_t len = 0;
        for (;len < size; len++) {
                if (dst[len] == '\0')
                        break;
        }

If you think about it, this is strnlen() and what follows is strncat().

size_t strlcat_willy_fixed(char *dst, const char *src, size_t size)
{
        const char *orig_src = src;
        size_t len = strlen(dst);
        if (size < len)
                len = size;

Same here.

We can simplify the code by using them, but the size doesn't seem to be smaller. Let me see what I can do.