From 34577da641d836dcf27433fee3c6384565ca7847 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 9 Sep 2015 09:17:59 +0200 Subject: [PATCH] portability: Use g_ascii_strcasecmp() in favor of strcasecmp(). This is more portable and guaranteed locale-independent. --- src/dmm/metex14.c | 46 ++++++++++++++++++------------------- src/hardware/rigol-ds/api.c | 2 +- src/hardware/scpi-pps/api.c | 2 +- src/scpi/helpers.c | 10 ++++---- src/strutil.c | 6 ++--- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/dmm/metex14.c b/src/dmm/metex14.c index 90278ffd..81829d58 100644 --- a/src/dmm/metex14.c +++ b/src/dmm/metex14.c @@ -56,14 +56,14 @@ static int parse_value(const uint8_t *buf, struct metex14_info *info, /* Bytes 5-7: Over limit (various forms) */ is_ol = 0; - is_ol += (!strcasecmp((const char *)&valstr, ".OL")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "O.L")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "OL.")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "OL")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "-.OL")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "-O.L")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "-OL.")) ? 1 : 0; - is_ol += (!strcasecmp((const char *)&valstr, "-OL")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, ".OL")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "O.L")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "OL.")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "OL")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-.OL")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-O.L")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-OL.")) ? 1 : 0; + is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-OL")) ? 1 : 0; if (is_ol != 0) { sr_spew("Over limit."); *result = INFINITY; @@ -114,35 +114,35 @@ static void parse_flags(const char *buf, struct metex14_info *info) /* Bytes 9-12: Unit */ u = (const char *)&unit; - if (!strcasecmp(u, "A")) + if (!g_ascii_strcasecmp(u, "A")) info->is_ampere = TRUE; - else if (!strcasecmp(u, "mA")) + else if (!g_ascii_strcasecmp(u, "mA")) info->is_milli = info->is_ampere = TRUE; - else if (!strcasecmp(u, "uA")) + else if (!g_ascii_strcasecmp(u, "uA")) info->is_micro = info->is_ampere = TRUE; - else if (!strcasecmp(u, "V")) + else if (!g_ascii_strcasecmp(u, "V")) info->is_volt = TRUE; - else if (!strcasecmp(u, "mV")) + else if (!g_ascii_strcasecmp(u, "mV")) info->is_milli = info->is_volt = TRUE; - else if (!strcasecmp(u, "Ohm")) + else if (!g_ascii_strcasecmp(u, "Ohm")) info->is_ohm = TRUE; - else if (!strcasecmp(u, "KOhm")) + else if (!g_ascii_strcasecmp(u, "KOhm")) info->is_kilo = info->is_ohm = TRUE; - else if (!strcasecmp(u, "MOhm")) + else if (!g_ascii_strcasecmp(u, "MOhm")) info->is_mega = info->is_ohm = TRUE; - else if (!strcasecmp(u, "pF")) + else if (!g_ascii_strcasecmp(u, "pF")) info->is_pico = info->is_farad = TRUE; - else if (!strcasecmp(u, "nF")) + else if (!g_ascii_strcasecmp(u, "nF")) info->is_nano = info->is_farad = TRUE; - else if (!strcasecmp(u, "uF")) + else if (!g_ascii_strcasecmp(u, "uF")) info->is_micro = info->is_farad = TRUE; - else if (!strcasecmp(u, "KHz")) + else if (!g_ascii_strcasecmp(u, "KHz")) info->is_kilo = info->is_hertz = TRUE; - else if (!strcasecmp(u, "C")) + else if (!g_ascii_strcasecmp(u, "C")) info->is_celsius = TRUE; - else if (!strcasecmp(u, "DB")) + else if (!g_ascii_strcasecmp(u, "DB")) info->is_decibel = TRUE; - else if (!strcasecmp(u, "")) + else if (!g_ascii_strcasecmp(u, "")) info->is_unitless = TRUE; /* Bytes 0-1: Measurement mode, except AC/DC */ diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 679bf546..176478be 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -298,7 +298,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } for (i = 0; i < ARRAY_SIZE(supported_models); i++) { - if (!strcasecmp(hw_info->manufacturer, + if (!g_ascii_strcasecmp(hw_info->manufacturer, supported_models[i].series->vendor->full_name) && !strcmp(hw_info->model, supported_models[i].name)) { model = &supported_models[i]; diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 1210b81c..1fddeea0 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -74,7 +74,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) device = NULL; for (i = 0; i < num_pps_profiles; i++) { vendor = sr_vendor_alias(hw_info->manufacturer); - if (strcasecmp(vendor, pps_profiles[i].vendor)) + if (g_ascii_strcasecmp(vendor, pps_profiles[i].vendor)) continue; model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL); if (g_regex_match(model_re, hw_info->model, 0, &model_mi)) diff --git a/src/scpi/helpers.c b/src/scpi/helpers.c index 0fb1d401..999658a5 100644 --- a/src/scpi/helpers.c +++ b/src/scpi/helpers.c @@ -38,7 +38,7 @@ SR_PRIV const char *sr_vendor_alias(const char *raw_vendor) unsigned int i; for (i = 0; i < ARRAY_SIZE(scpi_vendors); i++) { - if (!strcasecmp(raw_vendor, scpi_vendors[i][0])) + if (!g_ascii_strcasecmp(raw_vendor, scpi_vendors[i][0])) return scpi_vendors[i][1]; } @@ -111,11 +111,11 @@ SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, const struct scpi_comma if (g_variant_type_equal(gvtype, G_VARIANT_TYPE_BOOLEAN)) { if ((ret = sr_scpi_get_string(scpi, NULL, &s)) != SR_OK) return ret; - if (!strcasecmp(s, "ON") || !strcasecmp(s, "1") - || !strcasecmp(s, "YES")) + if (!g_ascii_strcasecmp(s, "ON") || !g_ascii_strcasecmp(s, "1") + || !g_ascii_strcasecmp(s, "YES")) *gvar = g_variant_new_boolean(TRUE); - else if (!strcasecmp(s, "OFF") || !strcasecmp(s, "0") - || !strcasecmp(s, "NO")) + else if (!g_ascii_strcasecmp(s, "OFF") || !g_ascii_strcasecmp(s, "0") + || !g_ascii_strcasecmp(s, "NO")) *gvar = g_variant_new_boolean(FALSE); else ret = SR_ERR; diff --git a/src/strutil.c b/src/strutil.c index bb5913f3..8d42be3f 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -421,7 +421,7 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) } else *size += frac_part; - if (s && *s && strcasecmp(s, "Hz")) + if (s && *s && g_ascii_strcasecmp(s, "Hz")) return SR_ERR; return SR_OK; @@ -533,9 +533,9 @@ SR_API int sr_parse_voltage(const char *voltstr, uint64_t *p, uint64_t *q) if (s && *s) { while (*s == ' ') s++; - if (!strcasecmp(s, "mv")) + if (!g_ascii_strcasecmp(s, "mv")) *q = 1000L; - else if (!strcasecmp(s, "v")) + else if (!g_ascii_strcasecmp(s, "v")) *q = 1; else /* Must have a base suffix. */