Module Name: src
Committed By: martin
Date: Mon Aug 12 09:34:53 UTC 2019
Modified Files:
src/distrib/utils/libhack: strcasecmp.c
Log Message:
Make this at least work for ASCII strings (there are way more users
than libcurses in various crunched environments, so the original assumption
of a very limited set of inputs was wrong).
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/distrib/utils/libhack/strcasecmp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/utils/libhack/strcasecmp.c
diff -u src/distrib/utils/libhack/strcasecmp.c:1.1 src/distrib/utils/libhack/strcasecmp.c:1.2
--- src/distrib/utils/libhack/strcasecmp.c:1.1 Sun Jul 28 10:21:18 2019
+++ src/distrib/utils/libhack/strcasecmp.c Mon Aug 12 09:34:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: strcasecmp.c,v 1.1 2019/07/28 10:21:18 martin Exp $ */
+/* $NetBSD: strcasecmp.c,v 1.2 2019/08/12 09:34:53 martin Exp $ */
/*
* Written by Martin Husemann <[email protected]>
@@ -8,13 +8,21 @@
#include <strings.h>
/*
- * Cheap and dirty strcasecmp() - implements just enough
- * for our libcurses in crunched environments: since we
- * know all compared strings are fixed, uppercase, and plain ASCII,
- * just use strcmp()
+ * Simple strcasecmp, try to avoid pulling in real locales
*/
int
strcasecmp(const char *s1, const char *s2)
{
- return strcmp(s1, s2);
+ unsigned int c1, c2;
+
+ do {
+ c1 = *s1++;
+ c2 = *s2++;
+ if (c1 >= 'A' && c1 <= 'Z')
+ c1 += 'a' - 'A';
+ if (c2 >= 'A' && c2 <= 'Z')
+ c2 += 'a' - 'A';
+ } while (c1 == c2 && c1 != 0 && c2 != 0);
+
+ return ((c1 == c2) ? 0 : ((c1 > c2) ? 1 : -1));
}