+
+char *m_strrtrim(char *s)
+{
+ ssize_t len = m_strlen(s);
+
+ while (len > 1 && ISSPACE(s[len - 1]))
+ s[--len] = '\0';
+
+ return s + len;
+}
+
+const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen)
+{
+ int nc;
+
+ if (!nlen)
+ return haystack;
+
+ nc = tolower(*needle);
+ for (;;) {
+ int c = tolower(*haystack);
+
+ if (c != nc) {
+ if (c == '\0')
+ return NULL;
+ } else {
+ ssize_t i;
+
+ /* compare the rest of needle */
+ for (i = 1;; i++) {
+ if (i == nlen)
+ return haystack;
+ if (c == '\0')
+ return NULL;
+ c = tolower(haystack[i]);
+ if (c != tolower(needle[i]))
+ break;
+ }
+ }
+
+ haystack++;
+ }
+}
+
+/** \brief \c NULL resistant strcasecmp.
+ * \param[in] a the first string.
+ * \param[in] b the second string.
+ * \return <tt>strcasecmp(a, b)</tt>, and treats \c NULL strings like \c ""
+ * ones, as if we were in the C locale.
+ */
+int ascii_strcasecmp(const char *a, const char *b)
+{
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+
+ while (*a || *b) {
+ int i;
+ if ((i = ascii_tolower(*a++) - ascii_tolower(*b++)))
+ return i;
+ }
+
+ return 0;
+}
+
+/** \brief \c NULL resistant strncasecmp.
+ * \param[in] a the first string.
+ * \param[in] b the second string.
+ * \param[in] n the number of maximum chars to compare.
+ * \return <tt>strncasecmp(a, b)</tt>, and treats \c NULL strings like \c ""
+ * ones, as if we were in the C locale.
+ */
+int ascii_strncasecmp(const char *a, const char *b, ssize_t n)
+{
+ if (a == b)
+ return 0;
+ if (!a)
+ return -1;
+ if (!b)
+ return 1;
+
+ while ((*a || *b) && n > 0) {
+ int i;
+ if ((i = ascii_tolower(*a++) - ascii_tolower(*b++)))
+ return i;
+ n--;
+ }
+
+ return 0;
+}
+
+/*@}*/