Zipios++

filepath.cpp

Go to the documentation of this file.
00001 
00002 #include "zipios++/zipios-config.h"
00003 
00004 #include <stdexcept>
00005 #include <string>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 
00009 #include "zipios++/filepath.h"
00010 
00011 namespace zipios {
00012 
00013 using namespace std ;
00014 
00015 const char FilePath::_separator = '/' ;
00016 
00017 
00018 FilePath::FilePath( const string &path, bool check_exists )
00019   : _checked( false ),
00020     _path( path ) {
00021   pruneTrailingSeparator() ;
00022   if ( check_exists ) 
00023     exists() ;
00024 }
00025 
00026 
00027 void FilePath::check() const {
00028   _checked     = true  ;  
00029   _exists      = false ;
00030   _is_reg      = false ;
00031   _is_dir      = false ;
00032   _is_char     = false ; 
00033   _is_block    = false ;
00034   _is_socket   = false ;
00035   _is_fifo     = false ;
00036   
00037   struct stat buf ;
00038   if ( stat( _path.c_str(), &buf ) != -1 ) {
00039     _exists    = true ;
00040     #if defined(BOOST_WINNT)
00041     _is_reg    = _S_IFREG & buf.st_mode ;
00042     _is_dir    = _S_IFDIR & buf.st_mode ;
00043     _is_char   = _S_IFCHR & buf.st_mode ;
00044     #else
00045     _is_reg    = S_ISREG ( buf.st_mode ) ;
00046     _is_dir    = S_ISDIR ( buf.st_mode ) ;
00047     _is_char   = S_ISCHR ( buf.st_mode ) ;
00048     _is_block  = S_ISBLK ( buf.st_mode ) ;
00049     _is_socket = S_ISSOCK( buf.st_mode ) ;
00050     _is_fifo   = S_ISFIFO( buf.st_mode ) ;
00051     #endif
00052   } 
00053 }
00054 
00055 } // namespace
00056 
00061 /*
00062   Zipios++ - a small C++ library that provides easy access to .zip files.
00063   Copyright (C) 2000  Thomas Søndergaard
00064   
00065   This library is free software; you can redistribute it and/or
00066   modify it under the terms of the GNU Lesser General Public
00067   License as published by the Free Software Foundation; either
00068   version 2 of the License, or (at your option) any later version.
00069   
00070   This library is distributed in the hope that it will be useful,
00071   but WITHOUT ANY WARRANTY; without even the implied warranty of
00072   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00073   Lesser General Public License for more details.
00074   
00075   You should have received a copy of the GNU Lesser General Public
00076   License along with this library; if not, write to the Free Software
00077   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00078 */