summaryrefslogtreecommitdiffstats
path: root/sw/z80/libc/string.c
blob: 9dd56ccbac1ba8fa2c09072399af6c6f530d4b71 (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
38
39
#include "string.h"

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

    void *dp = 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(const void *s1, const void *s2, size_t n) {

    uint8_t u1, u2;

    for ( ; n--; s1++, s2++) {

        u1 = *s1;
        u2 = *s2;

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

    return 0;
}