From 05e6caacb24957e1ac5e973cce3939872eb7208c Mon Sep 17 00:00:00 2001 From: corinna Date: Fri, 12 Aug 2011 12:31:06 +0000 Subject: [PATCH] * fhandler.h (fhandler_proc::opendir): Declare. (fhandler_proc::closedir): Declare. * fhandler_proc.cc (fhandler_proc::opendir): New method. Fetch list of active processes here once to avoid potential duplicates. (fhandler_proc::closedir): New method. --- winsup/cygwin/ChangeLog | 8 ++++++++ winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_proc.cc | 22 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8dc5248dba..933769a487 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2011-08-12 Corinna Vinschen + + * fhandler.h (fhandler_proc::opendir): Declare. + (fhandler_proc::closedir): Declare. + * fhandler_proc.cc (fhandler_proc::opendir): New method. Fetch list + of active processes here once to avoid potential duplicates. + (fhandler_proc::closedir): New method. + 2011-08-11 Corinna Vinschen * fhandler_proc.cc (fhandler_proc::get_proc_fhandler): Don't allow to diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index b8c3f20bb5..3cbcba91dd 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1440,6 +1440,8 @@ class fhandler_proc: public fhandler_virtual public: fhandler_proc (); virtual_ftype_t exists(); + DIR *opendir (int fd) __attribute__ ((regparm (2))); + int closedir (DIR *); int readdir (DIR *, dirent *) __attribute__ ((regparm (3))); static fh_devices get_proc_fhandler (const char *path); diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 63178a0037..94007cae17 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -220,6 +220,26 @@ fhandler_proc::fstat (struct __stat64 *buf) return -1; } +DIR * +fhandler_proc::opendir (int fd) +{ + DIR *dir = fhandler_virtual::opendir (fd); + if (dir && !(dir->__handle = (void *) new winpids ((DWORD) 0))) + { + free (dir); + dir = NULL; + set_errno (ENOMEM); + } + return dir; +} + +int +fhandler_proc::closedir (DIR *dir) +{ + free (dir->__handle); + return fhandler_virtual::closedir (dir); +} + int fhandler_proc::readdir (DIR *dir, dirent *de) { @@ -232,7 +252,7 @@ fhandler_proc::readdir (DIR *dir, dirent *de) } else { - winpids pids ((DWORD) 0); + winpids &pids = *(winpids *) dir->__handle; int found = 0; res = ENMFILE; for (unsigned i = 0; i < pids.npids; i++) -- 2.11.0