errno = 0;
std::string filename = keydir;
+
if( 0 != mkdir( filename.c_str(), 0755 ) ) {
if( EEXIST != errno ) {
return "";
}
filename += "/crt";
+
if( 0 != mkdir( filename.c_str(), 0755 ) ) {
if( EEXIST != errno ) {
return "";
//! \FIXME: Check this is a directory
}
+
std::string first;
if( serial.length() < 3 ) {
}
filename += "/" + first;
+
if( 0 != mkdir( filename.c_str(), 0755 ) ) {
if( EEXIST != errno ) {
return "";
return std::pair<bool, time_t>( false, 0 );
}
}
+
+std::shared_ptr<std::ofstream> openLogfile( const std::string name) {
+ struct stat buffer;
+ std::string tname = name;
+ int ctr = 2;
+ while(stat (tname.c_str(), &buffer) == 0) {
+ tname = name + "_" + std::to_string(ctr++);
+ }
+ auto res = std::shared_ptr<std::ofstream>(new std::ofstream( tname ),
+ [](std::ofstream *p){
+ p->close();
+ delete p;
+ });
+ if(! res->good() ){
+ throw std::string("Failed to open file for logging: ") + name;
+ }
+ return res;
+}