-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.c
61 lines (54 loc) · 1004 Bytes
/
string.c
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
54
55
56
57
58
59
60
61
//
// string.h approach for the J.Molloy's kernel
// author: Alex. Cremieux
//
#include "string.h"
#include "common.h"
#include "kheap.h"
void *memset(void *str, u8int constant, u32int number)
{
char *c = (char*)str;
for(u32int idx = 0; idx < number; idx++)
{
c[idx] = constant;
}
return str;
}
void *memcpy(void *dest, void *src, u32int size)
{
char *cdest = (char *)dest;
char *csrc = (char *)src;
u32int i = 0;
for(i = 0; i < size; i++)
{
cdest[i] = csrc[i];
}
}
char *strcpy(char *dest, char *src)
{
u32int i = 0;
while(src[i] != '\n')
{
dest[i] = src[i];
}
return dest;
}
u32int strlen(char *str)
{
u32int len = 0;
while(str[len] != '\n')
{
len++;
}
return len;
}
int strcmp(char *str1, char *str2)
{
int output = 1;
int i = 0;
while(str1[i] != '\n' && output){
output = str1[i] == str2[i];
i++;
}
return output ? str1[i] == str2[i] : 0;
}