-
Notifications
You must be signed in to change notification settings - Fork 62
/
support.c
47 lines (40 loc) · 914 Bytes
/
support.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
// This saves over 1kb
#include <string.h>
#include <stdint.h>
void *memmove(void *dst0, const void *src0, size_t len) {
char *dst = dst0;
const char *src = src0;
if (src < dst) {
src += len;
dst += len;
while (len--)
*--dst = *--src;
} else if (src != dst) {
while (len--)
*dst++ = *src++;
}
return dst0;
}
void *memcpy(void *dst0, const void *src0, size_t len) __attribute__((alias("memmove")));
void *memset(void *s, int c, size_t n) {
uint8_t *p = s;
while (n--)
*p++ = c;
return s;
}
size_t strlen(const char *s) {
const char *s0 = s;
while (*s++)
;
return (s - s0) - 1;
}
int memcmp(const void *aa, const void *bb, size_t n)
{
const uint8_t *a = aa;
const uint8_t *b = bb;
while (n--) {
if (*a != *b)
return (int)*a - (int)*b;
}
return 0;
}