Many files:
  Checked in e2fsprogs 0.5c

diff --git a/lib/e2p/iod.c b/lib/e2p/iod.c
index 52c16a1..7b02a7f 100644
--- a/lib/e2p/iod.c
+++ b/lib/e2p/iod.c
@@ -14,8 +14,6 @@
  * 93/10/30	- Creation
  */
 
-#include <dirent.h>
-
 #include "e2p.h"
 
 int iterate_on_dir (const char * dir_name,
@@ -23,7 +21,13 @@
 		    void * private)
 {
 	DIR * dir;
-	struct dirent de;
+#if HAVE_DIRENT_NAMELEN
+	/* Declare DE_BUF with some extra room for the name.  */
+	char de_buf[sizeof (struct dirent) + 32];
+	struct dirent *de = (struct dirent *)&de_buf;
+#else
+	struct dirent de_buf, *de = &de_buf;
+#endif
 	struct dirent *dep;
 
 	dir = opendir (dir_name);
@@ -31,12 +35,32 @@
 		return -1;
 	while ((dep = readdir (dir)))
 	{
-		de.d_ino = dep->d_ino;
-		de.d_off = dep->d_off;
-		de.d_reclen = dep->d_reclen;
-		strcpy (de.d_name, dep->d_name);
-		(*func) (dir_name, &de, private);
+#if HAVE_DIRENT_NAMELEN
+	  /* See if there's enough room for this entry in DE, and grow if
+	     not.  */
+	  if (de_len < dep->d_reclen)
+	    {
+	      de_len = dep->d_reclen + 32;
+	      de =
+		(de == (struct dirent *)&de_buf
+		 ? malloc (de_len)
+		 : realloc (de, de_len));
+	      if (de == NULL)
+		{
+		  errno = ENOMEM;
+		  return -1;
+		}
+	    }
+	  memcpy (de, dep, dep->d_reclen);
+#else
+	  *de = *dep;
+#endif
+	  (*func) (dir_name, de, private);
 	}
+#if HAVE_DIRENT_NAMELEN
+	if (de != (struct dirent *)&de_buf)
+	  free (de);
+#endif
 	closedir (dir);
 	return 0;
 }