libcdio-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libcdio-devel] [PATCH 1/4] Add case insensitive _cdio_stricmp and _cdio


From: Pete Batard
Subject: [Libcdio-devel] [PATCH 1/4] Add case insensitive _cdio_stricmp and _cdio_strnicmp function calls
Date: Wed, 24 Jan 2024 17:17:35 +0000

---
 include/cdio/util.h    |  6 ++++++
 lib/driver/libcdio.sym |  2 ++
 lib/driver/util.c      | 29 +++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/include/cdio/util.h b/include/cdio/util.h
index 9cca8f9f..82a22bbf 100644
--- a/include/cdio/util.h
+++ b/include/cdio/util.h
@@ -105,6 +105,12 @@ _cdio_memdup (const void *mem, size_t count);
 char *
 _cdio_strdup_upper (const char str[]);
 
+int
+_cdio_stricmp(const char str1[], const char str2[]);
+
+int
+_cdio_strnicmp(const char str1[], const char str2[], size_t count);
+
 /*! Duplicate path and make it platform compliant. Typically needed for
     MinGW/MSYS where a "/c/..." path must be translated to "c:/..." for
     use with fopen(), etc. Returned string must be freed by the caller
diff --git a/lib/driver/libcdio.sym b/lib/driver/libcdio.sym
index 7d757af9..b20031b7 100644
--- a/lib/driver/libcdio.sym
+++ b/lib/driver/libcdio.sym
@@ -12,6 +12,8 @@ _cdio_list_node_free
 _cdio_list_node_next
 _cdio_list_prepend
 _cdio_strfreev
+_cdio_stricmp
+_cdio_strnicmp
 _cdio_strsplit
 cdio_abspath
 cdio_audio_get_msf_seconds
diff --git a/lib/driver/util.c b/lib/driver/util.c
index 5108457e..9fede555 100644
--- a/lib/driver/util.c
+++ b/lib/driver/util.c
@@ -140,6 +140,35 @@ _cdio_strdup_upper (const char str[])
   return new_str;
 }
 
+int
+_cdio_stricmp (const char str1[], const char str2[])
+{
+  if (str1 && str2) {
+    int c1, c2;
+    do {
+      c1 = tolower((unsigned char)*str1++);
+      c2 = tolower((unsigned char)*str2++);
+    } while (c1 == c2 && c1 != '\0');
+    return c1 - c2;
+  } else return (str1 != str2);
+}
+
+int
+_cdio_strnicmp(const char str1[], const char str2[], size_t count)
+{
+    if (str1 && str2) {
+      int c1 = 0, c2 = 0;
+      size_t i;
+      for (i = 0; i < count; i++) {
+        c1 = tolower((unsigned char)*str1++);
+        c2 = tolower((unsigned char)*str2++);
+        if (c1 != c2 || c1 == '\0')
+          break;
+      }
+      return c1 - c2;
+    } else return (str1 != str2);
+}
+
 /* Convert MinGW/MSYS paths that start in "/c/..." to "c:/..."
    so that they can be used with fopen(), stat(), etc.
    Returned string must be freed by the caller using cdio_free().*/
-- 
2.43.0.windows.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]