4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * stupid library routines.. The optimized versions should generally be found
9 * as inline code in <asm-xx/string.h>
11 * These are buggy as well..
13 * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
14 * - Added strsep() which will replace strtok() soon (because strsep() is
15 * reentrant and should be faster). Use only strsep() in new code, please.
18 #include <linux/types.h>
19 #include <linux/string.h>
20 #include <linux/ctype.h>
22 #ifndef __HAVE_ARCH_STRNICMP
23 int strnicmp(const char *s1, const char *s2, size_t len)
25 /* Yes, Virginia, it had better be unsigned */
45 return (int)c1 - (int)c2;
51 #ifndef __HAVE_ARCH_STRCPY
52 char * strcpy(char * dest,const char *src)
56 while ((*dest++ = *src++) != '\0')
62 #ifndef __HAVE_ARCH_STRNCPY
63 char * strncpy(char * dest,const char *src,size_t count)
67 while (count-- && (*dest++ = *src++) != '\0')
74 #ifndef __HAVE_ARCH_STRCAT
75 char * strcat(char * dest, const char * src)
81 while ((*dest++ = *src++) != '\0')
88 #ifndef __HAVE_ARCH_STRNCAT
89 char * strncat(char *dest, const char *src, size_t count)
96 while ((*dest++ = *src++)) {
108 #ifndef __HAVE_ARCH_STRCMP
109 int strcmp(const char * cs,const char * ct)
111 register signed char __res;
114 if ((__res = *cs - *ct++) != 0 || !*cs++)
122 #ifndef __HAVE_ARCH_STRNCMP
123 int strncmp(const char * cs,const char * ct,size_t count)
125 register signed char __res = 0;
128 if ((__res = *cs - *ct++) != 0 || !*cs++)
137 #ifndef __HAVE_ARCH_STRCHR
138 char * strchr(const char * s, int c)
140 for(; *s != (char) c; ++s)
147 #ifndef __HAVE_ARCH_STRRCHR
148 char * strrchr(const char * s, int c)
150 const char *p = s + strlen(s);
159 #ifndef __HAVE_ARCH_STRLEN
160 size_t strlen(const char * s)
164 for (sc = s; *sc != '\0'; ++sc)
170 #ifndef __HAVE_ARCH_STRNLEN
171 size_t strnlen(const char * s, size_t count)
175 for (sc = s; count-- && *sc != '\0'; ++sc)
181 #ifndef __HAVE_ARCH_STRSPN
182 size_t strspn(const char *s, const char *accept)
188 for (p = s; *p != '\0'; ++p) {
189 for (a = accept; *a != '\0'; ++a) {
202 #ifndef __HAVE_ARCH_STRPBRK
203 char * strpbrk(const char * cs,const char * ct)
205 const char *sc1,*sc2;
207 for( sc1 = cs; *sc1 != '\0'; ++sc1) {
208 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
217 #ifndef __HAVE_ARCH_STRTOK
218 char * strtok(char * s,const char * ct)
222 sbegin = s ? s : ___strtok;
226 sbegin += strspn(sbegin,ct);
227 if (*sbegin == '\0') {
231 send = strpbrk( sbegin, ct);
232 if (send && *send != '\0')
239 #ifndef __HAVE_ARCH_STRSEP
241 char * strsep(char **s, const char * ct)
247 sbegin += strspn(sbegin,ct);
251 *s = strpbrk( sbegin, ct);
252 if (*s && **s != '\0')
258 #ifndef __HAVE_ARCH_MEMSET
259 void * memset(void * s,int c,size_t count)
261 char *xs = (char *) s;
270 #ifndef __HAVE_ARCH_BCOPY
271 char * bcopy(const char * src, char * dest, int count)
282 #ifndef __HAVE_ARCH_MEMCPY
283 void * memcpy(void * dest,const void *src,size_t count)
285 char *tmp = (char *) dest, *s = (char *) src;
294 #ifndef __HAVE_ARCH_MEMMOVE
295 void * memmove(void * dest,const void *src,size_t count)
306 tmp = (char *) dest + count;
307 s = (char *) src + count;
316 #ifndef __HAVE_ARCH_MEMCMP
317 int memcmp(const void * cs,const void * ct,size_t count)
319 const unsigned char *su1, *su2;
322 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
323 if ((res = *su1 - *su2) != 0)
330 * find the first occurrence of byte 'c', or 1 past the area if none
332 #ifndef __HAVE_ARCH_MEMSCAN
333 void * memscan(void * addr, int c, size_t size)
335 unsigned char * p = (unsigned char *) addr;
347 #ifndef __HAVE_ARCH_STRSTR
348 char * strstr(const char * s1,const char * s2)
358 if (!memcmp(s1,s2,l2))
366 #ifndef __HAVE_ARCH_MEMCHR
367 void *memchr(const void *s, int c, size_t n)
369 const unsigned char *p = s;
371 if ((unsigned char)c == *p++) {
372 return (void *)(p-1);