summaryrefslogtreecommitdiff
path: root/src/port/string.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-02-22 18:54:28 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-02-22 18:54:28 +0100
commitd92e188e4b4c53e89ba55ae54a10802f156fdf19 (patch)
treefc177ff92704aecb47a1a8d8a6e0971dfdd8ad05 /src/port/string.c
parent2b55ffee666c795e5b639cacf147ab4798b17044 (diff)
downloadwolfbones-d92e188e4b4c53e89ba55ae54a10802f156fdf19.tar.gz
wolfbones-d92e188e4b4c53e89ba55ae54a10802f156fdf19.tar.bz2
started to add string.h replacements
Diffstat (limited to 'src/port/string.c')
-rw-r--r--src/port/string.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/port/string.c b/src/port/string.c
index c059431..01c5228 100644
--- a/src/port/string.c
+++ b/src/port/string.c
@@ -69,3 +69,52 @@ int wolf_port_strerror_r( int num, char *buf, size_t buflen ) {
}
#endif /* !defined HAVE_STRERROR_R */
+
+/**
+ * str(n)casecmp is always around but on very old or strance C libraries.
+ * We should only use it in 7-bit ASCII places like in the protocol. In
+ * the Windows API they are called stri(n)cmp, so we have to map them
+ * anyway.
+ */
+
+#if !defined HAVE_STRCASECMP
+
+#include <ctype.h> /* for tolower */
+
+int wolf_port_strcasecmp( const char *s1, const char *s2 ) {
+ int c1, c2;
+
+ do {
+ c1 = tolower( (unsigned char)*s1 );
+ c2 = tolower( (unsigned char)*s2 );
+ s1++;
+ s2++;
+ } while( c1 == c2 && c1 != '\0' && c2 != '\0' );
+
+ return( c2 > c1 ? -1 : c1 > c2 );
+}
+
+#endif /* !defined HAVE_STRCASECMP */
+
+#if !defined HAVE_STRNCASECMP
+
+#include <ctype.h> /* for tolower */
+
+int wolf_port_strncasecmp( const char *s1, const char *s2, size_t n ) {
+ int c1, c2;
+
+ if( n == 0 )
+ return 0;
+
+ do {
+ c1 = tolower( (unsigned char)*s1 );
+ c2 = tolower( (unsigned char)*s2 );
+ s1++;
+ s2++;
+ n--;
+ } while( n > 0 && c1 == c2 && c1 != '\0' && c2 != '\0' );
+
+ return( c2 > c1 ? -1 : c1 > c2 );
+}
+
+#endif /* !defined HAVE_STRNCASECMP */