diff --git a/src/bacnet/bacstr.c b/src/bacnet/bacstr.c index 20b9cc91..f088eb7c 100644 --- a/src/bacnet/bacstr.c +++ b/src/bacnet/bacstr.c @@ -408,7 +408,7 @@ bool characterstring_init_ansi_safe( BACNET_CHARACTER_STRING *char_string, const char *value, size_t tmax) { return characterstring_init(char_string, CHARACTER_ANSI_X34, value, - value ? strnlen(value, tmax) : 0); + value ? bacnet_strnlen(value, tmax) : 0); } /** @@ -1191,3 +1191,44 @@ bool octetstring_value_same( return false; } #endif + +/** + * @brief Compare two strings ignoring case + * @param s1 - first string + * @param s2 - second string + * @return 0 if the strings are equal, otherwise non-zero + */ +int bacnet_stricmp(const char *s1, const char *s2) +{ + unsigned char c1, c2; + + do { + c1 = (unsigned char)*s1; + c2 = (unsigned char)*s2; + c1 = (unsigned char)tolower(c1); + c2 = (unsigned char)tolower(c2); + s1++; + s2++; + } while ((c1 == c2) && (c1 != '\0')); + + return (int)c1 - c2; +} + +/** + * @brief non-standard strnlen function + * @param s - string to check + * @param maxlen - maximum length to check + * @return length of string, up to maxlen + */ +size_t bacnet_strnlen(const char *s, size_t maxlen) +{ + size_t len; + + for (len = 0; len < maxlen; len++, s++) { + if (!*s) { + break; + } + } + + return len; +} diff --git a/src/bacnet/bacstr.h b/src/bacnet/bacstr.h index ab49fb49..8b2e3b38 100644 --- a/src/bacnet/bacstr.h +++ b/src/bacnet/bacstr.h @@ -215,6 +215,11 @@ extern "C" { BACNET_OCTET_STRING * octet_string1, BACNET_OCTET_STRING * octet_string2); + BACNET_STACK_EXPORT + int bacnet_stricmp(const char *s1, const char *s2); + BACNET_STACK_EXPORT + size_t bacnet_strnlen(const char *s, size_t maxlen); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/sys/platform.h b/src/bacnet/basic/sys/platform.h index d4d3264f..9d67fc4b 100644 --- a/src/bacnet/basic/sys/platform.h +++ b/src/bacnet/basic/sys/platform.h @@ -77,17 +77,6 @@ __inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...) return count; } #endif -#elif defined(__ZEPHYR__) -#include -/* For some reason my Zephyr build for non-native targets does not - * see a definition for strnlen(), but it is visible in when - * compiling for native_posix. This results in the compiler - * emitting a warning, forcing Zephyr's sanitycheck() script to stop. - * Until this is chased down, the definition is being provided here. - */ -#if !CONFIG_NATIVE_APPLICATION -size_t strnlen(const char *, size_t); -#endif #endif /* some common min/max as defined in windef.h */ diff --git a/src/bacnet/indtext.c b/src/bacnet/indtext.c index 78105fa8..37677a38 100644 --- a/src/bacnet/indtext.c +++ b/src/bacnet/indtext.c @@ -7,33 +7,9 @@ */ #include #include -#include +#include "bacnet/bacstr.h" #include "bacnet/indtext.h" -/** @file indtext.c Maps text strings and indices of type INDTEXT_DATA */ - -/** - * @brief Compare two strings ignoring case - * @param s1 - first string - * @param s2 - second string - * @return 0 if the strings are equal, otherwise non-zero - */ -static int indtext_stricmp(const char *s1, const char *s2) -{ - unsigned char c1, c2; - - do { - c1 = (unsigned char)*s1; - c2 = (unsigned char)*s2; - c1 = (unsigned char)tolower(c1); - c2 = (unsigned char)tolower(c2); - s1++; - s2++; - } while ((c1 == c2) && (c1 != '\0')); - - return (int)c1 - c2; -} - /** * @brief Search a list of strings to find a matching string * @param data_list - list of strings and indices @@ -80,7 +56,7 @@ bool indtext_by_istring( if (data_list && search_name) { while (data_list->pString) { - if (indtext_stricmp(data_list->pString, search_name) == 0) { + if (bacnet_stricmp(data_list->pString, search_name) == 0) { index = data_list->index; found = true; break;