blob: 00c10e6e7da1087f5087fe110e9b6920efcb9acc (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include "vof.h"
int strlen(const char *s)
{
int len = 0;
while (*s != 0) {
len += 1;
s += 1;
}
return len;
}
int strcmp(const char *s1, const char *s2)
{
while (*s1 != 0 && *s2 != 0) {
if (*s1 != *s2) {
break;
}
s1 += 1;
s2 += 1;
}
return *s1 - *s2;
}
void *memcpy(void *dest, const void *src, size_t n)
{
char *cdest;
const char *csrc = src;
cdest = dest;
while (n-- > 0) {
*cdest++ = *csrc++;
}
return dest;
}
int memcmp(const void *ptr1, const void *ptr2, size_t n)
{
const unsigned char *p1 = ptr1;
const unsigned char *p2 = ptr2;
while (n-- > 0) {
if (*p1 != *p2) {
return *p1 - *p2;
}
p1 += 1;
p2 += 1;
}
return 0;
}
void *memmove(void *dest, const void *src, size_t n)
{
char *cdest;
const char *csrc;
int i;
/* Do the buffers overlap in a bad way? */
if (src < dest && src + n >= dest) {
/* Copy from end to start */
cdest = dest + n - 1;
csrc = src + n - 1;
for (i = 0; i < n; i++) {
*cdest-- = *csrc--;
}
} else {
/* Normal copy is possible */
cdest = dest;
csrc = src;
for (i = 0; i < n; i++) {
*cdest++ = *csrc++;
}
}
return dest;
}
void *memset(void *dest, int c, size_t size)
{
unsigned char *d = (unsigned char *)dest;
while (size-- > 0) {
*d++ = (unsigned char)c;
}
return dest;
}
|