X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Futil.cpp;h=224613e7caff236cab5df05f5027a930d664c668;hb=da9f337a893bd317460118f89efa83a3427f797f;hp=e721021b0de6d2105014ea4b05b42188010ab5b7;hpb=8efcd6124e1d02bd6427ded015be603037770883;p=cassiopeia.git diff --git a/src/util.cpp b/src/util.cpp index e721021..224613e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,7 +29,7 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c if( 0 != mkdir( filename.c_str(), 0755 ) ) { if( EEXIST != errno ) { - throw std::runtime_error("Storage location could not be determined"); + throw std::runtime_error( "Storage location could not be determined" ); } //! \FIXME: Check this is a directory @@ -117,7 +117,7 @@ std::pair parseDate( const std::string& date ) { } std::pair addMonths( std::time_t t, int32_t count ) { - std::tm* parsed = gmtime( &t ); + std::tm *parsed = gmtime( &t ); if( !parsed || count <= 0 || count > 24 ) { // FIXED MAX-Validity-Length return std::pair( false, 0 ); @@ -144,7 +144,7 @@ std::pair parseMonthInterval( std::time_t t, const std::string& da try { size_t end = 0; - int num = std::stoi( date.substr( 0, date.size() - 1 ) , &end ); + int num = std::stoi( date.substr( 0, date.size() - 1 ), &end ); if( end != date.size() - 1 ) { return std::pair( false, 0 ); @@ -179,7 +179,7 @@ std::pair parseYearInterval( std::time_t t, const std::string& dat } } -std::unique_ptr openLogfile( const std::string &name ) { +std::unique_ptr openLogfile( const std::string& name ) { struct stat buffer; std::string tname = name; int ctr = 2; @@ -191,16 +191,18 @@ std::unique_ptr openLogfile( const std::string &name ) { auto res = std::make_unique( tname ); if( ! res->good() ) { - throw std::runtime_error( std::string("Failed to open file for logging: " ) + name ); + throw std::runtime_error( std::string( "Failed to open file for logging: " ) + name ); } return res; } -std::string timestamp(){ +std::string timestamp() { time_t c_time; + if( time( &c_time ) == -1 ) { throw std::runtime_error( "Error while fetching time?" ); } + return std::to_string( c_time ); }