Browse code

strcasestr() check and replacement.

git-svn: trunk@3461

Török Edvin authored on 2007/12/29 00:13:12
Showing 5 changed files
... ...
@@ -240,6 +240,9 @@
240 240
 /* Define to 1 if you have the <stdlib.h> header file. */
241 241
 #undef HAVE_STDLIB_H
242 242
 
243
+/* Define to 1 if you have the `strcasestr' function. */
244
+#undef HAVE_STRCASESTR
245
+
243 246
 /* Define to 1 if you have the `strerror_r' function. */
244 247
 #undef HAVE_STRERROR_R
245 248
 
... ...
@@ -21191,7 +21191,8 @@ fi
21191 21191
 
21192 21192
 
21193 21193
 
21194
-for ac_func in poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat inet_ntop setgroups initgroups ctime_r mkstemp
21194
+
21195
+for ac_func in poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp
21195 21196
 do
21196 21197
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
21197 21198
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
... ...
@@ -210,7 +210,7 @@ AC_CHECK_LIB(nsl, gethostent, [LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_M
210 210
 
211 211
 AC_CHECK_LIB(iconv, libiconv_open, LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -liconv")
212 212
 
213
-AC_CHECK_FUNCS(poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat inet_ntop setgroups initgroups ctime_r mkstemp)
213
+AC_CHECK_FUNCS(poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp)
214 214
 AC_FUNC_MMAP
215 215
 AC_FUNC_FSEEKO
216 216
 
... ...
@@ -397,6 +397,24 @@ char *cli_strrcpy(char *dest, const char *source) /* by NJH */
397 397
     return --dest;
398 398
 }
399 399
 
400
+#ifndef HAVE_STRCASESTR
401
+const char* cli_strcasestr(const char* a, const char *b)
402
+{
403
+	/*
404
+	 * From http://unixpapa.com/incnote/string.html, which has this notice:
405
+	 * All of the C code on this page is public domain and may be used without concern for licenses. Some was contributed by Dan Cross.
406
+	 */
407
+	size_t l;
408
+	char f[3];
409
+
410
+	snprintf(f, sizeof(f), "%c%c", tolower(*b), toupper(*b));
411
+	for (l = strcspn(a, f); l != strlen(a); l += strcspn(a + l + 1, f) + 1)
412
+		if (strncasecmp(a + l, b, strlen(b)) == 0)
413
+			return(a + l);
414
+	return(NULL);
415
+}
416
+#endif
417
+
400 418
 void cli_strtokenize(char *buffer, const char delim, const size_t token_count, const char **tokens)
401 419
 {
402 420
 	size_t tokens_found;
... ...
@@ -23,6 +23,12 @@
23 23
 
24 24
 #include "cltypes.h"
25 25
 
26
+#ifdef HAVE_STRCASESTR
27
+#define cli_strcasestr strcasestr
28
+#else
29
+const char *cli_strcasestr(const char *haystack, const char *needle);
30
+#endif
31
+
26 32
 int cli_strbcasestr(const char *haystack, const char *needle);
27 33
 int cli_chomp(char *string);
28 34
 char *cli_strtok(const char *line, int field, const char *delim);