4 * Open Hack'Ware BIOS: str<xxx> functions
6 * Copyright (c) 2004-2005 Jocelyn Mayer
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License V2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* functions prototypes are here */
24 /* NULL is defined here */
25 /* malloc is defined here */
27 /* toupper is defined here */
30 /* str___ functions */
31 #if defined (__USE_strcpy__)
32 void *strcpy (char *dest, const char *src)
47 #if defined (__USE_strncpy__)
48 void *strncpy (char *dest, const char *src, size_t n)
53 for (; n != 0; n--, q++) {
63 #if defined (__USE_strdup__)
64 char *strdup (const char *s)
78 #if defined (__USE_strndup__)
80 char *strndup (const char *s, size_t n)
90 memcpy(dest, s, len - 1);
98 #if defined (__USE_stpcpy__)
99 void *stpcpy (char *dest, const char *src)
114 #if defined (__USE_stpncpy__)
115 void *stpncpy (char *dest, const char *src, size_t n)
120 for (; n != 0; n--, q++) {
130 #if defined (__USE_strcat__)
131 char *strcat (char *dest, const char *src)
135 for (q = dest + strlen(dest); ; q++) {
145 #if defined (__USE_strncat__)
146 char *strncat (char *dest, const char *src, size_t n)
150 for (q = dest + strlen(dest); n != 0; n--, q++) {
160 #if defined (__USE_strcmp__)
161 int strcmp (const char *s1, const char *s2)
165 for (ret = 0; ret == 0; s1++) {
175 #if defined (__USE_strcasecmp__)
176 int strcasecmp (const char *s1, const char *s2)
180 for (ret = 0; ret == 0; s1++) {
181 ret = toupper(*s1) - toupper(*s2++);
190 #if defined (__USE_strncmp__)
191 int strncmp (const char *s1, const char *s2, size_t n)
195 for (ret = 0; ret == 0 && n != 0; n--, s1++) {
205 #if defined (__USE_strncasecmp__)
206 int strncasecmp (const char *s1, const char *s2, size_t n)
210 for (ret = 0; ret == 0 && n != 0; n--, s1++) {
211 ret = toupper(*s1) - toupper(*s2++);
220 #if defined (__USE_strchr__)
221 char *strchr (const char *s, int c)
225 for (r = NULL; *s != '\0'; s++) {
236 #if defined (__USE_strchrnul__)
238 char *strchrnul (const char *s, int c)
240 for (; *s != '\0' && *s != c; s++)
247 #if defined (__USE_strrchr__)
248 char *strrchr (const char *s, int c)
253 for (p = s + strlen(s); p != s; p--) {
264 #if defined (__USE_strstr__)
265 char *strstr (const char *haystack, const char *needle)
271 return (char *)haystack;
273 hlen = strlen(haystack);
274 nlen = strlen(needle);
275 for (; hlen > nlen; hlen--, haystack++) {
276 if (memcmp(haystack, needle, nlen) == 0) {
286 #if defined (__USE_strcasestr__)
287 char *strcasestr (const char *haystack, const char *needle)
289 const char *p, *q, *r;
290 size_t hlen, nlen, n;
293 return (char *)haystack;
295 hlen = strlen(haystack);
296 nlen = strlen(needle);
297 for (; hlen > nlen; hlen--, haystack++) {
300 for (n = nlen; n != 0; n--) {
301 if (toupper(*p++) != toupper(*q++))
314 #if defined (__USE_strspn__)
316 size_t strspn (const char *s, const char *accept)
321 #if defined (__USE_strcspn__)
323 size_t strcspn (const char *s, const char *reject)
328 #if defined (__USE_strpbrk__)
330 char *strpbrk (const char *s, const char *accept)
335 #if defined (__USE_strtok__)
337 char *strtok (char *s, const char *delim)
342 #if defined (__USE_strtok_r__)
344 char *strtok_r (char *s, const char *delim, char **ptrptr)
349 #if defined (__USE_strsep__)
351 char *strsep (char **stringp, const char *delim)
356 #if defined (__USE_basename__)
357 char *basename (char *path)
362 if (path == NULL || (len = strlen(path)) == 0)
367 for (; sl != path; sl--) {
372 return strdup(sl + 1);
376 #if defined (__USE_dirname__)
377 char *dirname (char *path)
382 if (path == NULL || (len = strlen(path)) == 0) {
388 for (; sl != path; sl--) {
396 ret = malloc(len + 1);
398 memcpy(path, ret, len);
408 #if defined (__USE_strlen__)
409 size_t strlen (const char *s)
413 for (len = 0; *s != '\0'; len++)
420 #if defined (__USE_strnlen__)
421 size_t strnlen (const char *s, size_t maxlen)
425 for (len = 0; maxlen != 0 && *s != '\0'; maxlen--, len++)