summaryrefslogtreecommitdiff
path: root/lib/string/string.c
blob: 729c509b62c514bef6a055e3535f496d61b57384 (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 <stdbool.h>

//length 0 for null terminated strings;
bool strcmp(char *str1, char *str2, int length)
{
    int i=0;
    while(true)
    {
	if(str1[i]!=str2[i])return false;
	i++;

	if(i==length) return true;
	if(str1[i]==0||str2[i]==0)
	{
	    if(str1[i]==str2[i])return true;
	    return false;
	}
    }

}

void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size)
{
	unsigned char* dst = (unsigned char*) dstptr;
	const unsigned char* src = (const unsigned char*) srcptr;
	for ( int i = 0; i < size; i++ )
		dst[i] = src[i];
	return dstptr;
}

int strlen(const char* string)
{
	int result = 0;
	while ( string[result] )
		result++;
	return result;
}