Update of /cvsroot/pclasses/pclasses2/src/System
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3199/src/System
Added Files:
Directory.posix.cpp
Log Message:
Added Directory class (untested)
--- NEW FILE: Directory.posix.cpp ---
/***************************************************************************
* Copyright (C) 2004 by Christian Prochnow *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pclasses/System/Directory.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
namespace P {
namespace System {
Directory::Directory(const Unicode::String& path) throw(IO::IOError)
: _path(path)
{
/*@fixme DIR* d = opendir(_path.utf8());
if(!d)
throw IOError(errno, "Could not open directory", P_SOURCEINFO);
_handle = (unsigned long)d;*/
}
Directory::Directory(const std::string& path) throw(IO::IOError)
: _path(path.c_str())
{
DIR* d = opendir(path.c_str());
if(!d)
throw IO::IOError(errno, "Could not open directory", P_SOURCEINFO);
_handle = (unsigned long)d;
}
Directory::~Directory() throw()
{
closedir((DIR*)_handle);
}
const Unicode::String& Directory::path() const throw()
{
return _path;
}
void Directory::reload() throw(IO::IOError)
{
_entries.clear();
rewinddir((DIR*)_handle);
struct dirent* de;
while((de = readdir((DIR*)_handle)))
_entries.append(Unicode::String(de->d_name));
}
Directory::Iterator Directory::begin() const
{
return _entries.begin();
}
Directory::Iterator Directory::end() const
{
return _entries.end();
}
Unicode::String Directory::current() throw(IO::IOError)
{
char cwd[PATH_MAX];
if(!getcwd(cwd, PATH_MAX))
throw IO::IOError(errno, "Could not get current working directroy", P_SOURCEINFO);
return Unicode::String(cwd);
}
void Directory::change(const Unicode::String& path) throw(IO::IOError)
{
/*@fixme if(chdir(path.utf8()) == -1)
throw IO::IOError(errno, "Could not change working directory", P_SOURCEINFO);*/
}
void Directory::create(const Unicode::String& path) throw(IO::IOError)
{
/*@fixme if(mkdir(path.utf8(), 0777) == -1)
throw IO::IOError(errno, "Could not change working directory", P_SOURCEINFO); */
}
void Directory::remove(const Unicode::String& path) throw(IO::IOError)
{
/*@fixme if(rmdir(path.utf8()) == -1)
throw IO::IOError(errno, "Could not remove directory", P_SOURCEINFO); */
}
} // !namespace System
} // !namespace P
|