diff options
author | jhendersonHDF <jhenderson@hdfgroup.org> | 2023-07-27 18:01:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 18:01:24 (GMT) |
commit | 85fa6c27e7f6a5bbd342515e59d2f513044575b2 (patch) | |
tree | 52f73bb7062d7237ffc4bde3ec3a66835ecdd47a /src | |
parent | 651cf290aa3e15f0b0305e609e27b755b70f33a6 (diff) | |
download | hdf5-85fa6c27e7f6a5bbd342515e59d2f513044575b2.zip hdf5-85fa6c27e7f6a5bbd342515e59d2f513044575b2.tar.gz hdf5-85fa6c27e7f6a5bbd342515e59d2f513044575b2.tar.bz2 |
Add test for HDstrcasestr macro (#2115) (#3285)
Diffstat (limited to 'src')
-rw-r--r-- | src/H5system.c | 22 | ||||
-rw-r--r-- | src/H5win32defs.h | 3 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/H5system.c b/src/H5system.c index d6d734f..ecaa0f6 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -961,6 +961,28 @@ H5_strndup(const char *s, size_t n) done: FUNC_LEAVE_NOAPI(ret_value) } + +/*------------------------------------------------------------------------- + * Function: Wstrcasestr_wrap + * + * Purpose: Windows wrapper function for strcasestr to retain GNU + * behavior where searching for an empty substring returns the + * input string being searched. StrStrIA on Windows does not + * exhibit this same behavior. + * + * Return: Pointer to input string if 'needle' is the empty substring + * Otherwise, returns StrStrIA(haystack, needle) + * + *------------------------------------------------------------------------- + */ +char * +Wstrcasestr_wrap(const char *haystack, const char *needle) +{ + if (needle && !*needle) + return haystack; + else + return StrStrIA(haystack, needle); +} #endif /* H5_HAVE_WIN32_API */ /* dirname() and basename() are not easily ported to Windows and basename diff --git a/src/H5win32defs.h b/src/H5win32defs.h index a1299b1..1b65c79 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -81,7 +81,7 @@ struct timezone { #define HDsleep(S) Sleep(S * 1000) #define HDstat(S, B) _stati64(S, B) #define HDstrcasecmp(A, B) _stricmp(A, B) -#define HDstrcasestr(A, B) StrStrIA(A, B) +#define HDstrcasestr(A, B) Wstrcasestr_wrap(A, B) #define HDstrndup(S, N) H5_strndup(S, N) #define HDstrtok_r(X, Y, Z) strtok_s(X, Y, Z) #define HDtzset() _tzset() @@ -106,6 +106,7 @@ H5_DLL int Wopen_utf8(const char *path, int oflag, ...); H5_DLL int Wremove_utf8(const char *path); H5_DLL int H5_get_win32_times(H5_timevals_t *tvs); H5_DLL char *H5_strndup(const char *s, size_t n); +H5_DLL char *Wstrcasestr_wrap(const char *haystack, const char *needle); #ifdef __cplusplus } #endif /* __cplusplus */ |