/***************************************************************************
 * Copyright (C) 2026 Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * AI Disclosure: This file was largely AI-generated by Copilot (Sonnet 4.6).
 * The AI-generated portions may be considered public domain (CC0-1.0)
 * and not subject to the project's licence. The human contributor has
 * reviewed and verified that the code is correct.
 *
 * SPDX-License-Identifier: MIT and CC0-1.0
 **************************************************************************/

#include <stddef.h>
#include <stdint.h>

#include "string.h"

void *memcpy(void *dest, const void *src, size_t n)
{
    size_t index;
    uint8_t *dst = (uint8_t *)dest;
    const uint8_t *source = (const uint8_t *)src;

    for (index = 0U; index < n; ++index)
    {
        dst[index] = source[index];
    }

    return dest;
}

void *memset(void *dest, int c, size_t n)
{
    size_t index;
    uint8_t *dst = (uint8_t *)dest;
    uint8_t value = (uint8_t)c;

    for (index = 0U; index < n; ++index)
    {
        dst[index] = value;
    }

    return dest;
}

int memcmp(const void *lhs, const void *rhs, size_t n)
{
    size_t index;
    const uint8_t *left = (const uint8_t *)lhs;
    const uint8_t *right = (const uint8_t *)rhs;

    for (index = 0U; index < n; ++index)
    {
        if (left[index] != right[index])
        {
            return (left[index] < right[index]) ? -1 : 1;
        }
    }

    return 0;
}
