From: Guido van Rossum Date: Tue, 18 Jul 1995 18:16:52 +0000 (+0000) Subject: suppress . and .. in listdir return value X-Git-Tag: v1.3b1~176 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24f42ac74c360eab36721bb01293940d2a743dd5;p=thirdparty%2FPython%2Fcpython.git suppress . and .. in listdir return value --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3d4bdcf9eae6..ffddd09154a4 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);