about summary refs log tree commit diff
path: root/io
diff options
context:
space:
mode:
Diffstat (limited to 'io')
-rw-r--r--io/fts.c11
-rw-r--r--io/ftw.c15
2 files changed, 16 insertions, 10 deletions
diff --git a/io/fts.c b/io/fts.c
index 5bc1aff015..fe5750ab56 100644
--- a/io/fts.c
+++ b/io/fts.c
@@ -661,13 +661,16 @@ fts_build(sp, type)
 	/* Read the directory, attaching each entry to the `link' pointer. */
 	adjaddr = NULL;
 	for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) {
+		int namlen;
+
 		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
 			continue;
 
-		if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+		namlen = _D_EXACT_NAMLEN (dp);
+		if ((p = fts_alloc(sp, dp->d_name, namlen)) == NULL)
 			goto mem1;
-		if (dp->d_namlen > maxlen) {
-			if (fts_palloc(sp, (size_t)dp->d_namlen)) {
+		if (namlen > maxlen) {
+			if (fts_palloc(sp, (size_t)namlen)) {
 				/*
 				 * No more memory for path or structures.  Save
 				 * errno, free up the current structure and the
@@ -687,7 +690,7 @@ mem1:				saved_errno = errno;
 			maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1;
 		}
 
-		p->fts_pathlen = len + dp->d_namlen + 1;
+		p->fts_pathlen = len + namlen + 1;
 		p->fts_parent = sp->fts_cur;
 		p->fts_level = level;
 
diff --git a/io/ftw.c b/io/ftw.c
index 7b264e032e..ff2e2b1fdc 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 Contributed by Ian Lance Taylor (ian@airs.com).
 
@@ -53,18 +53,21 @@ DEFUN (ftw_dir, (dirs, level, descriptors, dir, len, func),
     {
       struct stat s;
       int flag, retval, newlev;
+      size_t namlen;
 
       ++got;
 
       if (entry->d_name[0] == '.'
-	  && (entry->d_namlen == 1 ||
-	      (entry->d_namlen == 2 && entry->d_name[1] == '.')))
+	  && (entry->d_name[1] == '\0' ||
+	      (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
 	{
 	  errno = 0;
 	  continue;
 	}
 
-      if (entry->d_namlen + len + 1 > PATH_MAX)
+      namlen = _D_EXACT_NAMLEN (entry);
+
+      if (namlen + len + 1 > PATH_MAX)
 	{
 #ifdef ENAMETOOLONG
 	  errno = ENAMETOOLONG;
@@ -76,7 +79,7 @@ DEFUN (ftw_dir, (dirs, level, descriptors, dir, len, func),
 
       dir[len] = '/';
       memcpy ((PTR) (dir + len + 1), (PTR) entry->d_name,
-	      entry->d_namlen + 1);
+	      namlen + 1);
 
       if (stat (dir, &s) < 0)
 	{
@@ -110,7 +113,7 @@ DEFUN (ftw_dir, (dirs, level, descriptors, dir, len, func),
 	{
 	  if (retval == 0)
 	    retval = ftw_dir (dirs, newlev, descriptors, dir,
-			      entry->d_namlen + len + 1, func);
+			      namlen + len + 1, func);
 	  if (dirs[newlev] != NULL)
 	    {
 	      int save;