-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
45 lines (36 loc) · 796 Bytes
/
string.c
File metadata and controls
45 lines (36 loc) · 796 Bytes
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
/* OneOS-ARM String Utilities Implementation */
#include "string.h"
int strcmp(const char *s1, const char *s2)
{
while (*s1 && *s2) {
if (*s1 != *s2) {
return *s1 - *s2;
}
s1++;
s2++;
}
return *s1 - *s2;
}
size_t strlen(const char *s)
{
size_t len = 0;
while (*s++) len++;
return len;
}
void *memcpy(void *dest, const void *src, size_t n)
{
unsigned char *d = (unsigned char *)dest;
const unsigned char *s = (const unsigned char *)src;
for (size_t i = 0; i < n; i++) {
d[i] = s[i];
}
return dest;
}
void *memset(void *s, int c, size_t n)
{
unsigned char *p = (unsigned char *)s;
for (size_t i = 0; i < n; i++) {
p[i] = (unsigned char)c;
}
return s;
}