Huw Davies : nsiproxy: Use an ascii version of str(n)casecmp() instead of _strnicmp().

Alexandre Julliard julliard at winehq.org
Fri Oct 1 18:02:23 CDT 2021


Module: wine
Branch: master
Commit: 280999aee223d604d60bf9c8c845ab0557a6005e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=280999aee223d604d60bf9c8c845ab0557a6005e

Author: Huw Davies <huw at codeweavers.com>
Date:   Fri Oct  1 15:07:04 2021 +0100

nsiproxy: Use an ascii version of str(n)casecmp() instead of _strnicmp().

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/nsiproxy.sys/ip.c               | 22 +++++++++++-----------
 dlls/nsiproxy.sys/ndis.c             |  2 +-
 dlls/nsiproxy.sys/nsiproxy_private.h | 21 +++++++++++++++++++++
 dlls/nsiproxy.sys/tcp.c              |  4 ++--
 dlls/nsiproxy.sys/udp.c              |  6 +++---
 5 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/dlls/nsiproxy.sys/ip.c b/dlls/nsiproxy.sys/ip.c
index 12fae3f2f12..7308e4a687e 100644
--- a/dlls/nsiproxy.sys/ip.c
+++ b/dlls/nsiproxy.sys/ip.c
@@ -261,10 +261,10 @@ static NTSTATUS ipv4_icmpstats_get_all_parameters( const void *key, DWORD key_si
 
         while ((ptr = fgets( buf, sizeof(buf), fp )))
         {
-            if (_strnicmp( buf, hdr, sizeof(hdr) - 1 )) continue;
+            if (ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 )) continue;
             /* last line was a header, get another */
             if (!(ptr = fgets( buf, sizeof(buf), fp ))) break;
-            if (!_strnicmp( buf, hdr, sizeof(hdr) - 1 ))
+            if (!ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 ))
             {
                 ptr += sizeof(hdr);
                 sscanf( ptr, "%u %u %*u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
@@ -427,13 +427,13 @@ static NTSTATUS ipv6_icmpstats_get_all_parameters( const void *key, DWORD key_si
             while (*value == ' ') value++;
             if ((ptr = strchr( value, '\n' ))) *ptr='\0';
 
-            if (!_strnicmp( buf, "Icmp6InMsgs", -1 ))
+            if (!ascii_strcasecmp( buf, "Icmp6InMsgs" ))
             {
                 if (sscanf( value, "%d", &res )) dyn.in_msgs = res;
                 continue;
             }
 
-            if (!_strnicmp( buf, "Icmp6InErrors", -1 ))
+            if (!ascii_strcasecmp( buf, "Icmp6InErrors" ))
             {
                 if (sscanf( value, "%d", &res )) dyn.in_errors = res;
                 continue;
@@ -441,7 +441,7 @@ static NTSTATUS ipv6_icmpstats_get_all_parameters( const void *key, DWORD key_si
 
             for (i = 0; i < ARRAY_SIZE(in_list); i++)
             {
-                if (!_strnicmp( buf, in_list[i].name, -1 ))
+                if (!ascii_strcasecmp( buf, in_list[i].name ))
                 {
                     if (sscanf( value, "%d", &res ))
                         dyn.in_type_counts[in_list[i].pos] = res;
@@ -449,13 +449,13 @@ static NTSTATUS ipv6_icmpstats_get_all_parameters( const void *key, DWORD key_si
                 }
             }
 
-            if (!_strnicmp( buf, "Icmp6OutMsgs", -1 ))
+            if (!ascii_strcasecmp( buf, "Icmp6OutMsgs" ))
             {
                 if (sscanf( value, "%d", &res )) dyn.out_msgs = res;
                 continue;
             }
 
-            if (!_strnicmp( buf, "Icmp6OutErrors", -1 ))
+            if (!ascii_strcasecmp( buf, "Icmp6OutErrors" ))
             {
                 if (sscanf( value, "%d", &res )) dyn.out_errors = res;
                 continue;
@@ -463,7 +463,7 @@ static NTSTATUS ipv6_icmpstats_get_all_parameters( const void *key, DWORD key_si
 
             for (i = 0; i < ARRAY_SIZE(out_list); i++)
             {
-                if (!_strnicmp( buf, out_list[i].name, -1 ))
+                if (!ascii_strcasecmp( buf, out_list[i].name ))
                 {
                     if (sscanf( value, "%d", &res ))
                         dyn.out_type_counts[out_list[i].pos] = res;
@@ -504,10 +504,10 @@ static NTSTATUS ipv4_ipstats_get_all_parameters( const void *key, DWORD key_size
 
         while ((ptr = fgets( buf, sizeof(buf), fp )))
         {
-            if (_strnicmp( buf, hdr, sizeof(hdr) - 1 )) continue;
+            if (ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 )) continue;
             /* last line was a header, get another */
             if (!(ptr = fgets( buf, sizeof(buf), fp ))) break;
-            if (!_strnicmp( buf, hdr, sizeof(hdr) - 1 ))
+            if (!ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 ))
             {
                 DWORD in_recv, in_hdr_errs, fwd_dgrams, in_delivers, out_reqs;
                 ptr += sizeof(hdr);
@@ -643,7 +643,7 @@ static NTSTATUS ipv6_ipstats_get_all_parameters( const void *key, DWORD key_size
             if ((ptr = strchr( value, '\n' ))) *ptr = '\0';
 
             for (i = 0; i < ARRAY_SIZE(ipstatlist); i++)
-                if (!_strnicmp( buf, ipstatlist[i].name, -1 ))
+                if (!ascii_strcasecmp( buf, ipstatlist[i].name ))
                 {
                     if (ipstatlist[i].size == sizeof(long))
                         *(long *)ipstatlist[i].elem = strtoul( value, NULL, 10 );
diff --git a/dlls/nsiproxy.sys/ndis.c b/dlls/nsiproxy.sys/ndis.c
index 1d0e69c593c..b46b53b536c 100644
--- a/dlls/nsiproxy.sys/ndis.c
+++ b/dlls/nsiproxy.sys/ndis.c
@@ -354,7 +354,7 @@ static void ifinfo_fill_dynamic( struct if_entry *entry, struct nsi_ndis_ifinfo_
             while ((ptr = fgets( buf, sizeof(buf), fp )))
             {
                 while (*ptr && isspace( *ptr )) ptr++;
-                if (!_strnicmp( ptr, entry->if_unix_name, name_len ) && ptr[name_len] == ':')
+                if (!ascii_strncasecmp( ptr, entry->if_unix_name, name_len ) && ptr[name_len] == ':')
                 {
                     unsigned long long values[9];
                     ptr += name_len + 1;
diff --git a/dlls/nsiproxy.sys/nsiproxy_private.h b/dlls/nsiproxy.sys/nsiproxy_private.h
index 7dd8748e3f7..acc60ce4806 100644
--- a/dlls/nsiproxy.sys/nsiproxy_private.h
+++ b/dlls/nsiproxy.sys/nsiproxy_private.h
@@ -135,3 +135,24 @@ extern const struct module ipv4_module DECLSPEC_HIDDEN;
 extern const struct module ipv6_module DECLSPEC_HIDDEN;
 extern const struct module tcp_module DECLSPEC_HIDDEN;
 extern const struct module udp_module DECLSPEC_HIDDEN;
+
+static inline int ascii_strncasecmp( const char *s1, const char *s2, size_t n )
+{
+    int l1, l2;
+
+    while (n--)
+    {
+        l1 = (unsigned char)((*s1 >= 'A' && *s1 <= 'Z') ? *s1 + ('a' - 'A') : *s1);
+        l2 = (unsigned char)((*s2 >= 'A' && *s2 <= 'Z') ? *s2 + ('a' - 'A') : *s2);
+        if (l1 != l2) return l1 - l2;
+        if (!l1) return 0;
+        s1++;
+        s2++;
+    }
+    return 0;
+}
+
+static inline int ascii_strcasecmp( const char *s1, const char *s2 )
+{
+    return ascii_strncasecmp( s1, s2, -1 );
+}
diff --git a/dlls/nsiproxy.sys/tcp.c b/dlls/nsiproxy.sys/tcp.c
index f9ddf1a2b23..6b431e93c8e 100644
--- a/dlls/nsiproxy.sys/tcp.c
+++ b/dlls/nsiproxy.sys/tcp.c
@@ -147,10 +147,10 @@ static NTSTATUS tcp_stats_get_all_parameters( const void *key, DWORD key_size, v
 
         while ((ptr = fgets( buf, sizeof(buf), fp )))
         {
-            if (_strnicmp( buf, hdr, sizeof(hdr) - 1 )) continue;
+            if (ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 )) continue;
             /* last line was a header, get another */
             if (!(ptr = fgets( buf, sizeof(buf), fp ))) break;
-            if (!_strnicmp( buf, hdr, sizeof(hdr) - 1 ))
+            if (!ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 ))
             {
                 DWORD in_segs, out_segs;
                 ptr += sizeof(hdr);
diff --git a/dlls/nsiproxy.sys/udp.c b/dlls/nsiproxy.sys/udp.c
index a0ace071753..c2dcc2c38e8 100644
--- a/dlls/nsiproxy.sys/udp.c
+++ b/dlls/nsiproxy.sys/udp.c
@@ -123,10 +123,10 @@ static NTSTATUS udp_stats_get_all_parameters( const void *key, DWORD key_size, v
 
         while ((ptr = fgets( buf, sizeof(buf), fp )))
         {
-            if (_strnicmp( buf, hdr, sizeof(hdr) - 1) ) continue;
+            if (ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 )) continue;
             /* last line was a header, get another */
             if (!(ptr = fgets( buf, sizeof(buf), fp ))) break;
-            if (!_strnicmp(buf, hdr, sizeof(hdr) - 1))
+            if (!ascii_strncasecmp( buf, hdr, sizeof(hdr) - 1 ))
             {
                 unsigned int in_dgrams, out_dgrams;
                 ptr += sizeof(hdr);
@@ -176,7 +176,7 @@ static NTSTATUS udp_stats_get_all_parameters( const void *key, DWORD key_size, v
             if ((ptr = strchr( value, '\n' ))) *ptr='\0';
 
             for (i = 0; i < ARRAY_SIZE(udp_stat_list); i++)
-                if (!_strnicmp( buf, udp_stat_list[i].name, -1 ) && sscanf( value, "%d", &res ))
+                if (!ascii_strcasecmp( buf, udp_stat_list[i].name ) && sscanf( value, "%d", &res ))
                     *udp_stat_list[i].elem = res;
         }
         dyn.in_dgrams = in_dgrams;




More information about the wine-cvs mailing list