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.
13 FILE_LICENCE ( GPL2_ONLY );
16 * stupid library routines.. The optimized versions should generally be found
17 * as inline code in <asm-xx/string.h>
19 * These are buggy as well..
21 * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
22 * - Added strsep() which will replace strtok() soon (because strsep() is
23 * reentrant and should be faster). Use only strsep() in new code, please.
27 * these are the standard string functions that are currently not used by
28 * any code in etherboot. put into a separate file to avoid linking them in
29 * with the rest of string.o
30 * if anything ever does want to use a function of these, consider moving
31 * the function in question back into string.c
39 /* *** FROM string.c *** */
41 #ifndef __HAVE_ARCH_STRNICMP
43 * strnicmp - Case insensitive, length-limited string comparison
45 * @s2: The other string
46 * @len: the maximum number of characters to compare
48 int strnicmp(const char *s1, const char *s2, size_t len)
50 /* Yes, Virginia, it had better be unsigned */
70 return (int)c1 - (int)c2;
76 #ifndef __HAVE_ARCH_STRNCAT
78 * strncat - Append a length-limited, %NUL-terminated string to another
79 * @dest: The string to be appended to
80 * @src: The string to append to it
81 * @count: The maximum numbers of bytes to copy
83 * Note that in contrast to strncpy, strncat ensures the result is
86 char * strncat(char *dest, const char *src, size_t count)
93 while ((*dest++ = *src++)) {
105 #ifndef __HAVE_ARCH_STRSPN
107 * strspn - Calculate the length of the initial substring of @s which only
108 * contain letters in @accept
109 * @s: The string to be searched
110 * @accept: The string to search for
112 size_t strspn(const char *s, const char *accept)
118 for (p = s; *p != '\0'; ++p) {
119 for (a = accept; *a != '\0'; ++a) {
132 #ifndef __HAVE_ARCH_STRCSPN
134 * strcspn - Calculate the length of the initial substring of @s which only
135 * contain letters not in @reject
136 * @s: The string to be searched
137 * @accept: The string to search for
139 size_t strcspn(const char *s, const char *reject)
145 for (p = s; *p != '\0'; ++p) {
146 for (r = reject; *r != '\0'; ++r) {
157 #ifndef __HAVE_ARCH_STRPBRK
159 * strpbrk - Find the first occurrence of a set of characters
160 * @cs: The string to be searched
161 * @ct: The characters to search for
163 char * strpbrk(const char * cs,const char * ct)
165 const char *sc1,*sc2;
167 for( sc1 = cs; *sc1 != '\0'; ++sc1) {
168 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
177 #ifndef __HAVE_ARCH_STRTOK
179 * strtok - Split a string into tokens
180 * @s: The string to be searched
181 * @ct: The characters to search for
183 * WARNING: strtok is deprecated, use strsep instead.
185 char * strtok(char * s,const char * ct)
189 sbegin = s ? s : ___strtok;
193 sbegin += strspn(sbegin,ct);
194 if (*sbegin == '\0') {
198 send = strpbrk( sbegin, ct);
199 if (send && *send != '\0')
206 #ifndef __HAVE_ARCH_STRSEP
208 * strsep - Split a string into tokens
209 * @s: The string to be searched
210 * @ct: The characters to search for
212 * strsep() updates @s to point after the token, ready for the next call.
214 * It returns empty tokens, too, behaving exactly like the libc function
215 * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
216 * Same semantics, slimmer shape. ;)
218 char * strsep(char **s, const char *ct)
220 char *sbegin = *s, *end;
225 end = strpbrk(sbegin, ct);
234 #ifndef __HAVE_ARCH_BCOPY
236 * bcopy - Copy one area of memory to another
237 * @src: Where to copy from
238 * @dest: Where to copy to
239 * @count: The size of the area.
241 * Note that this is the same as memcpy(), with the arguments reversed.
242 * memcpy() is the standard, bcopy() is a legacy BSD function.
244 * You should not use this function to access IO space, use memcpy_toio()
245 * or memcpy_fromio() instead.
247 char * bcopy(const char * src, char * dest, int count)
249 return memmove(dest,src,count);
253 #ifndef __HAVE_ARCH_MEMSCAN
255 * memscan - Find a character in an area of memory.
256 * @addr: The memory area
257 * @c: The byte to search for
258 * @size: The size of the area.
260 * returns the address of the first occurrence of @c, or 1 byte past
261 * the area if @c is not found
263 void * memscan(const void * addr, int c, size_t size)
265 unsigned char * p = (unsigned char *) addr;