| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2002     Manuel Novoa III | 
|  | 3 | * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> | 
|  | 4 | * | 
|  | 5 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. | 
|  | 6 | */ | 
|  | 7 |  | 
|  | 8 | #include "_string.h" | 
|  | 9 | #include <ctype.h> | 
|  | 10 |  | 
|  | 11 | char *strcasestr(const char *s1, const char *s2) | 
|  | 12 | { | 
|  | 13 | register const char *s = s1; | 
|  | 14 | register const char *p = s2; | 
|  | 15 |  | 
|  | 16 | #if 1 | 
|  | 17 | do { | 
|  | 18 | if (!*p) { | 
|  | 19 | return (char *) s1;; | 
|  | 20 | } | 
|  | 21 | if ((*p == *s) | 
|  | 22 | || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s))) | 
|  | 23 | ) { | 
|  | 24 | ++p; | 
|  | 25 | ++s; | 
|  | 26 | } else { | 
|  | 27 | p = s2; | 
|  | 28 | if (!*s) { | 
|  | 29 | return NULL; | 
|  | 30 | } | 
|  | 31 | s = ++s1; | 
|  | 32 | } | 
|  | 33 | } while (1); | 
|  | 34 | #else | 
|  | 35 | while (*p && *s) { | 
|  | 36 | if ((*p == *s) | 
|  | 37 | || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s))) | 
|  | 38 | ) { | 
|  | 39 | ++p; | 
|  | 40 | ++s; | 
|  | 41 | } else { | 
|  | 42 | p = s2; | 
|  | 43 | s = ++s1; | 
|  | 44 | } | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | return (*p) ? NULL : (char *) s1; | 
|  | 48 | #endif | 
|  | 49 | } | 
|  | 50 | libc_hidden_def(strcasestr) |