aboutsummaryrefslogtreecommitdiffstats
path: root/indep.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-06-07 15:46:44 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-06-07 15:46:44 +0000
commit259d1f18be2e57a9ec6e768989571f6c8f82aed7 (patch)
treebe356bce49aef38de77c76cdaa413bdf7658a46a /indep.c
parent[w3m-dev 03206] Re: dict (diff)
downloadw3m-259d1f18be2e57a9ec6e768989571f6c8f82aed7.tar.gz
w3m-259d1f18be2e57a9ec6e768989571f6c8f82aed7.zip
[w3m-dev 03207] strchr(), strcasecmp(), and strncasecmp()
* etc.c (strchr): removed (strcasecmp): removed (strncasecmp): removed * indep.c (strchr): moved, cast (strcasecmp): moved, fix the case that s1 = "" (strncasecmp): moved, fix the case that s1 is shorter than s2 * indep.h (strchr): added (strcasecmp): added (strncasecmp): added From: Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
Diffstat (limited to '')
-rw-r--r--indep.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/indep.c b/indep.c
index a0b2ee4..a535748 100644
--- a/indep.c
+++ b/indep.c
@@ -1,4 +1,4 @@
-/* $Id: indep.c,v 1.21 2001/12/26 17:57:57 ukai Exp $ */
+/* $Id: indep.c,v 1.22 2002/06/07 15:46:44 ukai Exp $ */
#include "fm.h"
#include <stdio.h>
#include <pwd.h>
@@ -193,6 +193,50 @@ expandPath(char *name)
return extpath->ptr;
}
+#ifndef HAVE_STRCHR
+char *
+strchr(const char *s, int c)
+{
+ while (*s) {
+ if ((unsigned char)*s == c)
+ return (char *)s;
+ s++;
+ }
+ return NULL;
+}
+#endif /* not HAVE_STRCHR */
+
+#ifndef HAVE_STRCASECMP
+int
+strcasecmp(const char *s1, const char *s2)
+{
+ int x;
+ while (*s1) {
+ x = tolower(*s1) - tolower(*s2);
+ if (x != 0)
+ return x;
+ s1++;
+ s2++;
+ }
+ return -tolower(*s2);
+}
+
+int
+strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ int x;
+ while (*s1 && n) {
+ x = tolower(*s1) - tolower(*s2);
+ if (x != 0)
+ return x;
+ s1++;
+ s2++;
+ n--;
+ }
+ return n ? -tolower(*s2) : 0;
+}
+#endif /* not HAVE_STRCASECMP */
+
#ifndef HAVE_STRCASESTR
/* string search using the simplest algorithm */
char *