summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2007-05-09 02:01:53 +0000
committerPaul Smith <psmith@gnu.org>2007-05-09 02:01:53 +0000
commit52ebc531ce68b369594267a716e93f53720c8f1b (patch)
tree3404b1e3f513b67dd501f252d2aea327c06ca03b /misc.c
parent891409f2126f8abfd64f28fe82f546d716c671e2 (diff)
downloadgunmake-52ebc531ce68b369594267a716e93f53720c8f1b.tar.gz
Fix Savannah bug #19656: rationalize our use of case-insensitive string
comparison functions to always use POSIX strcasecmp(). For non-POSIX systems that use other functions (strcmpi or stricmp) use a macro to alias strcasecmp to those. If we can't find any of them (VMS, plus whatever UNIX doesn't have them) then define our own version in misc.c.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index df54163..a63bbfd 100644
--- a/misc.c
+++ b/misc.c
@@ -556,6 +556,33 @@ free_ns_chain (struct nameseq *ns)
}
}
+
+#if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI
+
+/* If we don't have strcasecmp() (from POSIX), or anything that can substitute
+ for it, define our own version. */
+
+int
+strcasecmp (const char *s1, const char *s2)
+{
+ while (1)
+ {
+ int c1 = (int) *(s1++);
+ int c2 = (int) *(s2++);
+
+ if (isalpha (c1))
+ c1 = tolower (c1);
+ if (isalpha (c2))
+ c2 = tolower (c2);
+
+ if (c1 != '\0' && c1 == c2)
+ continue;
+
+ return (c1 - c2);
+ }
+}
+#endif
+
#ifdef GETLOADAVG_PRIVILEGED
#ifdef POSIX