Removed strcasecmp and strncasecmp because they are non-standand C functions. (#858)
This commit is contained in:
+4
-4
@@ -4200,12 +4200,12 @@ bool bacapp_parse_application_data(
|
||||
switch (tag_number) {
|
||||
#if defined(BACAPP_BOOLEAN)
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
if (strcasecmp(argv, "true") == 0 ||
|
||||
strcasecmp(argv, "active") == 0) {
|
||||
if (bacnet_stricmp(argv, "true") == 0 ||
|
||||
bacnet_stricmp(argv, "active") == 0) {
|
||||
value->type.Boolean = true;
|
||||
} else if (
|
||||
strcasecmp(argv, "false") == 0 ||
|
||||
strcasecmp(argv, "inactive") == 0) {
|
||||
bacnet_stricmp(argv, "false") == 0 ||
|
||||
bacnet_stricmp(argv, "inactive") == 0) {
|
||||
value->type.Boolean = false;
|
||||
} else {
|
||||
status = strtol_checked(argv, &long_value);
|
||||
|
||||
+48
-1
@@ -1227,12 +1227,18 @@ bool octetstring_value_same(
|
||||
* @param a - first string
|
||||
* @param b - second string
|
||||
* @return 0 if the strings are equal, non-zero if not
|
||||
* @note The stricmp() function is not included C standard.
|
||||
* @note The stricmp() function is not included in the C standard.
|
||||
*/
|
||||
int bacnet_stricmp(const char *a, const char *b)
|
||||
{
|
||||
int twin_a, twin_b;
|
||||
|
||||
if (a == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (b == NULL) {
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
twin_a = *(const unsigned char *)a;
|
||||
twin_b = *(const unsigned char *)b;
|
||||
@@ -1245,6 +1251,47 @@ int bacnet_stricmp(const char *a, const char *b)
|
||||
return twin_a - twin_b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare two strings, case insensitive, with length limit
|
||||
* @details The strnicmp() function compares, at most, the first n characters
|
||||
* of string1 and string2 without sensitivity to case.
|
||||
*
|
||||
* The function operates on null terminated strings.
|
||||
* The string arguments to the function are expected to contain
|
||||
* a null character (\0) marking the end of the string.
|
||||
*
|
||||
* @param a - first string
|
||||
* @param b - second string
|
||||
* @param length - maximum length to compare
|
||||
* @return 0 if the strings are equal, non-zero if not
|
||||
* @note The strnicmp() function is not included in the C standard.
|
||||
*/
|
||||
int bacnet_strnicmp(const char *a, const char *b, size_t length)
|
||||
{
|
||||
int twin_a, twin_b;
|
||||
|
||||
if (length == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (a == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (b == NULL) {
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
twin_a = *(const unsigned char *)a;
|
||||
twin_b = *(const unsigned char *)b;
|
||||
twin_a = tolower(toupper(twin_a));
|
||||
twin_b = tolower(toupper(twin_b));
|
||||
a++;
|
||||
b++;
|
||||
length--;
|
||||
} while ((twin_a == twin_b) && (twin_a != '\0') && (length > 0));
|
||||
|
||||
return twin_a - twin_b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the length of a string, within a maximum length
|
||||
* @note The strnlen function is non-standard and not available in
|
||||
|
||||
@@ -170,6 +170,8 @@ bool octetstring_value_same(
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_stricmp(const char *a, const char *b);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacnet_strnicmp(const char *a, const char *b, size_t length);
|
||||
BACNET_STACK_EXPORT
|
||||
size_t bacnet_strnlen(const char *str, size_t maxlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -46,12 +46,6 @@
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#ifndef strcasecmp
|
||||
#define strcasecmp _stricmp
|
||||
#endif
|
||||
#ifndef strncasecmp
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
|
||||
@@ -558,13 +558,13 @@ bool bacnet_channel_value_from_ascii(
|
||||
return false;
|
||||
}
|
||||
if (!status) {
|
||||
if (strcasecmp(argv, "null") == 0) {
|
||||
if (bacnet_stricmp(argv, "null") == 0) {
|
||||
value->tag = BACNET_APPLICATION_TAG_NULL;
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
if (!status) {
|
||||
if (strcasecmp(argv, "true") == 0) {
|
||||
if (bacnet_stricmp(argv, "true") == 0) {
|
||||
value->tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||
#if defined(CHANNEL_BOOLEAN)
|
||||
value->type.Boolean = true;
|
||||
@@ -573,7 +573,7 @@ bool bacnet_channel_value_from_ascii(
|
||||
}
|
||||
}
|
||||
if (!status) {
|
||||
if (strcasecmp(argv, "false") == 0) {
|
||||
if (bacnet_stricmp(argv, "false") == 0) {
|
||||
value->tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||
#if defined(CHANNEL_BOOLEAN)
|
||||
value->type.Boolean = false;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* @ingroup DataLink
|
||||
*/
|
||||
#include "bacnet/datalink/datalink.h"
|
||||
|
||||
#include "bacnet/bacstr.h"
|
||||
#if defined(BACDL_MULTIPLE) || defined FOR_DOXYGEN
|
||||
#if defined(BACDL_ETHERNET)
|
||||
#include "bacnet/datalink/ethernet.h"
|
||||
@@ -32,9 +32,6 @@
|
||||
#if defined(BACDL_BSC)
|
||||
#include "bacnet/datalink/bsc/bsc-datalink.h"
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h> /* for strcasecmp() */
|
||||
#endif
|
||||
|
||||
static enum {
|
||||
DATALINK_NONE = 0,
|
||||
@@ -48,36 +45,36 @@ static enum {
|
||||
|
||||
void datalink_set(char *datalink_string)
|
||||
{
|
||||
if (strcasecmp("none", datalink_string) == 0) {
|
||||
if (bacnet_stricmp("none", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_NONE;
|
||||
}
|
||||
#if defined(BACDL_BIP)
|
||||
else if (strcasecmp("bip", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("bip", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_BIP;
|
||||
}
|
||||
#endif
|
||||
#if defined(BACDL_BIP6)
|
||||
else if (strcasecmp("bip6", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("bip6", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_BIP6;
|
||||
}
|
||||
#endif
|
||||
#if defined(BACDL_ETHERNET)
|
||||
else if (strcasecmp("ethernet", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("ethernet", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_ETHERNET;
|
||||
}
|
||||
#endif
|
||||
#if defined(BACDL_ARCNET)
|
||||
else if (strcasecmp("arcnet", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("arcnet", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_ARCNET;
|
||||
}
|
||||
#endif
|
||||
#if defined(BACDL_MSTP)
|
||||
else if (strcasecmp("mstp", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("mstp", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_MSTP;
|
||||
}
|
||||
#endif
|
||||
#if defined(BACDL_BSC)
|
||||
else if (strcasecmp("bsc", datalink_string) == 0) {
|
||||
else if (bacnet_stricmp("bsc", datalink_string) == 0) {
|
||||
Datalink_Transport = DATALINK_BSC;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user