-
Notifications
You must be signed in to change notification settings - Fork 10
/
string.c
65 lines (51 loc) · 902 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
62
63
64
65
/*
* Raspberry PI Remote Serial Protocol.
* Copyright 2012 Jamie Iles, [email protected].
* Licensed under GPLv2.
*/
#include "kernel.h"
#include "string.h"
size_t strlen(const char *str)
{
size_t len = 0;
while (*str++)
++len;
return len;
}
int strncmp(const char *a, const char *b, size_t len)
{
int ac, bc;
if (len == 0)
return 0;
while (len > 0) {
ac = *a++;
bc = *b++;
if (ac == '\0' || ac != bc)
return ac - bc;
--len;
}
return ac - bc;
}
bool is_hex(char v)
{
if (v >= 'A' && v <= 'F')
v = (v - 'A') + 'a';
return (v >= '0' && v <= '9') || (v >= 'a' && v <= 'f');
}
char *strchr(const char *str, int delim)
{
while (*str) {
if (*str == delim)
return (char *)str;
++str;
}
return NULL;
}
void *memcpy(void *dst, const void *src, size_t len)
{
char *dst8 = dst;
const char *src8 = src;
while (len--)
*dst8++ = *src8++;
return dst8;
}