$NetBSD$

--- lib/ftw/ftw.c.orig	2005-12-18 22:14:06.000000000 +0000
+++ lib/ftw/ftw.c
@@ -19,6 +19,7 @@
  *  recycle file descriptors.
  */
 
+#include <limits.h>
 #include <stdio.h>
 #include "cdialect.h"
 #include <sys/stat.h>
@@ -71,7 +72,11 @@ ftw(directory, funcptr, depth)
 
     /* Get ready to hold the full paths. */
     i = strlen(directory);
+#ifdef NAME_MAX
+    fullpath = (char *)malloc(i + 1 + NAME_MAX + 1);
+#else
     fullpath = (char *)malloc(i + 1 + MAXNAMLEN + 1);
+#endif
     if (fullpath == NULL) {
 	closedir(dirp);
 	return -1;
