filepath.cpp

Go to the documentation of this file.
00001 
00002 #include "zipios-config.h"
00003 
00004 #include <stdexcept>
00005 #include <string>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 
00009 #include "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 #if defined (__GNUC__)
00038   struct stat buf ;
00039   if ( stat( _path.c_str(), &buf ) != -1 ) {
00040 #else
00041   struct _stat buf ;
00042   if ( _stat( _path.c_str(), &buf ) != -1 ) {
00043 #endif
00044     _exists    = true ;
00045 #if defined(BOOST_WINNT)
00046     _is_reg    = _S_IFREG & buf.st_mode ;
00047     _is_dir    = _S_IFDIR & buf.st_mode ;
00048     _is_char   = _S_IFCHR & buf.st_mode ;
00049 #else
00050     _is_reg    = S_ISREG ( buf.st_mode ) ;
00051     _is_dir    = S_ISDIR ( buf.st_mode ) ;
00052     _is_char   = S_ISCHR ( buf.st_mode ) ;
00053     _is_block  = S_ISBLK ( buf.st_mode ) ;
00054     _is_socket = S_ISSOCK( buf.st_mode ) ;
00055     _is_fifo   = S_ISFIFO( buf.st_mode ) ;
00056 #endif
00057   } 
00058 }
00059 
00060 } // namespace
00061 
00066 /*
00067   Zipios++ - a small C++ library that provides easy access to .zip files.
00068   Copyright (C) 2000  Thomas Søndergaard
00069   
00070   This library is free software; you can redistribute it and/or
00071   modify it under the terms of the GNU Lesser General Public
00072   License as published by the Free Software Foundation; either
00073   version 2 of the License, or (at your option) any later version.
00074   
00075   This library is distributed in the hope that it will be useful,
00076   but WITHOUT ANY WARRANTY; without even the implied warranty of
00077   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00078   Lesser General Public License for more details.
00079   
00080   You should have received a copy of the GNU Lesser General Public
00081   License along with this library; if not, write to the Free Software
00082   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00083 */

Generated on Wed Nov 23 19:00:14 2011 for FreeCAD by  doxygen 1.6.1