2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2004 Tobias Lorenz
5 * string handling functions
6 * based on linux/lib/string.c
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 * stupid library routines.. The optimized versions should generally be found
15 * as inline code in <asm-xx/string.h>
17 * These are buggy as well..
19 * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
20 * - Added strsep() which will replace strtok() soon (because strsep() is
21 * reentrant and should be faster). Use only strsep() in new code, please.
25 * these are the standard string functions that are currently not used by
26 * any code in etherboot. put into a separate file to avoid linking them in
27 * with the rest of string.o
28 * if anything ever does want to use a function of these, consider moving
29 * the function in question back into string.c
37 /* *** FROM string.c *** */
39 #ifndef __HAVE_ARCH_STRNICMP
41 * strnicmp - Case insensitive, length-limited string comparison
43 * @s2: The other string
44 * @len: the maximum number of characters to compare
46 int strnicmp(const char *s1
, const char *s2
, size_t len
)
48 /* Yes, Virginia, it had better be unsigned */
68 return (int)c1
- (int)c2
;
74 #ifndef __HAVE_ARCH_STRNCAT
76 * strncat - Append a length-limited, %NUL-terminated string to another
77 * @dest: The string to be appended to
78 * @src: The string to append to it
79 * @count: The maximum numbers of bytes to copy
81 * Note that in contrast to strncpy, strncat ensures the result is
84 char * strncat(char *dest
, const char *src
, size_t count
)
91 while ((*dest
++ = *src
++)) {
103 #ifndef __HAVE_ARCH_STRSPN
105 * strspn - Calculate the length of the initial substring of @s which only
106 * contain letters in @accept
107 * @s: The string to be searched
108 * @accept: The string to search for
110 size_t strspn(const char *s
, const char *accept
)
116 for (p
= s
; *p
!= '\0'; ++p
) {
117 for (a
= accept
; *a
!= '\0'; ++a
) {
130 #ifndef __HAVE_ARCH_STRCSPN
132 * strcspn - Calculate the length of the initial substring of @s which only
133 * contain letters not in @reject
134 * @s: The string to be searched
135 * @accept: The string to search for
137 size_t strcspn(const char *s
, const char *reject
)
143 for (p
= s
; *p
!= '\0'; ++p
) {
144 for (r
= reject
; *r
!= '\0'; ++r
) {
155 #ifndef __HAVE_ARCH_STRPBRK
157 * strpbrk - Find the first occurrence of a set of characters
158 * @cs: The string to be searched
159 * @ct: The characters to search for
161 char * strpbrk(const char * cs
,const char * ct
)
163 const char *sc1
,*sc2
;
165 for( sc1
= cs
; *sc1
!= '\0'; ++sc1
) {
166 for( sc2
= ct
; *sc2
!= '\0'; ++sc2
) {
175 #ifndef __HAVE_ARCH_STRTOK
177 * strtok - Split a string into tokens
178 * @s: The string to be searched
179 * @ct: The characters to search for
181 * WARNING: strtok is deprecated, use strsep instead.
183 char * strtok(char * s
,const char * ct
)
187 sbegin
= s
? s
: ___strtok
;
191 sbegin
+= strspn(sbegin
,ct
);
192 if (*sbegin
== '\0') {
196 send
= strpbrk( sbegin
, ct
);
197 if (send
&& *send
!= '\0')
204 #ifndef __HAVE_ARCH_STRSEP
206 * strsep - Split a string into tokens
207 * @s: The string to be searched
208 * @ct: The characters to search for
210 * strsep() updates @s to point after the token, ready for the next call.
212 * It returns empty tokens, too, behaving exactly like the libc function
213 * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
214 * Same semantics, slimmer shape. ;)
216 char * strsep(char **s
, const char *ct
)
218 char *sbegin
= *s
, *end
;
223 end
= strpbrk(sbegin
, ct
);
232 #ifndef __HAVE_ARCH_BCOPY
234 * bcopy - Copy one area of memory to another
235 * @src: Where to copy from
236 * @dest: Where to copy to
237 * @count: The size of the area.
239 * Note that this is the same as memcpy(), with the arguments reversed.
240 * memcpy() is the standard, bcopy() is a legacy BSD function.
242 * You should not use this function to access IO space, use memcpy_toio()
243 * or memcpy_fromio() instead.
245 char * bcopy(const char * src
, char * dest
, int count
)
247 return memmove(dest
,src
,count
);
251 #ifndef __HAVE_ARCH_MEMSCAN
253 * memscan - Find a character in an area of memory.
254 * @addr: The memory area
255 * @c: The byte to search for
256 * @size: The size of the area.
258 * returns the address of the first occurrence of @c, or 1 byte past
259 * the area if @c is not found
261 void * memscan(const void * addr
, int c
, size_t size
)
263 unsigned char * p
= (unsigned char *) addr
;