aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/string.c
blob: c171439c4e9cc71b450f1d74d61b64d684bd2b32 (plain) (blame)
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
#include <stddef.h>
#include <kernel/io/io.h>

size_t strlen(const char *str) {
    size_t len = 0;
    while (str[len])
        len++;
    return len;
}

size_t strcmp(const char *s1, const char *s2) {
    size_t s_a = strlen(s1);
    for (size_t i = 0; i < s_a; i++) 
        if (s1[i] != s2[i])
            return 1;
    return 0;
}

void strcat(char *dest, const char *src) {
    size_t s_dest = strlen(dest);
    size_t s_orig = strlen(src);

    for (size_t i = 0; i < s_orig; i++) dest[s_dest + i] = src[i];
    dest[s_dest + s_orig] = 0;
}

void strcpy(char *dest, const char *src) {
    size_t s_orig = strlen(src);

    for (size_t i = 0; i < s_orig; i++) dest[i] = src[i];
    dest[s_orig] = 0;
}