aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/string.c
blob: ef746d66f239685d0a51b2f23815b2395a91dae3 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stddef.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) {
    while (*s1 && (*s1 == *s2)) {
        s1++;
        s2++;
    }
    return *(const unsigned char *) s1 - *(const unsigned char *) s2;
}

char *strcat(char *dest, const char *src) {
    unsigned int i = 0;
    unsigned int j = 0;
    for (i = 0; dest[i] != 0; i++) {}
    for (j = 0; src[j] != 0; j++) {
        dest[i + j] = src[j];
    }
    dest[i + j] = 0;
    return dest;
}

char *strcpy(char *dest, const char *src) {
    unsigned int i = 0;
    for (i = 0; src[i] != 0; i++) {
        dest[i] = src[i];
    }
    dest[i] = 0;
    return dest;
}

void *itoa(int i, char *b, int base) {
    int temp_i;
    temp_i = i;
    int stringLen = 1;

    while ((int) temp_i / base != 0) {
        temp_i = (int) temp_i / base;
        stringLen++;
    }

    temp_i = i;
    do {
        *(b + stringLen - 1) = (temp_i % base) + '0';
        temp_i = (int) temp_i / base;
    } while (stringLen--);
}