aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/string.h17
-rw-r--r--include/wchar.h17
-rw-r--r--src/string/strcmp.c29
-rw-r--r--src/wchar/wcscmp.c24
4 files changed, 87 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h
index 53aaca6..d1eedd0 100644
--- a/include/string.h
+++ b/include/string.h
@@ -727,6 +727,23 @@ void* memdup(const void*, size_t)
int memcmp(const void*, const void*, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
+#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+/**
+ * Compare two memory segments alphabetically in a case insensitive manner.
+ *
+ * This is a slibc extension added because it was useful
+ * in implementing slibc itself.
+ *
+ * @param a A negative value is returned if this is the lesser.
+ * @param b A positive value is returned if this is the lesser.
+ * @param size The size of the segments.
+ * @return Zero is returned if `a` and `b` are equal, otherwise,
+ * see the specifications for `a` and `b`.
+ */
+int memcasecmp(const void*, const void*, size_t)
+ __GCC_ONLY(__attribute__((warn_unused_result, pure)));
+#endif
+
/**
* Compare two strings alphabetically in a case sensitive manner.
*
diff --git a/include/wchar.h b/include/wchar.h
index 755b583..2b757ca 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -658,6 +658,23 @@ wchar_t* wmemdup(const wchar_t*, size_t)
int wmemcmp(const wchar_t*, const wchar_t*, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
+#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+/**
+ * Compare two memory segments alphabetically in a case insensitive manner.
+ *
+ * This is a slibc extension added because it was useful
+ * in implementing slibc itself.
+ *
+ * @param a A negative value is returned if this is the lesser.
+ * @param b A positive value is returned if this is the lesser.
+ * @param size The size of the segments.
+ * @return Zero is returned if `a` and `b` are equal, otherwise,
+ * see the specifications for `a` and `b`.
+ */
+int wmemcasecmp(const wchar_t*, const wchar_t*, size_t)
+ __GCC_ONLY(__attribute__((warn_unused_result, pure)));
+#endif
+
/**
* Compare two strings alphabetically in a case sensitive manner.
*
diff --git a/src/string/strcmp.c b/src/string/strcmp.c
index 066b7c1..bffb2ad 100644
--- a/src/string/strcmp.c
+++ b/src/string/strcmp.c
@@ -45,6 +45,35 @@ int memcmp(const void* a, const void* b, size_t size)
/**
+ * Compare two memory segments alphabetically in a case insensitive manner.
+ *
+ * This is a slibc extension added because it was useful
+ * in implementing slibc itself.
+ *
+ * @param a A negative value is returned if this is the lesser.
+ * @param b A positive value is returned if this is the lesser.
+ * @param size The size of the segments.
+ * @return Zero is returned if `a` and `b` are equal, otherwise,
+ * see the specifications for `a` and `b`.
+ */
+int memcasecmp(const void* a, const void* b, size_t size)
+{
+ const signed char* s1 = a;
+ const signed char* s2 = b;
+ int c1, c2;
+ for (; size--; s1++, s2++)
+ if (*s1 != *s2)
+ {
+ c1 = isalpha(*s1) ? tolower(*s1) : (int)*s1;
+ c2 = isalpha(*s2) ? tolower(*s2) : (int)*s2;
+ if ((c1 -= c2))
+ return c1;
+ }
+ return 0;
+}
+
+
+/**
* Compare two strings alphabetically in a case sensitive manner.
*
* @param a A negative value is returned if this is the lesser.
diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c
index aa3cdf3..ddbd228 100644
--- a/src/wchar/wcscmp.c
+++ b/src/wchar/wcscmp.c
@@ -42,6 +42,30 @@ int wmemcmp(const wchar_t* a, const wchar_t* b, size_t size)
/**
+ * Compare two memory segments alphabetically in a case insensitive manner.
+ *
+ * @param a A negative value is returned if this is the lesser.
+ * @param b A positive value is returned if this is the lesser.
+ * @param size The size of the segments.
+ * @return Zero is returned if `a` and `b` are equal, otherwise,
+ * see the specifications for `a` and `b`.
+ */
+int wmemcasecmp(const wchar_t* a, const wchar_t* b, size_t size)
+{
+ wchar_t c1, c2;
+ for (; size--; a++, b++)
+ if (*a != *b);
+ {
+ c1 = iswalpha(*a) ? towlower(*a) : *a;
+ c2 = iswalpha(*b) ? towlower(*b) : *b;
+ if (c1 != c2)
+ return c1 < c2 ? -1 : +1;
+ }
+ return 0;
+}
+
+
+/**
* Compare two strings alphabetically in a case sensitive manner.
*
* @param a A negative value is returned if this is the lesser.