From 24f42ac74c360eab36721bb01293940d2a743dd5 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 18 Jul 1995 18:16:52 +0000 Subject: suppress . and .. in listdir return value --- Modules/posixmodule.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3d4bdcf..ffddd09 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -408,6 +408,11 @@ posix_listdir(self, args) return posix_error(); } do { + if (FileData.cFileName[0] == '.' && + (FileData.cFileName[1] == '\0' || + FileData.cFileName[1] == '.' && + FileData.cFileName[2] == '\0')) + continue; v = newstringobject(FileData.cFileName); if (v == NULL) { DECREF(d); @@ -449,6 +454,10 @@ posix_listdir(self, args) return NULL; } while ((ep = readdir(dirp)) != NULL) { + if (ep->d_name[0] == '.' && + (NAMLEN(ep) == 1 || + ep->d_name[1] == '.' && NAMLEN(ep) == 2)) + continue; v = newsizedstringobject(ep->d_name, NAMLEN(ep)); if (v == NULL) { DECREF(d); -- cgit v0.12