news download themes documentation links










Directory.cc

00001 // Directory.cc
00002 // Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 // DEALINGS IN THE SOFTWARE.
00021 
00022 // $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $
00023 
00024 #include "Directory.hh"
00025 
00026 #include <sys/stat.h>
00027 #include <unistd.h>
00028 
00029 namespace FbTk {
00030 
00031 Directory::Directory(const char *dir):m_dir(0),
00032 m_num_entries(0) {
00033     if (dir != 0)
00034         open(dir);
00035 }
00036 
00037 Directory::~Directory() {
00038     close();
00039 }
00040 
00041 void Directory::rewind() {
00042     if (m_dir != 0)
00043         rewinddir(m_dir);
00044 }
00045 
00046 struct dirent *Directory::read() {
00047     if (m_dir == 0)
00048         return 0;
00049 
00050     return readdir(m_dir);
00051 }
00052 
00053 std::string Directory::readFilename() {
00054     dirent *ent = read();
00055     if (ent == 0)
00056         return "";
00057     return (ent->d_name ? ent->d_name : "");
00058 }
00059 
00060 void Directory::close() {
00061     if (m_dir != 0) { 
00062         closedir(m_dir);
00063         m_dir = 0;
00064         m_num_entries = 0;
00065     }
00066 }
00067 
00068 
00069 bool Directory::open(const char *dir) {
00070     if (dir == 0)
00071         return false;
00072 
00073     if (m_dir != 0)
00074         close();
00075 
00076     m_dir = opendir(dir);
00077     if (m_dir == 0) // successfull loading?
00078         return false;
00079 
00080     // get number of entries
00081     while (read())
00082         m_num_entries++;
00083 
00084     rewind(); // go back to start
00085 
00086     return true;
00087 }
00088 
00089 bool Directory::isDirectory(const std::string &filename) {
00090     struct stat statbuf;
00091     if (stat(filename.c_str(), &statbuf) != 0)
00092         return false;
00093 
00094     return S_ISDIR(statbuf.st_mode);
00095 }
00096 
00097 bool Directory::isRegularFile(const std::string &filename) {
00098     struct stat statbuf;
00099     if (stat(filename.c_str(), &statbuf) != 0)
00100         return false;
00101 
00102     return S_ISREG(statbuf.st_mode);
00103 }
00104 
00105 }; // end namespace FbTk

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA