#include <errno.h>
#include <ftw.h>
+#include <limits.h>
#include <search.h>
#include <stdlib.h>
#include <string.h>
# include <sys/stat.h>
#endif
-#include <limits.h>
-#ifndef PATH_MAX
-# define PATH_MAX 1024
-#endif
-
#if ! _LIBC && !HAVE_DECL_STPCPY && !defined stpcpy
char *stpcpy ();
#endif
# define NFTW_FUNC_T __nftw_func_t
#endif
+/* We define PATH_MAX if the system does not provide a definition.
+ This does not artificially limit any operation. PATH_MAX is simply
+ used as a guesstimate for the expected maximal path length.
+ Buffers will be enlarged if necessary. */
+#ifndef PATH_MAX
+# define PATH_MAX 1024
+#endif
+
struct dir_data
{
DIR *stream;
* sizeof (struct dir_data *));
memset (data.dirstreams, '\0', data.maxdir * sizeof (struct dir_data *));
+ /* PATH_MAX is always defined when we get here. */
dir_len = strlen (dir);
data.dirbufsize = MAX (2 * dir_len, PATH_MAX);
data.dirbuf = (char *) malloc (data.dirbufsize);
/* Return to the start directory (if necessary). */
if (cwd != NULL)
{
- int saved_errno = errno;
+ int save_err = errno;
__chdir (cwd);
free (cwd);
- __set_errno (saved_errno);
+ __set_errno (save_err);
}
/* Free all memory. */