aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/Directory.cc15
-rw-r--r--src/FbTk/Directory.hh7
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 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ 22// $Id: Directory.cc,v 1.3 2004/04/19 18:09:15 fluxgen Exp $
23 23
24#include "Directory.hh" 24#include "Directory.hh"
25 25
@@ -60,6 +60,7 @@ std::string Directory::readFilename() {
60void Directory::close() { 60void Directory::close() {
61 if (m_dir != 0) { 61 if (m_dir != 0) {
62 closedir(m_dir); 62 closedir(m_dir);
63 m_name.clear();
63 m_dir = 0; 64 m_dir = 0;
64 m_num_entries = 0; 65 m_num_entries = 0;
65 } 66 }
@@ -77,6 +78,8 @@ bool Directory::open(const char *dir) {
77 if (m_dir == 0) // successfull loading? 78 if (m_dir == 0) // successfull loading?
78 return false; 79 return false;
79 80
81 m_name= dir;
82
80 // get number of entries 83 // get number of entries
81 while (read()) 84 while (read())
82 m_num_entries++; 85 m_num_entries++;
@@ -102,4 +105,14 @@ bool Directory::isRegularFile(const std::string &filename) {
102 return S_ISREG(statbuf.st_mode); 105 return S_ISREG(statbuf.st_mode);
103} 106}
104 107
108bool Directory::isExecutable(const std::string &filename) {
109 struct stat statbuf;
110 if (stat(filename.c_str(), &statbuf) != 0)
111 return false;
112
113 return statbuf.st_mode & S_IXUSR ||
114 statbuf.st_mode & S_IXGRP ||
115 statbuf.st_mode & S_IXOTH;
116}
117
105}; // end namespace FbTk 118}; // 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 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Directory.hh,v 1.3 2003/12/16 17:06:49 fluxgen Exp $ 22// $Id: Directory.hh,v 1.4 2004/04/19 18:09:14 fluxgen Exp $
23 23
24#ifndef FBTK_DIRECTORY_HH 24#ifndef FBTK_DIRECTORY_HH
25#define FBTK_DIRECTORY_HH 25#define FBTK_DIRECTORY_HH
@@ -37,6 +37,7 @@ class Directory: private FbTk::NotCopyable {
37public: 37public:
38 explicit Directory(const char *dir = 0); 38 explicit Directory(const char *dir = 0);
39 ~Directory(); 39 ~Directory();
40 const std::string &name() const { return m_name; }
40 /// go to start of filelist 41 /// go to start of filelist
41 void rewind(); 42 void rewind();
42 /// gets next dirent info struct in directory and 43 /// gets next dirent info struct in directory and
@@ -55,7 +56,11 @@ public:
55 static bool isDirectory(const std::string &filename); 56 static bool isDirectory(const std::string &filename);
56 /// @return true if a file is a regular file 57 /// @return true if a file is a regular file
57 static bool isRegularFile(const std::string &filename); 58 static bool isRegularFile(const std::string &filename);
59 /// @return true if a file executable for user
60 static bool isExecutable(const std::string &filename);
61
58private: 62private:
63 std::string m_name;
59 DIR *m_dir; 64 DIR *m_dir;
60 size_t m_num_entries; ///< number of file entries in directory 65 size_t m_num_entries; ///< number of file entries in directory
61}; 66};