#include <iostream>
#include <time.h>
#include <dirent.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
void configcache::openOutFile(int actnequi)
{
time_t secstamp = time(NULL);
+ int iseq=0;
+
+ while (true) {
+ outFileName.str("");
+ outFileName << DATADIR << "/" << secstamp << "." << iseq << "_" << getFileId(actnequi) << "_.edat.tmp";
+
+ int tmpfd = open(outFileName.str().c_str(), O_CREAT | O_EXCL, 0644);
- outFileName.str("");
- outFileName << DATADIR << "/" << secstamp << "_" << getFileId(actnequi) << "_.edat.tmp";
+ if ( tmpfd != -1 ) {
+ close(tmpfd);
+ break;
+ }
+ else if ( errno != EEXIST ) {
+ if(log) *log << "CCACHE: Could not create cachefile!" << endl << flush;
+ exit(1);
+ }
+ iseq++;
+ }
+
outFile.open( outFileName.str().c_str(), std::ios::binary );
ioBuffers->out = new boost::iostreams::filtering_ostreambuf;