all repos — fluxbox @ 2211428f2d3de7da6e057624e43dc8d13a106a54

custom fork of the fluxbox windowmanager

added isDirectory and isRegularFile
fluxgen fluxgen
commit

2211428f2d3de7da6e057624e43dc8d13a106a54

parent

856ca4330f8afcf866a642999a74892afdf9467e

2 files changed, 25 insertions(+), 3 deletions(-)

jump to
M src/FbTk/Directory.ccsrc/FbTk/Directory.cc

@@ -19,9 +19,12 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.cc,v 1.1 2003/05/18 22:06:59 fluxgen Exp $ +// $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ #include "Directory.hh" + +#include <sys/stat.h> +#include <unistd.h> namespace FbTk {

@@ -81,6 +84,22 @@

rewind(); // go back to start return true; +} + +bool Directory::isDirectory(const std::string &filename) { + struct stat statbuf; + if (stat(filename.c_str(), &statbuf) != 0) + return false; + + return S_ISDIR(statbuf.st_mode); +} + +bool Directory::isRegularFile(const std::string &filename) { + struct stat statbuf; + if (stat(filename.c_str(), &statbuf) != 0) + return false; + + return S_ISREG(statbuf.st_mode); } }; // end namespace FbTk
M src/FbTk/Directory.hhsrc/FbTk/Directory.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.hh,v 1.1 2003/05/18 22:06:59 fluxgen Exp $ +// $Id: Directory.hh,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ #ifndef FBTK_DIRECTORY_HH #define FBTK_DIRECTORY_HH

@@ -51,7 +51,10 @@ /// @param dir the directory name

bool open(const char *dir); /// @return number of entries in the directory size_t entries() const { return m_num_entries; } - + /// @return true if file is a directory + static bool isDirectory(const std::string &filename); + /// @return true if a file is a regular file + static bool isRegularFile(const std::string &filename); private: DIR *m_dir; size_t m_num_entries; ///< number of file entries in directory