Mercurial > hg > octave-kai > gnulib-hg
annotate m4/strcasestr.m4 @ 11628:59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
* modules/strstr: Split into...
* modules/strstr-simple: ...new module that does not care about
performance, but does care about glibc bug.
* m4/strstr.m4 (gl_FUNC_STRSTR): Split...
(gl_FUNC_STRSTR_SIMPLE): ...into new macro, which replaces strstr
if platform memchr is broken, per Debian bug 521737.
* m4/strcasestr.m4 (gl_FUNC_STRCASESTR_SIMPLE): React to broken
memchr.
* m4/memchr.m4 (gl_FUNC_MEMCHR): Only expand once.
* doc/posix-functions/strstr.texi (strstr): Document the fix.
* doc/glibc-functions/strcasestr.texi (strcasestr): Likewise.
* modules/mountlist (Depends-on): Add strstr-simple.
* modules/gen-uni-tables (Depends-on): Likewise.
* modules/argz (Depends-on): Add strstr.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Tue, 16 Jun 2009 06:14:05 -0600 |
parents | 2304e9103317 |
children | b0f6e24e92ac |
rev | line source |
---|---|
11628
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
1 # strcasestr.m4 serial 13 |
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
2 dnl Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc. |
6058 | 3 dnl This file is free software; the Free Software Foundation |
4 dnl gives unlimited permission to copy and/or distribute it, | |
5 dnl with or without modifications, as long as this notice is preserved. | |
6 | |
11628
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
7 dnl Check that strcasestr is present and works. |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
8 AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE], |
6058 | 9 [ |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
10 dnl Persuade glibc <string.h> to declare strcasestr(). |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
11 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
12 |
7982
6b61aba76343
Enforce ordering constraints between gl_HEADER_STRING_H_DEFAULTS and the
Bruno Haible <bruno@clisp.org>
parents:
7980
diff
changeset
|
13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) |
11628
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
14 AC_REQUIRE([gl_FUNC_MEMCHR]) |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
15 AC_REPLACE_FUNCS([strcasestr]) |
8098
cc3f4a2db5b0
New module 'mbscasestr'. Reduced goal of 'strcasestr'.
Bruno Haible <bruno@clisp.org>
parents:
7982
diff
changeset
|
16 if test $ac_cv_func_strcasestr = no; then |
cc3f4a2db5b0
New module 'mbscasestr'. Reduced goal of 'strcasestr'.
Bruno Haible <bruno@clisp.org>
parents:
7982
diff
changeset
|
17 HAVE_STRCASESTR=0 |
cc3f4a2db5b0
New module 'mbscasestr'. Reduced goal of 'strcasestr'.
Bruno Haible <bruno@clisp.org>
parents:
7982
diff
changeset
|
18 gl_PREREQ_STRCASESTR |
11628
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
19 elif test "$gl_cv_func_memchr_works" != yes; then |
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
20 REPLACE_STRCASESTR=1 |
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
21 AC_LIBOBJ([strcasestr]) |
59047bad770e
strstr, strcasestr: replace on platforms with broken memchr
Eric Blake <ebb9@byu.net>
parents:
10189
diff
changeset
|
22 gl_PREREQ_STRCASESTR |
8098
cc3f4a2db5b0
New module 'mbscasestr'. Reduced goal of 'strcasestr'.
Bruno Haible <bruno@clisp.org>
parents:
7982
diff
changeset
|
23 fi |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
24 ]) # gl_FUNC_STRCASESTR_SIMPLE |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
25 |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
26 dnl Additionally, check that strcasestr is efficient. |
9624 | 27 AC_DEFUN([gl_FUNC_STRCASESTR], |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
28 [ |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
29 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE]) |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
30 if test $ac_cv_func_strcasestr = yes; then |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
31 AC_CACHE_CHECK([whether strcasestr works in linear time], |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
32 [gl_cv_func_strcasestr_linear], |
9921
01cfd65cc7e0
Fix underquoting of AC_LANG_PROGRAM arguments.
Bruno Haible <bruno@clisp.org>
parents:
9624
diff
changeset
|
33 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
10189
2304e9103317
Work around environments that (stupidly) ignore SIGALRM.
Eric Blake <ebb9@byu.net>
parents:
10082
diff
changeset
|
34 #include <signal.h> /* for signal */ |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
35 #include <string.h> /* for memmem */ |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
36 #include <stdlib.h> /* for malloc */ |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
37 #include <unistd.h> /* for alarm */ |
9921
01cfd65cc7e0
Fix underquoting of AC_LANG_PROGRAM arguments.
Bruno Haible <bruno@clisp.org>
parents:
9624
diff
changeset
|
38 ]], [[size_t m = 1000000; |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
39 char *haystack = (char *) malloc (2 * m + 2); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
40 char *needle = (char *) malloc (m + 2); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
41 void *result = 0; |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
42 /* Failure to compile this test due to missing alarm is okay, |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
43 since all such platforms (mingw) also lack strcasestr. */ |
10189
2304e9103317
Work around environments that (stupidly) ignore SIGALRM.
Eric Blake <ebb9@byu.net>
parents:
10082
diff
changeset
|
44 signal (SIGALRM, SIG_DFL); |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
45 alarm (5); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
46 /* Check for quadratic performance. */ |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
47 if (haystack && needle) |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
48 { |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
49 memset (haystack, 'A', 2 * m); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
50 haystack[2 * m] = 'B'; |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
51 haystack[2 * m + 1] = 0; |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
52 memset (needle, 'A', m); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
53 needle[m] = 'B'; |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
54 needle[m + 1] = 0; |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
55 result = strcasestr (haystack, needle); |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
56 } |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
57 return !result;]])], |
10081
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
58 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no], |
10082
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
59 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
60 dnl strcasestr that works in linear time. |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
61 AC_EGREP_CPP([Lucky user], |
10081
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
62 [ |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
63 #include <features.h> |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
64 #ifdef __GNU_LIBRARY__ |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
65 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2) |
10082
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
66 Lucky user |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
67 #endif |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
68 #endif |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
69 #ifdef __CYGWIN__ |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
70 #include <cygwin/version.h> |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
71 #if CYGWIN_VERSION_DLL_MAJOR >= 1007 |
44e8848f6ce8
Extend previous patch to cygwin 1.7.0.
Eric Blake <ebb9@byu.net>
parents:
10081
diff
changeset
|
72 Lucky user |
10081
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
73 #endif |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
74 #endif |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
75 ], |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
76 [gl_cv_func_strcasestr_linear=yes], |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
77 [gl_cv_func_strcasestr_linear="guessing no"]) |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
78 ]) |
ea9dd8bc5005
Update cross-compiling guess now that glibc 2.9 will have fast implementations.
Bruno Haible <bruno@clisp.org>
parents:
9921
diff
changeset
|
79 ]) |
9623
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
80 if test "$gl_cv_func_strcasestr_linear" != yes; then |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
81 REPLACE_STRCASESTR=1 |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
82 AC_LIBOBJ([strcasestr]) |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
83 fi |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
84 fi |
69d9307c0aa0
Convert strcasestr module to use Two-Way algorithm.
Eric Blake <ebb9@byu.net>
parents:
8100
diff
changeset
|
85 ]) # gl_FUNC_STRCASESTR |
6058 | 86 |
87 # Prerequisites of lib/strcasestr.c. | |
88 AC_DEFUN([gl_PREREQ_STRCASESTR], [ | |
6301
015760832874
Deal with the fact that mbchar.h, mbfile.h, mbiter.h, mbuiter.h can
Bruno Haible <bruno@clisp.org>
parents:
6058
diff
changeset
|
89 : |
6058 | 90 ]) |