From 95c20b15f90ae8b406b2c9a4e6eae4e3e8d0c77f Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 19 Apr 2004 18:09:15 +0000 Subject: added name and isExecutable, patch from Mathias Gumz --- src/FbTk/Directory.cc | 15 ++++++++++++++- src/FbTk/Directory.hh | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/FbTk/Directory.cc b/src/FbTk/Directory.cc index 5ec5c0c..1f2ac7d 100644 --- a/src/FbTk/Directory.cc +++ b/src/FbTk/Directory.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ +// $Id: Directory.cc,v 1.3 2004/04/19 18:09:15 fluxgen Exp $ #include "Directory.hh" @@ -60,6 +60,7 @@ std::string Directory::readFilename() { void Directory::close() { if (m_dir != 0) { closedir(m_dir); + m_name.clear(); m_dir = 0; m_num_entries = 0; } @@ -77,6 +78,8 @@ bool Directory::open(const char *dir) { if (m_dir == 0) // successfull loading? return false; + m_name= dir; + // get number of entries while (read()) m_num_entries++; @@ -102,4 +105,14 @@ bool Directory::isRegularFile(const std::string &filename) { return S_ISREG(statbuf.st_mode); } +bool Directory::isExecutable(const std::string &filename) { + struct stat statbuf; + if (stat(filename.c_str(), &statbuf) != 0) + return false; + + return statbuf.st_mode & S_IXUSR || + statbuf.st_mode & S_IXGRP || + statbuf.st_mode & S_IXOTH; +} + }; // end namespace FbTk diff --git a/src/FbTk/Directory.hh b/src/FbTk/Directory.hh index 8d3a42d..a553d56 100644 --- a/src/FbTk/Directory.hh +++ b/src/FbTk/Directory.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.hh,v 1.3 2003/12/16 17:06:49 fluxgen Exp $ +// $Id: Directory.hh,v 1.4 2004/04/19 18:09:14 fluxgen Exp $ #ifndef FBTK_DIRECTORY_HH #define FBTK_DIRECTORY_HH @@ -37,6 +37,7 @@ class Directory: private FbTk::NotCopyable { public: explicit Directory(const char *dir = 0); ~Directory(); + const std::string &name() const { return m_name; } /// go to start of filelist void rewind(); /// gets next dirent info struct in directory and @@ -55,7 +56,11 @@ public: static bool isDirectory(const std::string &filename); /// @return true if a file is a regular file static bool isRegularFile(const std::string &filename); + /// @return true if a file executable for user + static bool isExecutable(const std::string &filename); + private: + std::string m_name; DIR *m_dir; size_t m_num_entries; ///< number of file entries in directory }; -- cgit v0.11.2