forked from Hexabinome/OS-RaspberryPi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
62 lines (50 loc) · 973 Bytes
/
string.c
File metadata and controls
62 lines (50 loc) · 973 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "string.h"
#include "config.h"
#include <stdint.h>
static char* strfnd_replace(char* str, const char delim, uint8_t replace)
{
if (str == NULL)
{
return NULL;
}
char* current = str;
while (*current != delim)
{
current++;
}
if (replace)
{
*current = '\0';
}
return current;
}
char* strtok(char* str, const char delim)
{
return strfnd_replace(str, delim, TRUE);
}
char* strfnd(char* str, const char delim)
{
return strfnd_replace(str, delim, FALSE);
}
// http://www.jbox.dk/sanos/source/lib/string.c.html
int strcmp(const char* s1, const char* s2)
{
int ret = 0;
while (!(ret = *(unsigned char*) s1 - *(unsigned char*) s2) && *s2) ++s1, ++s2;
if (ret < 0)
{
ret = -1;
}
else if (ret > 0)
{
ret = 1;
}
return ret;
}
// http://www.opensource.apple.com/source/Libc/Libc-167/gen.subproj/i386.subproj/strlen.c
unsigned int strlen(const char* str)
{
register const char* s;
for (s = str; *s; ++s) ;
return (s - str);
}