added Chmod for files

pull/40/head
Matchman Green 2012-05-24 18:56:48 +08:00
parent 428afa6538
commit a49794897a
4 changed files with 34 additions and 5 deletions

View File

@ -56,10 +56,6 @@ Json Config::Read( const std::string& filename )
}
catch ( Exception& e )
{
// throw Error()
// << File( filename )
// << expt::ErrMsg("Cannot open config file ")
// << expt::Nested(e) ;
return Json() ;
}
}

View File

@ -73,7 +73,12 @@ void SetFileTime( const std::string& filename, const DateTime& t )
{
struct timeval tvp[2] = { t.Tv(), t.Tv() } ;
if ( ::utimes( filename.c_str(), tvp ) != 0 )
throw expt::ErrMsg( "cannot set file time" ) ;
BOOST_THROW_EXCEPTION(
Error()
<< boost::errinfo_api_function("utimes")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(filename)
) ;
}
} } // end of namespaces

View File

@ -30,6 +30,8 @@
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/info.hpp>
#include <sys/stat.h>
namespace gr {
StdioFile::StdioFile( const std::string& filename, const char *mode ) : m_file( 0 )
@ -110,4 +112,28 @@ long StdioFile::Tell() const
return std::ftell( m_file ) ;
}
void StdioFile::Chmod( int mode )
{
assert( m_file != 0 ) ;
int fd = ::fileno(m_file) ;
if ( fd == -1 )
{
BOOST_THROW_EXCEPTION(
Error()
<< boost::errinfo_api_function("fileno")
<< boost::errinfo_errno(errno)
) ;
}
if ( ::fchmod( fd, mode ) != 0 )
{
BOOST_THROW_EXCEPTION(
Error()
<< boost::errinfo_api_function("fchmod")
<< boost::errinfo_errno(errno)
) ;
}
}
} // end of namespace

View File

@ -48,6 +48,8 @@ public :
int Seek( long offset, int whence ) ;
long Tell() const ;
void Chmod( int mode ) ;
private :
std::FILE *m_file ;
} ;