2 # Use the replacement ftw.c if the one in the C library is inadequate or buggy.
3 # For now, we always use the code in lib/ because libc doesn't have the FTW_DCH
4 # or FTW_DCHP that we need. Arrange to use lib/ftw.h. And since that
5 # implementation uses tsearch.c/tdestroy, add tsearch.o to the list of
6 # objects and arrange to use lib/search.h if necessary.
9 AC_DEFUN([AC_FUNC_FTW],
12 AC_REQUIRE([jm_FUNC_LSTAT])
13 AC_REQUIRE([AC_HEADER_DIRENT])
14 AC_CHECK_HEADERS(sys/param.h)
15 AC_CHECK_DECLS([stpcpy])
17 # In the event that we have to use the replacement ftw.c,
18 # see if we'll also need the replacement tsearch.c.
19 AC_CHECK_FUNC([tdestroy], , [need_tdestroy=1])
21 AC_CACHE_CHECK([for ftw/FTW_CHDIR that informs callback of failed chdir],
22 ac_cv_func_ftw_working,
24 # The following test would fail prior to glibc-2.3.2, because `depth'
25 # would be 2 rather than 4. Of course, now that we require FTW_DCH
26 # and FTW_DCHP, this test fails even with GNU libc's fixed ftw.
27 mkdir -p conftest.dir/a/b/c
28 AC_RUN_IFELSE([AC_LANG_SOURCE([[
33 static char *_f[] = { "conftest.dir", "conftest.dir/a",
34 "conftest.dir/a/b", "conftest.dir/a/b/c" };
39 cb (const char *file, const struct stat *sb, int file_type, struct FTW *info)
41 if (strcmp (file, *p++) != 0)
50 /* Require these symbols, too. */
54 int err = nftw ("conftest.dir", cb, 30, FTW_PHYS | FTW_MOUNT | FTW_CHDIR);
55 exit ((err == 0 && depth == 4) ? 0 : 1);
58 [ac_cv_func_ftw_working=yes],
59 [ac_cv_func_ftw_working=no],
60 [ac_cv_func_ftw_working=no])])
62 if test $ac_cv_func_ftw_working = no; then
64 AC_CONFIG_LINKS([$ac_config_libobj_dir/ftw.h:$ac_config_libobj_dir/ftw_.h])
65 # Add tsearch.o IFF we have to use the replacement ftw.c.
66 if test -n "$need_tdestroy"; then
68 # Link search.h to search_.h if we use the replacement tsearch.c.
70 [$ac_config_libobj_dir/search.h:$ac_config_libobj_dir/search_.h])