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

carmelo at uclibc.org carmelo at uclibc.org
Mon Oct 6 15:04:46 UTC 2008


Author: carmelo
Date: 2008-10-06 08:04:46 -0700 (Mon, 06 Oct 2008)
New Revision: 23600

Log:
Fix scandir function to reset the errno when the 
selector returns zero(no entries) modifying the errno.
The attached test case implements a dummy filter that returns
alway no entries, but change the errno. scandir is not expected
to fail, just returning 0 entries.

Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono at st.com>
Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro at st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>


Added:
   trunk/uClibc/test/misc/tst-scandir.c

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


Changeset:
Modified: trunk/uClibc/libc/misc/dirent/scandir.c
===================================================================
--- trunk/uClibc/libc/misc/dirent/scandir.c	2008-10-06 14:54:09 UTC (rev 23599)
+++ trunk/uClibc/libc/misc/dirent/scandir.c	2008-10-06 15:04:46 UTC (rev 23600)
@@ -35,9 +35,22 @@
     __set_errno (0);
 
     pos = 0;
-    while ((current = readdir (dp)) != NULL)
-	if (selector == NULL || (*selector) (current))
+    while ((current = readdir (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 dirent *vnew;
 	    size_t dsize;
 
@@ -64,6 +77,7 @@
 
 	    names[pos++] = (struct dirent *) memcpy (vnew, current, dsize);
 	}
+	}
 
     if (unlikely(errno != 0))
     {

Added: trunk/uClibc/test/misc/tst-scandir.c
===================================================================
--- trunk/uClibc/test/misc/tst-scandir.c	                        (rev 0)
+++ trunk/uClibc/test/misc/tst-scandir.c	2008-10-06 15:04:46 UTC (rev 23600)
@@ -0,0 +1,21 @@
+#include <dirent.h>
+#include <errno.h>
+
+int skip_all(const struct dirent *dirbuf)
+{
+	__set_errno(EBADF);
+	return 0;
+}
+
+int main()
+{
+	struct dirent **namelist;
+	int n;
+
+	n = scandir(".", &namelist, skip_all, 0);
+	if (n < 0) {
+		perror("scandir");
+		return 1;
+	}
+	return 0;
+}




More information about the uClibc-cvs mailing list