-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.c
61 lines (49 loc) · 984 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
#include "types.h"
char *strcpy(char *dest, const char *src) {
int i = 0;
while (src[i]) {
*dest++ = src[i++];
}
*dest = '\0';
return dest;
}
unsigned int strlen(const char *s) {
unsigned int ret;
for (ret = 0; s[ret] != '\0'; ret++)
;
return ret;
}
int strcmp(const char *s1, const char *s2) {
const char *p1, *p2;
p1 = s1;
p2 = s2;
while (*p1 == *p2 && *p1 != '\0' && *p2 != '\0') {
p1++;
p2++;
}
if (*p1 == *p2 && *p1 == '\0') {
return 0;
}
if (*p1 > *p2)
return 1;
else
return -1;
}
void *memset(void *s, int c, uint32_t n) {
uint32_t i;
for (i = 0; i < (n / sizeof(int)); i++) {
*((int *)(s) + i) = c;
}
return s;
}
void *memcpy(void *dest, const void *src, size_t n) {
char *d;
const char *s;
d = dest;
s = src;
size_t i;
for (i = 0; i < n; i++) {
*d++ = *s++;
}
return dest;
}