summaryrefslogtreecommitdiffstats
path: root/sw/z80/libc/string.c
blob: 57b3a7f913f0407666052fe8ef63346ab8f94b7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "string.h"

void *memset(void *dest, const int8_t src, size_t n) {

    char *dp = (char *) dest;

    while (n--)
        *(dp++) = src;

    return dest;
}

void *memcpy(void *dest, void *src, size_t n)
{
    char *dp = dest;
    char *sp = src;

    while (n--) {
        *dp++ = *sp++;
    }

    return dest;
}

int8_t memcmp(void *s1, void *s2, size_t n)
{
    char *u1 = (char *) s1;
    char *u2 = (char *) s2;

    for ( ; n--; u1++, u2++) {

        if (*u1 != *u2)
            return u1 - u2;
    }

    return 0;
}