aboutsummaryrefslogtreecommitdiff
path: root/src/lib/string.c
blob: 6ef0316b7d8848556df50507d77147c618d607d9 (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
#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 *dst, const char *src) {
    unsigned int i = 0;
    unsigned int j = 0;
    for (i = 0; dst[i] != 0; i++) {}
    for (j = 0; src[j] != 0; j++) {
        dst[i + j] = src[j];
    }
    dst[i + j] = 0;
    return dst;
}