svn commit: trunk/uClibc/libc/misc/dirent

aldot at uclibc.org aldot at uclibc.org
Sat Oct 18 12:48:09 UTC 2008


Author: aldot
Date: 2008-10-18 05:48:09 -0700 (Sat, 18 Oct 2008)
New Revision: 23709

Log:
- sync fix for scandir errno handling to scandir64 (r23600)
  Thanks to Peter S. Mazinger for mentioning this.


Modified:
   trunk/uClibc/libc/misc/dirent/scandir.c
   trunk/uClibc/libc/misc/dirent/scandir64.c


Changeset:
Modified: trunk/uClibc/libc/misc/dirent/scandir.c
===================================================================
--- trunk/uClibc/libc/misc/dirent/scandir.c	2008-10-18 12:47:42 UTC (rev 23708)
+++ trunk/uClibc/libc/misc/dirent/scandir.c	2008-10-18 12:48:09 UTC (rev 23709)
@@ -13,10 +13,10 @@
 #include "dirstream.h"
 
 /* Experimentally off - libc_hidden_proto(memcpy) */
-libc_hidden_proto(readdir)
 libc_hidden_proto(opendir)
 libc_hidden_proto(closedir)
 libc_hidden_proto(qsort)
+libc_hidden_proto(readdir)
 
 int scandir(const char *dir, struct dirent ***namelist,
 	int (*selector) (const struct dirent *),
@@ -40,14 +40,12 @@
 
 	if (! use_it)
 	{
-  		use_it = (*selector) (current);
-  		/*
-		 * The selector function might have changed errno.
-		 * It was zero before and it need to be again to make
-		 * the latter tests work.
-		 */
- 		if (! use_it)
-			__set_errno (0);
+	    use_it = (*selector) (current);
+	    /* The selector function might have changed errno.
+	     * It was zero before and it need to be again to make
+	     * the latter tests work.  */
+	    if (! use_it)
+		__set_errno (0);
 	}
 	if (use_it)
 	{
@@ -64,20 +62,21 @@
 		    names_size = 10;
 		else
 		    names_size *= 2;
-		new = (struct dirent **) realloc (names, names_size * sizeof (struct dirent *));
+		new = (struct dirent **) realloc (names,
+					names_size * sizeof (struct dirent *));
 		if (new == NULL)
 		    break;
 		names = new;
 	    }
 
-	    dsize = &current->d_name[_D_ALLOC_NAMLEN (current)] - (char *) current;
+	    dsize = &current->d_name[_D_ALLOC_NAMLEN(current)] - (char*)current;
 	    vnew = (struct dirent *) malloc (dsize);
 	    if (vnew == NULL)
 		break;
 
 	    names[pos++] = (struct dirent *) memcpy (vnew, current, dsize);
 	}
-	}
+    }
 
     if (unlikely(errno != 0))
     {

Modified: trunk/uClibc/libc/misc/dirent/scandir64.c
===================================================================
--- trunk/uClibc/libc/misc/dirent/scandir64.c	2008-10-18 12:47:42 UTC (rev 23708)
+++ trunk/uClibc/libc/misc/dirent/scandir64.c	2008-10-18 12:48:09 UTC (rev 23709)
@@ -53,9 +53,20 @@
     __set_errno (0);
 
     pos = 0;
-    while ((current = readdir64 (dp)) != NULL)
-	if (selector == NULL || (*selector) (current))
+    while ((current = readdir64 (dp)) != NULL) {
+	int use_it = selector == NULL;
+
+	if (! use_it)
 	{
+	    use_it = (*selector) (current);
+	    /* The selector function might have changed errno.
+	     * It was zero before and it need to be again to make
+	     * the latter tests work.  */
+	    if (! use_it)
+		__set_errno (0);
+	}
+	if (use_it)
+	{
 	    struct dirent64 *vnew;
 	    size_t dsize;
 
@@ -69,20 +80,21 @@
 		    names_size = 10;
 		else
 		    names_size *= 2;
-		new = (struct dirent64 **) realloc (names, names_size * sizeof (struct dirent64 *));
+		new = (struct dirent64 **) realloc (names,
+				      names_size * sizeof (struct dirent64 *));
 		if (new == NULL)
 		    break;
 		names = new;
 	    }
 
-	    dsize = &current->d_name[_D_ALLOC_NAMLEN (current)] - (char *) current;
+	    dsize = &current->d_name[_D_ALLOC_NAMLEN(current)] - (char*)current;
 	    vnew = (struct dirent64 *) malloc (dsize);
 	    if (vnew == NULL)
 		break;
 
 	    names[pos++] = (struct dirent64 *) memcpy (vnew, current, dsize);
 	}
-
+    }
     if (unlikely(errno != 0))
     {
 	save = errno;




More information about the uClibc-cvs mailing list