From: Christian P. <cp...@us...> - 2004-12-27 07:06:01
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10778/src/System Added Files: FileInfo.common.cpp FileInfo.posix.cpp Log Message: Added P::System::FileInfo class. --- NEW FILE: FileInfo.common.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/FileInfo.h" namespace P { namespace System { FileInfo::FileInfo(const FileInfo& fi) : _path(fi._path), _size(fi._size), _type(fi.type()), _ctime(fi._ctime), _mtime(fi._mtime), _atime(fi._atime) { } FileInfo::FileInfo(const Unicode::String& path) throw(SystemError) : _path(path) { refresh(); } FileInfo::~FileInfo() throw() { } const Unicode::String& FileInfo::path() const throw() { return _path; } FileInfo::fsize_t FileInfo::size() const throw() { return _size; } FileInfo::FileType FileInfo::type() const throw() { return _type; } const DateTime& FileInfo::ctime() const throw() { return _ctime; } const DateTime& FileInfo::mtime() const throw() { return _mtime; } const DateTime& FileInfo::atime() const throw() { return _atime; } FileInfo& FileInfo::operator=(const FileInfo& fi) throw() { _path = fi._path; _size = fi._size; _type = fi._type; _ctime = fi._ctime; _mtime = fi._mtime; _atime = fi._atime; return *this; } } // !namespace System } // !namespace P --- NEW FILE: FileInfo.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/pclasses-config.h" #include "pclasses/System/FileInfo.h" #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <errno.h> namespace P { namespace System { void FileInfo::refresh() throw(SystemError) { struct stat st; if(stat(_path.utf8().c_str(), &st)) throw SystemError(errno, "Could not stat file", P_SOURCEINFO); _size = st.st_size; if(S_ISREG(st.st_mode)) _type = File; else if(S_ISDIR(st.st_mode)) _type = Directory; else if(S_ISCHR(st.st_mode)) _type = CharDevice; else if(S_ISBLK(st.st_mode)) _type = BlockDevice; else if(S_ISFIFO(st.st_mode)) _type = Pipe; #ifdef S_ISSOCK else if(S_ISSOCK(st.st_mode)) _type = Pipe; #endif #ifdef S_ISLNK else if(S_ISLNK(st.st_mode)) _type = Link; #endif else _type = Unknown; _ctime = DateTime(st.st_ctime); _mtime = DateTime(st.st_mtime); _atime = DateTime(st.st_atime); } } // !namespace System } // !namespace P |