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..
14 #include <linux/types.h>
15 #include <linux/string.h>
18 #define __HAVE_ARCH_BCOPY
19 #define __HAVE_ARCH_MEMCMP
20 #define __HAVE_ARCH_MEMCPY
21 #define __HAVE_ARCH_MEMMOVE
22 #define __HAVE_ARCH_MEMSET
23 #define __HAVE_ARCH_STRCAT
24 #define __HAVE_ARCH_STRCMP
25 #define __HAVE_ARCH_STRCPY
26 #define __HAVE_ARCH_STRLEN
27 #define __HAVE_ARCH_STRNCPY
29 char * ___strtok = NULL;
31 #ifndef __HAVE_ARCH_STRCPY
32 char * strcpy(char * dest,const char *src)
36 while ((*dest++ = *src++) != '\0')
42 #ifndef __HAVE_ARCH_STRNCPY
43 char * strncpy(char * dest,const char *src,size_t count)
47 while (count-- && (*dest++ = *src++) != '\0')
54 #ifndef __HAVE_ARCH_STRCAT
55 char * strcat(char * dest, const char * src)
61 while ((*dest++ = *src++) != '\0')
68 #ifndef __HAVE_ARCH_STRNCAT
69 char * strncat(char *dest, const char *src, size_t count)
76 while ((*dest++ = *src++)) {
88 #ifndef __HAVE_ARCH_STRCMP
89 int strcmp(const char * cs,const char * ct)
91 register signed char __res;
94 if ((__res = *cs - *ct++) != 0 || !*cs++)
102 #ifndef __HAVE_ARCH_STRNCMP
103 int strncmp(const char * cs,const char * ct,size_t count)
105 register signed char __res = 0;
108 if ((__res = *cs - *ct++) != 0 || !*cs++)
117 #ifndef __HAVE_ARCH_STRCHR
118 char * strchr(const char * s, int c)
120 for(; *s != (char) c; ++s)
127 #ifndef __HAVE_ARCH_STRRCHR
128 char * strrchr(const char * s, int c)
130 const char *p = s + strlen(s);
139 #ifndef __HAVE_ARCH_STRLEN
140 size_t strlen(const char * s)
144 for (sc = s; *sc != '\0'; ++sc)
150 #ifndef __HAVE_ARCH_STRNLEN
151 size_t strnlen(const char * s, size_t count)
155 for (sc = s; count-- && *sc != '\0'; ++sc)
161 #ifndef __HAVE_ARCH_STRDUP
162 char * strdup(const char *s)
167 ((new = malloc (strlen(s) + 1)) == NULL) ) {
176 #ifndef __HAVE_ARCH_STRSPN
177 size_t strspn(const char *s, const char *accept)
183 for (p = s; *p != '\0'; ++p) {
184 for (a = accept; *a != '\0'; ++a) {
197 #ifndef __HAVE_ARCH_STRPBRK
198 char * strpbrk(const char * cs,const char * ct)
200 const char *sc1,*sc2;
202 for( sc1 = cs; *sc1 != '\0'; ++sc1) {
203 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
212 #ifndef __HAVE_ARCH_STRTOK
213 char * strtok(char * s,const char * ct)
217 sbegin = s ? s : ___strtok;
221 sbegin += strspn(sbegin,ct);
222 if (*sbegin == '\0') {
226 send = strpbrk( sbegin, ct);
227 if (send && *send != '\0')
234 #ifndef __HAVE_ARCH_MEMSET
235 void * memset(void * s,char c,size_t count)
237 char *xs = (char *) s;
246 #ifndef __HAVE_ARCH_BCOPY
247 char * bcopy(const char * src, char * dest, int count)
258 #ifndef __HAVE_ARCH_MEMCPY
259 void * memcpy(void * dest,const void *src,size_t count)
261 char *tmp = (char *) dest, *s = (char *) src;
270 #ifndef __HAVE_ARCH_MEMMOVE
271 void * memmove(void * dest,const void *src,size_t count)
282 tmp = (char *) dest + count;
283 s = (char *) src + count;
292 #ifndef __HAVE_ARCH_MEMCMP
293 int memcmp(const void * cs,const void * ct,size_t count)
295 const unsigned char *su1, *su2;
298 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
299 if ((res = *su1 - *su2) != 0)
306 * find the first occurrence of byte 'c', or 1 past the area if none
308 #ifndef __HAVE_ARCH_MEMSCAN
309 void * memscan(void * addr, int c, size_t size)
311 unsigned char * p = (unsigned char *) addr;
323 #ifndef __HAVE_ARCH_STRSTR
324 char * strstr(const char * s1,const char * s2)
334 if (!memcmp(s1,s2,l2))