Subversion Repositories Kolibri OS

Rev

Rev 4001 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4001 Rev 6825
1
#include "string.h"
1
#include "string.h"
2
 
2
 
3
void*  memset(void *mem, int c, unsigned size)
3
void*  memset(void *mem, int c, unsigned size)
4
{
4
{
5
unsigned i;
5
unsigned i;
6
 
6
 
7
for ( i = 0; i < size; i++ )
7
for ( i = 0; i < size; i++ )
8
	 *((char *)mem+i) = (char) c;
8
	 *((char *)mem+i) = (char) c;
9
 
9
 
10
return NULL;	
10
return NULL;	
11
}
11
}
12
 
12
 
13
 
13
 
14
void* memcpy(void *dst, const void *src, unsigned size)
14
void* memcpy(void *dst, const void *src, unsigned size)
15
{
15
{
16
 
16
 
17
unsigned i;
17
unsigned i;
18
 
18
 
19
for ( i = 0; i < size; i++)
19
for ( i = 0; i < size; i++)
20
	*(char *)(dst+i) = *(char *)(src+i);
20
	*(char *)(dst+i) = *(char *)(src+i);
21
 
21
 
22
return NULL;
22
return NULL;
23
}
23
}
24
 
24
 
25
 
25
 
26
int memcmp(const void* buf1, const void* buf2, int count)
26
int memcmp(const void* buf1, const void* buf2, int count)
27
{
27
{
28
int i;
28
int i;
29
for (i=0;i
29
for (i=0;i
30
	{
30
	{
31
	if (*(unsigned char*)buf1<*(unsigned char*)buf2)
31
	if (*(unsigned char*)buf1<*(unsigned char*)buf2)
32
		return -1;
32
		return -1;
33
	if (*(unsigned char*)buf1>*(unsigned char*)buf2)			
33
	if (*(unsigned char*)buf1>*(unsigned char*)buf2)			
34
		return 1;
34
		return 1;
35
	}
35
	}
36
return 0;
36
return 0;
37
}
37
}
38
 
38
 
39
void strcat(char strDest[], char strSource[])
39
void strcat(char strDest[], char strSource[])
40
{
40
{
41
 
41
 
42
int i, j;
42
int i, j;
43
 
43
 
44
i = j = 0;
44
i = j = 0;
45
while (strDest[i] != '\0')
45
while (strDest[i] != '\0')
46
	i++;
46
	i++;
47
 
47
 
48
while ((strDest[i++] = strSource[j++]) != '\0')
48
while ((strDest[i++] = strSource[j++]) != '\0')
49
             ;
49
             ;
50
}
50
}
51
 
51
 
52
 
52
 
53
int strcmp(const char* string1, const char* string2)
53
int strcmp(const char* string1, const char* string2)
54
{
54
{
55
 
55
 
56
while (1)
56
while (1)
57
{
57
	{
58
if (*string1<*string2)
58
	if (*string1<*string2)
59
	return -1;
59
		return -1;
60
if (*string1>*string2)
60
	if (*string1>*string2)
61
	return 1;
61
		return 1;
62
 
62
 
63
if (*string1=='\0')
63
	if (*string1=='\0')
64
	return 0;
64
		return 0;
65
 
65
 
66
string1++;
66
	string1++;
67
string2++;
67
	string2++;
68
}
68
	}
69
 
69
 
70
}
70
}
71
 
71
 
-
 
72
int    strnicmp(const char* string1, const char* string2, unsigned count)
-
 
73
{
-
 
74
int pc = 0;
-
 
75
while (1)
-
 
76
	{
-
 
77
	if (toupper(*string1)
-
 
78
		return -1;
-
 
79
	if (toupper(*string1)>toupper(*string2))
-
 
80
		return 1;
-
 
81
 
-
 
82
	if (*string1=='\0' || pc == count)
-
 
83
		return 0;
-
 
84
 
-
 
85
	string1++;
-
 
86
	string2++;
-
 
87
	pc++;
-
 
88
	}
-
 
89
}
72
 
90
 
73
void strcpy(char strDest[], const char strSource[])
91
void strcpy(char strDest[], const char strSource[])
74
{
92
{
75
unsigned i;
93
unsigned i;
76
 
94
 
77
i = 0;
95
i = 0;
78
while ((strDest[i] = strSource[i]) != '\0')
96
while ((strDest[i] = strSource[i]) != '\0')
79
	i++;
97
	i++;
80
 
98
 
81
}
99
}
82
 
100
 
83
 
101
 
84
char* strncpy(char *strDest, const char *strSource, unsigned n)
102
char* strncpy(char *strDest, const char *strSource, unsigned n)
85
{
103
{
86
unsigned i;
104
unsigned i;
87
 
105
 
88
if (! n )
106
if (! n )
89
	return strDest;
107
	return strDest;
90
 
108
 
91
i = 0;
109
i = 0;
92
while ((strDest[i] = strSource[i]) != '\0')
110
while ((strDest[i] = strSource[i]) != '\0')
93
	if ( (n-1) == i )
111
	if ( (n-1) == i )
94
		break;
112
		break;
95
	else
113
	else
96
		i++;
114
		i++;
97
 
115
 
98
return strDest;
116
return strDest;
99
}
117
}
100
 
118
 
101
 
119
 
102
int strlen(const char* string)
120
int strlen(const char* string)
103
{
121
{
104
int i;
122
int i;
105
 
123
 
106
i=0;
124
i=0;
107
while (*string++) i++;
125
while (*string++) i++;
108
return i;
126
return i;
109
}
127
}
110
 
128
 
111
 
129
 
112
 
130
 
113
char* strchr(const char* string, int c)
131
char* strchr(const char* string, int c)
114
{
132
{
115
	while (*string)
133
	while (*string)
116
	{
134
	{
117
		if (*string==c)
135
		if (*string==c)
118
			return (char*)string;
136
			return (char*)string;
119
		string++;
137
		string++;
120
	}	
138
	}	
121
	return (char*)0;
139
	return (char*)0;
122
}
140
}
123
 
141
 
124
 
142
 
125
char* strrchr(const char* string, int c)
143
char* strrchr(const char* string, int c)
126
{
144
{
127
	char* last_found;
145
	char* last_found;
128
	while (*string)
146
	while (*string)
129
	{
147
	{
130
		if (*string==c)
148
		if (*string==c)
131
		{
149
		{
132
			last_found = (char*)string;
150
			last_found = (char*)string;
133
		}
151
		}
134
		string++;
152
		string++;
135
	}	
153
	}	
136
	return last_found;
154
	return last_found;
137
}
155
}
138
 
156
 
139
 
157
 
140
 
158
 
141
void _itoa(int i, char *s)
159
void _itoa(int i, char *s)
142
{
160
{
143
int a, b, c, d;
161
int a, b, c, d;
144
a = (i - i%1000)/1000;
162
a = (i - i%1000)/1000;
145
b = (i - i%100)/100 - a*10;
163
b = (i - i%100)/100 - a*10;
146
c = (i - i%10)/10 - a*100 - b*10;
164
c = (i - i%10)/10 - a*100 - b*10;
147
d = i%10;
165
d = i%10;
148
s[0] = a + '0';
166
s[0] = a + '0';
149
s[1] = b + '0';
167
s[1] = b + '0';
150
s[2] = c + '0';
168
s[2] = c + '0';
151
s[3] = d + '0';
169
s[3] = d + '0';
152
s[4] = 0;
170
s[4] = 0;
153
}
171
}
154
 
172
 
155
 
173
 
156
 /* reverse:  ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */
174
 /* reverse:  ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */
157
 void reverse(char s[])
175
 void reverse(char s[])
158
 {
176
 {
159
     int i, j;
177
     int i, j;
160
     char c;
178
     char c;
161
 
179
 
162
     for (i = 0, j = strlen(s)-1; i
180
     for (i = 0, j = strlen(s)-1; i
163
         c = s[i];
181
         c = s[i];
164
         s[i] = s[j];
182
         s[i] = s[j];
165
         s[j] = c;
183
         s[j] = c;
166
     }
184
     }
167
 }
185
 }
168
 
186
 
169
 
187
 
170
 /* itoa:  êîíâåðòèðóåì n â ñèìâîëû â s */
188
 /* itoa:  êîíâåðòèðóåì n â ñèìâîëû â s */
171
 void itoa(int n, char s[])
189
 void itoa(int n, char s[])
172
 {
190
 {
173
     int i, sign;
191
     int i, sign;
174
 
192
 
175
     if ((sign = n) < 0)
193
     if ((sign = n) < 0)
176
         n = -n;
194
         n = -n;
177
     i = 0;
195
     i = 0;
178
     do {
196
     do {
179
         s[i++] = n % 10 + '0';
197
         s[i++] = n % 10 + '0';
180
     } while ((n /= 10) > 0);
198
     } while ((n /= 10) > 0);
181
     if (sign < 0)
199
     if (sign < 0)
182
         s[i++] = '-';
200
         s[i++] = '-';
183
     s[i] = '\0';
201
     s[i] = '\0';
184
     reverse(s);
202
     reverse(s);
185
 }
203
 }
186
 
204
 
187
 
205
 
188
 
206
 
189
int _atoi ( char *s )
207
int _atoi ( char *s )
190
{
208
{
191
int i, n;
209
int i, n;
192
 
210
 
193
n = 0;
211
n = 0;
194
for ( i = 0; s[i]!= '\0'; ++i)
212
for ( i = 0; s[i]!= '\0'; ++i)
195
	if ((s[i]<'0') || (s[i]>'9'))
213
	if ((s[i]<'0') || (s[i]>'9'))
196
		return 0;
214
		return 0;
197
	else
215
	else
198
		n = 10 * n + s[i] - '0';
216
		n = 10 * n + s[i] - '0';
199
 
217
 
200
return n;
218
return n;
201
}
219
}
202
>
220
>
203
>
221
>
-
 
222
>