diff options
Diffstat (limited to 'src/H5system.c')
-rw-r--r-- | src/H5system.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/H5system.c b/src/H5system.c index 9a19860..a7f2edd 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -1350,3 +1350,42 @@ H5_get_option(int argc, const char *const *argv, const char *opts, const struct /* return the current flag character found */ return optchar; } + +/*------------------------------------------------------------------------- + * Function: H5_strcasestr + * + * Purpose: Find the first occurrence of the substring needle in the + * string haystack ignoring case. + * + * Return: Success: Pointer to the beginning of the located substring + * + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +char * +H5_strcasestr(const char *haystack, const char *needle) +{ + /* Check arguments. */ + HDassert(haystack); + HDassert(needle); + + /* begin once from each character of haystack, until needle is found */ + do { + const char *h = haystack; + const char *n = needle; + /* loop while lowercase strings match, or needle ends */ + while (HDtolower(*h) == HDtolower(*n) && *n) { + h++; + n++; + } + /* if all characters in needle matched we found it */ + if (*n == 0) { + /* must discard const qualifier here, so turn off the warning */ + H5_GCC_CLANG_DIAG_OFF("cast-qual") + return (char *)haystack; + H5_GCC_CLANG_DIAG_ON("cast-qual") + } + } while (*haystack++); + return 0; +} /* end H5_strcasestr() */ |