src/revsys.cc
/** Open a file for reading.

    This function throws an exception if there is any error otherwise
    it returns ios_base::binary if the file seems to be a binary file
    and zero if it looks like a text file (analyzing first 16 bytes).
*/
Open a file for reading.
This function throws an exception if there is any error otherwise
it returns ios_base::binary if the file seems to be a binary file
and zero if it looks like a text file (analyzing first 16 bytes).
Open a file for reading . This function throws an exception if there is any error otherwise it returns ios_base :: binary if the file seems to be a binary file and zero if it looks like a text file ( analyzing first 16 bytes ) .
std::streambuf* filesys::openfile( const boost::filesystem::path& pathname,
    const std::string& commit ) {
    using namespace boost::system::errc;
    using namespace boost::filesystem;
    using namespace boost::iostreams;
#if 0
    check(pathname);
#endif
    ifstream strm;
    strm.open(pathname);
    if( strm.fail() ) {
        boost::throw_exception(boost::system::system_error(
                make_error_code(no_such_file_or_directory),pathname.string()));
    }
    char firstBytes[16+1];
    int bytesRead = strm.readsome(firstBytes,16);
    strm.seekg(0,std::ios_base::beg);
    firstBytes[16] = '\0';
    for( int i = 0; i < bytesRead; ++i ) {
        if( !(isprint(firstBytes[i]) | isspace(firstBytes[i])) ) {
            return NULL;
        }
    }
    std::streambuf *buf
        = new stream_buffer<file_descriptor_source>(pathname,
            std::ios_base::in|std::ios_base::binary);
    return buf;
}
std :: streambuf * filesys :: openfile ( const boost :: filesystem :: path & pathname , const std :: string & commit ) { using namespace boost :: system :: errc ; using namespace boost :: filesystem ; using namespace boost :: iostreams ; #if 0 check ( pathname ) ; #endif ifstream strm ; strm . open ( pathname ) ; if ( strm . fail ( ) ) { boost :: throw_exception ( boost :: system :: system_error ( make_error_code ( no_such_file_or_directory ) , pathname . string ( ) ) ) ; } char firstBytes [ 16 + 1 ] ; int bytesRead = strm . readsome ( firstBytes , 16 ) ; strm . seekg ( 0 , std :: ios_base :: beg ) ; firstBytes [ 16 ] = ' \0 ' ; for ( int i = 0 ; i < bytesRead ; ++ i ) { if ( ! ( isprint ( firstBytes [ i ] ) | isspace ( firstBytes [ i ] ) ) ) { return NULL ; } } std :: streambuf * buf = new stream_buffer < file_descriptor_source > ( pathname , std :: ios_base :: in | std :: ios_base :: binary ) ; return buf ; }
Open a file for reading.
Open a file for reading .
/* \todo figure out how to pass iostream error code in exception. */ /* '\n' is not a printable character according to the C standard. */