This source file includes following definitions.
- strcpy
- strncpy
- strcat
- strncat
- strcmp
- strncmp
- strchr
- strlen
- strnlen
- strspn
- strpbrk
- strtok
- memset
- bcopy
- memcpy
- memmove
- memcmp
- memscan
- strstr
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/types.h>
15 #include <linux/string.h>
16
17 char * ___strtok = NULL;
18
19 #ifndef __HAVE_ARCH_STRCPY
20 char * strcpy(char * dest,const char *src)
21 {
22 char *tmp = dest;
23
24 while ((*dest++ = *src++) != '\0')
25 ;
26 return tmp;
27 }
28 #endif
29
30 #ifndef __HAVE_ARCH_STRNCPY
31 char * strncpy(char * dest,const char *src,size_t count)
32 {
33 char *tmp = dest;
34
35 while (count-- && (*dest++ = *src++) != '\0')
36 ;
37
38 return tmp;
39 }
40 #endif
41
42 #ifndef __HAVE_ARCH_STRCAT
43 char * strcat(char * dest, const char * src)
44 {
45 char *tmp = dest;
46
47 while (*dest)
48 dest++;
49 while ((*dest++ = *src++) != '\0')
50 ;
51
52 return tmp;
53 }
54 #endif
55
56 #ifndef __HAVE_ARCH_STRNCAT
57 char * strncat(char *dest, const char *src, size_t count)
58 {
59 char *tmp = dest;
60
61 if (count) {
62 while (*dest)
63 dest++;
64 while ((*dest++ = *src++)) {
65 if (--count == 0) {
66 *dest = '\0';
67 break;
68 }
69 }
70 }
71
72 return tmp;
73 }
74 #endif
75
76 #ifndef __HAVE_ARCH_STRCMP
77 int strcmp(const char * cs,const char * ct)
78 {
79 register signed char __res;
80
81 while (1) {
82 if ((__res = *cs - *ct++) != 0 || !*cs++)
83 break;
84 }
85
86 return __res;
87 }
88 #endif
89
90 #ifndef __HAVE_ARCH_STRNCMP
91 int strncmp(const char * cs,const char * ct,size_t count)
92 {
93 register signed char __res = 0;
94
95 while (count) {
96 if ((__res = *cs - *ct++) != 0 || !*cs++)
97 break;
98 count--;
99 }
100
101 return __res;
102 }
103 #endif
104
105 #ifndef __HAVE_ARCH_STRCHR
106 char * strchr(const char * s, int c)
107 {
108 for(; *s != (char) c; ++s)
109 if (*s == '\0')
110 return NULL;
111 return (char *) s;
112 }
113 #endif
114
115 #ifndef __HAVE_ARCH_STRLEN
116 size_t strlen(const char * s)
117 {
118 const char *sc;
119
120 for (sc = s; *sc != '\0'; ++sc)
121 ;
122 return sc - s;
123 }
124 #endif
125
126 #ifndef __HAVE_ARCH_STRNLEN
127 size_t strnlen(const char * s, size_t count)
128 {
129 const char *sc;
130
131 for (sc = s; count-- && *sc != '\0'; ++sc)
132 ;
133 return sc - s;
134 }
135 #endif
136
137 #ifndef __HAVE_ARCH_STRSPN
138 size_t strspn(const char *s, const char *accept)
139 {
140 const char *p;
141 const char *a;
142 size_t count = 0;
143
144 for (p = s; *p != '\0'; ++p) {
145 for (a = accept; *a != '\0'; ++a) {
146 if (*p == *a)
147 break;
148 }
149 if (*a == '\0')
150 return count;
151 ++count;
152 }
153
154 return count;
155 }
156 #endif
157
158 #ifndef __HAVE_ARCH_STRPBRK
159 char * strpbrk(const char * cs,const char * ct)
160 {
161 const char *sc1,*sc2;
162
163 for( sc1 = cs; *sc1 != '\0'; ++sc1) {
164 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
165 if (*sc1 == *sc2)
166 return (char *) sc1;
167 }
168 }
169 return NULL;
170 }
171 #endif
172
173 #ifndef __HAVE_ARCH_STRTOK
174 char * strtok(char * s,const char * ct)
175 {
176 char *sbegin, *send;
177
178 sbegin = s ? s : ___strtok;
179 if (!sbegin) {
180 return NULL;
181 }
182 sbegin += strspn(sbegin,ct);
183 if (*sbegin == '\0') {
184 ___strtok = NULL;
185 return( NULL );
186 }
187 send = strpbrk( sbegin, ct);
188 if (send && *send != '\0')
189 *send++ = '\0';
190 ___strtok = send;
191 return (sbegin);
192 }
193 #endif
194
195 #ifndef __HAVE_ARCH_MEMSET
196 void * memset(void * s,char c,size_t count)
197 {
198 char *xs = (char *) s;
199
200 while (count--)
201 *xs++ = c;
202
203 return s;
204 }
205 #endif
206
207 #ifndef __HAVE_ARCH_BCOPY
208 char * bcopy(const char * src, char * dest, int count)
209 {
210 char *tmp = dest;
211
212 while (count--)
213 *tmp++ = *src++;
214
215 return dest;
216 }
217 #endif
218
219 #ifndef __HAVE_ARCH_MEMCPY
220 void * memcpy(void * dest,const void *src,size_t count)
221 {
222 char *tmp = (char *) dest, *s = (char *) src;
223
224 while (count--)
225 *tmp++ = *s++;
226
227 return dest;
228 }
229 #endif
230
231 #ifndef __HAVE_ARCH_MEMMOVE
232 void * memmove(void * dest,const void *src,size_t count)
233 {
234 char *tmp, *s;
235
236 if (dest <= src) {
237 tmp = (char *) dest;
238 s = (char *) src;
239 while (count--)
240 *tmp++ = *s++;
241 }
242 else {
243 tmp = (char *) dest + count;
244 s = (char *) src + count;
245 while (count--)
246 *--tmp = *--s;
247 }
248
249 return dest;
250 }
251 #endif
252
253 #ifndef __HAVE_ARCH_MEMCMP
254 int memcmp(const void * cs,const void * ct,size_t count)
255 {
256 const unsigned char *su1, *su2;
257 signed char res = 0;
258
259 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
260 if ((res = *su1 - *su2) != 0)
261 break;
262 return res;
263 }
264 #endif
265
266
267
268
269 #ifndef __HAVE_ARCH_MEMSCAN
270 void * memscan(void * addr, int c, size_t size)
271 {
272 unsigned char * p = (unsigned char *) addr;
273
274 while (size) {
275 if (*p == c)
276 return (void *) p;
277 p++;
278 size--;
279 }
280 return (void *) p;
281 }
282 #endif
283
284 #ifndef __HAVE_ARCH_STRSTR
285 char * strstr(const char * s1,const char * s2)
286 {
287 int l1, l2;
288
289 l2 = strlen(s2);
290 if (!l2)
291 return (char *) s1;
292 l1 = strlen(s1);
293 while (l1 >= l2) {
294 l1--;
295 if (!memcmp(s1,s2,l2))
296 return (char *) s1;
297 s1++;
298 }
299 return NULL;
300 }
301 #endif