summaryrefslogtreecommitdiff
path: root/src/FbTk/Directory.cc
diff options
context:
space:
mode:
authormathias <mathias>2004-12-18 01:29:22 (GMT)
committermathias <mathias>2004-12-18 01:29:22 (GMT)
commitb3fa5c242881b55a76c0e25b3cebaf15d0744f69 (patch)
treebcdb8e0df23428f3f3107e27e6af008d6a0409cc /src/FbTk/Directory.cc
parent6458b1b485c7481da6d2d1bf235b44fe3b700bd3 (diff)
downloadfluxbox_lack-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.zip
fluxbox_lack-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.tar.bz2
* moved FbTk/Directory.cc/hh over to FbTk/FileUtil.cc/hh which contain now
file and directory - helproutines. * created the FileUtil-namespace which contains file-related functions, moved those functions out of Directory - code * changes to the rest of the files to follow those changes
Diffstat (limited to 'src/FbTk/Directory.cc')
-rw-r--r--src/FbTk/Directory.cc118
1 files changed, 0 insertions, 118 deletions
diff --git a/src/FbTk/Directory.cc b/src/FbTk/Directory.cc
deleted file mode 100644
index 0535dc0..0000000
--- a/src/FbTk/Directory.cc
+++ /dev/null
@@ -1,118 +0,0 @@
1// Directory.cc
2// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id$
23
24#include "Directory.hh"
25
26#include <sys/stat.h>
27#include <unistd.h>
28
29namespace FbTk {
30
31Directory::Directory(const char *dir):m_dir(0),
32m_num_entries(0) {
33 if (dir != 0)
34 open(dir);
35}
36
37Directory::~Directory() {
38 close();
39}
40
41void Directory::rewind() {
42 if (m_dir != 0)
43 rewinddir(m_dir);
44}
45
46struct dirent *Directory::read() {
47 if (m_dir == 0)
48 return 0;
49
50 return readdir(m_dir);
51}
52
53std::string Directory::readFilename() {
54 dirent *ent = read();
55 if (ent == 0)
56 return "";
57 return (ent->d_name ? ent->d_name : "");
58}
59
60void Directory::close() {
61 if (m_dir != 0) {
62 closedir(m_dir);
63 m_name = "";
64 m_dir = 0;
65 m_num_entries = 0;
66 }
67}
68
69
70bool Directory::open(const char *dir) {
71 if (dir == 0)
72 return false;
73
74 if (m_dir != 0)
75 close();
76
77 m_dir = opendir(dir);
78 if (m_dir == 0) // successfull loading?
79 return false;
80
81 m_name= dir;
82
83 // get number of entries
84 while (read())
85 m_num_entries++;
86
87 rewind(); // go back to start
88
89 return true;
90}
91
92bool Directory::isDirectory(const std::string &filename) {
93 struct stat statbuf;
94 if (stat(filename.c_str(), &statbuf) != 0)
95 return false;
96
97 return S_ISDIR(statbuf.st_mode);
98}
99
100bool Directory::isRegularFile(const std::string &filename) {
101 struct stat statbuf;
102 if (stat(filename.c_str(), &statbuf) != 0)
103 return false;
104
105 return S_ISREG(statbuf.st_mode);
106}
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
118}; // end namespace FbTk