-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathstring.cc
88 lines (62 loc) · 1.19 KB
/
string.cc
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
#include <os.h>
extern "C"
{
int strlen(char *s)
{
int i = 0;
while (*s++)
i++;
return i;
}
char *strncpy(char *destString, const char *sourceString,int maxLength)
{
unsigned count;
if ((destString == (char *) NULL) || (sourceString == (char *) NULL))
{
return (destString = NULL);
}
if (maxLength > 255)
maxLength = 255;
for (count = 0; (int)count < (int)maxLength; count ++)
{
destString[count] = sourceString[count];
if (sourceString[count] == '\0')
break;
}
if (count >= 255)
{
return (destString = NULL);
}
return (destString);
}
int strcmp(const char *dst, char *src)
{
int i = 0;
while ((dst[i] == src[i])) {
if (src[i++] == 0)
return 0;
}
return 1;
}
int strcpy(char *dst,const char *src)
{
int i = 0;
while ((dst[i] = src[i++]));
return i;
}
void strcat(void *dest,const void *src)
{
memcpy((char*)((int)dest+(int)strlen((char*)dest)),(char*)src,strlen((char*)src));
}
int strncmp( const char* s1, const char* s2, int c ) {
int result = 0;
while ( c ) {
result = *s1 - *s2++;
if ( ( result != 0 ) || ( *s1++ == 0 ) ) {
break;
}
c--;
}
return result;
}
}