summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-10 18:43:09 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-10 18:43:09 +0000
commitf8d8287cdbd7da9cd9392bcddf04860a10fa598e (patch)
tree668b4cc601fdfd050a51095d4f9bbebef9eaffec /src/utils.c
downloadiconv-f8d8287cdbd7da9cd9392bcddf04860a10fa598e.tar.gz
iconv-f8d8287cdbd7da9cd9392bcddf04860a10fa598e.tar.bz2
Import Iconv sources
svn path=/trunk/iconv/; revision=5677
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..5403816
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,53 @@
+#include <ctype.h>
+
+#include "internal.h"
+
+/**
+ * Case insensitive string comparison
+ *
+ * \param s1 Pointer to string
+ * \param s2 Pointer to string
+ * \return 0 if strings match, <> 0 if no match
+ */
+int strcasecmp(const char *s1, const char *s2)
+{
+ int i;
+
+ if (!s1 || !s2)
+ return 1; /* this is arbitrary */
+
+ if (s1 == s2)
+ return 0;
+
+ while ((i = tolower(*s1)) && i == tolower(*s2))
+ s1++, s2++;
+
+ return ((unsigned char) tolower(*s1) - (unsigned char) tolower(*s2));
+}
+
+/**
+ * Length-limited case insensitive string comparison
+ *
+ * \param s1 Pointer to string
+ * \param s2 Pointer to string
+ * \param len Length to compare
+ * \return 0 if strings match, <> 0 if no match
+ */
+int strncasecmp(const char *s1, const char *s2, size_t len)
+{
+ int i;
+
+ if (!s1 || !s2)
+ return 1; /* this is arbitrary */
+
+ if (len == 0)
+ return 0;
+
+ if (s1 == s2)
+ return 0;
+
+ while (len-- && (i = tolower(*s1)) && i == tolower(*s2))
+ s1++, s2++;
+
+ return ((unsigned char) tolower(*s1) - (unsigned char) tolower(*s2));
+}