summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2008-06-11 15:09:46 +0300
committerAlan Coopersmith <alan.coopersmith@sun.com>2008-08-06 16:05:32 -0700
commit5a5030af9b8c7a801f07c82feaf3d2eaf4784db3 (patch)
tree79a0bdc9286ff473ee9b733f185e28208e395927
parentf7ee776de29b1cc23a3fd894a559c7d27ddd62af (diff)
DIX: Add strncasecmp from FreeBSD, make strcasecmp args const
Add strncasecmp (as we're now using it) in case someone doesn't have it, and also change strncasecmp args to be const, in accordance with everything else. (cherry picked from 11f9e3520249a603b95e64503ee759998ff17feb commit)
-rw-r--r--dix/strcasecmp.c21
-rw-r--r--include/dix.h7
2 files changed, 26 insertions, 2 deletions
diff --git a/dix/strcasecmp.c b/dix/strcasecmp.c
index 58f0961e6..8f7c5c402 100644
--- a/dix/strcasecmp.c
+++ b/dix/strcasecmp.c
@@ -33,7 +33,7 @@
#ifdef NEED_STRCASECMP
int
-xstrcasecmp(char *str1,char *str2)
+xstrcasecmp(const char *str1, const char *str2)
{
const u_char *us1 = (const u_char *)str1, *us2 = (const u_char *)str2;
@@ -46,3 +46,22 @@ xstrcasecmp(char *str1,char *str2)
return (tolower(*us1) - tolower(*us2));
}
#endif
+
+#ifdef NEED_STRNCASECMP
+int
+xstrncasecmp(const char *s1, const char *s2, size_t n)
+{
+ if (n != 0) {
+ const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2;
+
+ do {
+ if (tolower(*us1) != tolower(*us2++))
+ return (tolower(*us1) - tolower(*--us2));
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+
+ return 0;
+}
+#endif
diff --git a/include/dix.h b/include/dix.h
index 0790f5847..a321757e9 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -556,7 +556,12 @@ typedef struct {
/* strcasecmp.c */
#if NEED_STRCASECMP
#define strcasecmp xstrcasecmp
-extern int xstrcasecmp(char *s1, char *s2);
+extern int xstrcasecmp(const char *s1, const char *s2);
+#endif
+
+#if NEED_STRNCASECMP
+#define strncasecmp xstrncasecmp
+extern int xstrncasecmp(const char *s1, const char *s2, size_t n);
#endif
/*