3 dnl SunOS's readdir is broken in such a way that rm.c has to add extra code
4 dnl to test whether a NULL return value really means there are no more files
7 dnl Detect the problem by creating a directory containing 300 files (254 not
8 dnl counting . and .. is the minimum) and see if a loop doing `readdir; unlink'
9 dnl removes all of them.
11 dnl Define HAVE_WORKING_READDIR if readdir does *not* have this problem.
13 dnl Written by Jim Meyering.
15 AC_DEFUN([jm_FUNC_READDIR],
17 AC_REQUIRE([AC_HEADER_DIRENT])
18 AC_CHECK_HEADERS(string.h)
19 AC_CACHE_CHECK([for working readdir], jm_cv_func_working_readdir,
21 # Arrange for deletion of the temporary directory this test creates, in
22 # case the test itself fails to delete everything -- as happens on Sunos.
23 ac_clean_files="$ac_clean_files conf-dir"
27 # include <sys/types.h>
34 # define NLENGTH(direct) (strlen((direct)->d_name))
35 # else /* not HAVE_DIRENT_H */
36 # define dirent direct
37 # define NLENGTH(direct) ((direct)->d_namlen)
38 # ifdef HAVE_SYS_NDIR_H
39 # include <sys/ndir.h>
40 # endif /* HAVE_SYS_NDIR_H */
41 # ifdef HAVE_SYS_DIR_H
43 # endif /* HAVE_SYS_DIR_H */
46 # endif /* HAVE_NDIR_H */
47 # endif /* HAVE_DIRENT_H */
49 # define DOT_OR_DOTDOT(Basename) \
50 (Basename[0] == '.' && (Basename[1] == '\0' \
51 || (Basename[1] == '.' && Basename[2] == '\0')))
53 /* Don't try to use replacement mkdir; it wouldn't resolve at link time. */
57 create_300_file_dir (const char *dir)
61 if (mkdir (dir, 0700))
66 for (i = 0; i < 300; i++)
71 sprintf (file_name, "%03d", i);
72 out = fopen (file_name, "w");
75 if (fclose (out) == EOF)
84 remove_dir (const char *dir)
97 struct dirent *dp = readdir (dirp);
101 if (DOT_OR_DOTDOT (dp->d_name))
104 if (unlink (dp->d_name))
119 const char *dir = "conf-dir";
120 create_300_file_dir (dir);
124 jm_cv_func_working_readdir=yes,
125 jm_cv_func_working_readdir=no,
126 jm_cv_func_working_readdir=no)])
128 if test $jm_cv_func_working_readdir = yes; then
129 AC_DEFINE(HAVE_WORKING_READDIR, 1,
130 [Define if readdir is found to work properly in some unusual cases. ])