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 _is_reg = S_ISREG ( buf.st_mode ) ;
00041 _is_dir = S_ISDIR ( buf.st_mode ) ;
00042 _is_char = S_ISCHR ( buf.st_mode ) ;
00043 _is_block = S_ISBLK ( buf.st_mode ) ;
00044 _is_socket = S_ISSOCK( buf.st_mode ) ;
00045 _is_fifo = S_ISFIFO( buf.st_mode ) ;
00046 }
00047 }
00048
00049 }
00050
00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072