forked from asweeney86/tinyboot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
string.c
98 lines (76 loc) · 1.38 KB
/
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
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
93
94
95
96
97
#include "string.h"
#include "vtxprintf.h"
#include "serial.h"
void *
memcpy(void *dst, const void *src, size_t count)
{
const uint8_t *s = (const uint8_t *)src;
uint8_t *d = (uint8_t *)dst;
for (; count != 0; count--)
*d++ = *s++;
return dst;
}
void *
memset(void *dst, int c, size_t count)
{
char *p = (char *)dst;
for (; count != 0; count--)
*p++ = c;
return dst;
}
void *
wmemset(void *dst, int c, size_t count)
{
unsigned short *tmp = (unsigned short *)dst;
for (; count != 0; count--)
*tmp++ = c;
return dst;
}
size_t
strlen(const char *str)
{
size_t ret;
for (ret = 0; *str != '\0'; str++)
ret++;
return ret;
}
size_t
strnlen(const char *str, size_t max)
{
size_t ret;
for (ret = 0; *str != '\0' && ret < max; str++)
ret++;
return ret;
}
int
strcmp(const char *s1, const char *s2)
{
while (*s1 && *s2 && *s1 == *s2)
s1++, s2++;
return *s1 - *s2;
}
static char *str_buf;
static void str_tx_byte(unsigned char byte)
{
*str_buf = byte;
str_buf++;
}
int
vsprintf(char *buf, const char *fmt, va_list args)
{
int i;
str_buf = buf;
i = vtxprintf(str_tx_byte, fmt, args);
*str_buf = '\0';
return i;
}
int
sprintf(char *buf, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
i = vsprintf(buf, fmt, args);
va_end(args);
return i;
}