void putFile(const char* filename,const char* nameInArchive) { char buff[BUFSIZ]; std::FILE* in=std::fopen(filename,"rb"); if(in==NULL) { std::stringstream err; err << "Cannot open " << filename << " "<< std::strerror(errno); throw std::runtime_error(err.str()); } std::fseek(in, 0L, SEEK_END); long int len= std::ftell(in); std::fseek(in,0L,SEEK_SET); PosixTarHeader header; _init((void*)&header); _filename((void*)&header,nameInArchive); header.typeflag[0]=0; _size((void*)&header,len); _checksum((void*)&header); out.write((const char*)&header,sizeof(PosixTarHeader)); std::size_t nRead=0; while((nRead=std::fread(buff,sizeof(char),BUFSIZ,in))>0) { out.write(buff,nRead); } std::fclose(in); _endRecord(len); }
void put(const char* filename,const char* content,std::size_t len) { PosixTarHeader header; _init((void*)&header); _filename((void*)&header,filename); header.typeflag[0]=0; _size((void*)&header,len); _checksum((void*)&header); out.write((const char*)&header,sizeof(PosixTarHeader)); out.write(content,len); _endRecord(len); }
void MT_ExperimentDataFile::registerFile( const char* label, const char* filename) { std::string _label(label); std::string _filename(filename); /* the label can't have any spaces */ _label = MT_ReplaceSpacesInString(_label); /* store the filename as relative to the XDF */ std::string rel_filename = MT_CalculateRelativePath(filename, m_XMLFile.GetFilename()); MT_AddOrReplaceNodeValue(getFilesNode(), _label.c_str(), rel_filename.c_str()); }
helper::io::Image* VoxelGridLoader::loadImage ( const std::string& filename, const Vec3i& res, const int hsize ) const { helper::io::Image* image = NULL; std::string _filename ( filename ); if(res.norm2() > 0 && bpp > 0) { if ( _filename.length() > 4 && _filename.compare ( _filename.length()-4, 4, ".raw" ) ==0 ) { helper::io::Image::ChannelFormat channels; switch (bpp) { case 8: channels = helper::io::Image::L; break; case 16: channels = helper::io::Image::LA; break; case 24: channels = helper::io::Image::RGB; break; case 32: channels = helper::io::Image::RGBA; break; default: serr << "Unknown bitdepth: " << bpp << sendl; return 0; } helper::io::ImageRAW *imageRAW = new helper::io::ImageRAW(); imageRAW->init(res[0], res[1], res[2], 1, helper::io::Image::UNORM8, channels); imageRAW->initHeader(hsize); if(imageRAW->load( _filename )) image = imageRAW; } } if(image == NULL) { this->serr << "Unable to load file " << _filename << sendl; } return image; }
/* * ucmCreateCabinetForSingleFile * * Purpose: * * Build cabinet for usage in methods where required 1 file. * */ BOOL ucmCreateCabinetForSingleFile( LPWSTR lpSourceDll, PVOID ProxyDll, DWORD ProxyDllSize ) { BOOL cond = FALSE, bResult = FALSE; CABDATA *Cabinet = NULL; LPWSTR lpFileName; WCHAR szMsuFileName[MAX_PATH * 2]; if ((ProxyDll == NULL) || (ProxyDllSize == 0)) { return FALSE; } do { //drop proxy dll if (!supWriteBufferToFile(lpSourceDll, ProxyDll, ProxyDllSize)) { break; } //build cabinet RtlSecureZeroMemory(szMsuFileName, sizeof(szMsuFileName)); _strcpy(szMsuFileName, g_ctx.szTempDirectory); _strcat(szMsuFileName, ELLOCNAK_MSU); Cabinet = cabCreate(szMsuFileName); if (Cabinet == NULL) break; lpFileName = _filename(lpSourceDll); //put file without compression bResult = cabAddFile(Cabinet, lpSourceDll, lpFileName); cabClose(Cabinet); } while (cond); return bResult; }
static char *_dirty_idx_filename(uint64_t log_number) { return _filename(log_number, "idx.dirty"); }
static char *idx_filename(uint64_t log_number) { return _filename(log_number, "idx"); }
char *log_filename(uint64_t log_number) { return _filename(log_number, "ydb"); }
bool MT_ExperimentDataFile::addDataStream(const char* label, const char* filename, bool force_overwrite) { if(m_bStatus == MT_XDF_ERROR) { return setError(); } /* if this is already one of our streams, return true * without doing anything */ if(findStreamIndexByLabel(label) != MT_XDF_STREAM_INDEX_ERROR) { return setOK(); } /* if filename == NULL, use filename = label */ std::string _filename(filename); if(!filename) { _filename = label; } std::string dir = dir_from_xdf(m_XMLFile.GetFilename()); _filename = dir + _filename; MT_mkdir(dir.c_str()); /* check to see if filename exists (for reading) */ bool exists = MT_FileIsAvailable(_filename.c_str(), "r"); /* if it does and force_overwrite is false, then * return false. if force_overwrite is true, then * overwrite the file. */ if(exists) { if(force_overwrite == MT_XDF_NO_OVERWRITE) { fprintf(stderr, "File %s already exists. If you are sure you want " "to overwrite it, try addDataStream(label, filename, MT_XDF_OVERWRITE).\n", _filename.c_str()); return setError(); } } /* make sure we can write to the file (this will erase the file if it's there!) */ FILE* fp = fopen(_filename.c_str(), "w"); if(!fp) { fprintf(stderr, "Error: Can't write to file %s. Unable to " "add to experiment data stream.\n", _filename.c_str()); return setOK(); } /* register the file in the XML master */ registerFile(label, _filename.c_str()); /* save the file */ m_XMLFile.SaveFile(); /* set up the various registers */ m_vpDataFiles.push_back(fp); m_vFileNames.push_back(_filename); m_vNames.push_back(label); m_vWroteThisTimeStep.push_back(false); m_viCheckedOut.push_back(0); /* if everything goes well, return true */ return setOK(); }
// Subscriber function. void remote_fo (i_transport *transport_, size_t msg_size_, int msg_count_, const char *subs_id_) { // Send sync message that we are ready to receive test messages. transport_->send (1); time_instant_t start_time = 0; for (int msg_nbr = 0; msg_nbr < msg_count_; msg_nbr++) { size_t size = transport_->receive (); // Capture test start timestamp. if (msg_nbr == 0) start_time = now(); // Check incomming message size. assert (size == msg_size_); } // Capture test end timestamp. time_instant_t stop_time = now(); // Calculate results. // Test time in [ms] with [ms] resolution, do not use for math!!! uint64_t test_time = (uint64_t) (stop_time - start_time) / (uint64_t) 1000000; // Throughput [msgs/s]. uint64_t msg_thput = ((uint64_t) 1000000000 * (uint64_t) msg_count_) / (uint64_t)(stop_time - start_time); // Throughput [Mb/s]. uint64_t tcp_thput = (msg_thput * msg_size_ * 8) / (uint64_t) 1000000; // Save the results into tests.dat file. std::cout << subs_id_ << ": Your average throughput is " << msg_thput << " [msg/s]\n"; std::cout << subs_id_ << "Your average throughput is " << tcp_thput << " [Mb/s]\n\n"; // Save the results into ${subs_id}_tests.dat file. std::string _filename (subs_id_); _filename += "_tests.dat"; std::ofstream outf (_filename.c_str (), std::ios::out | std::ios::app); assert (outf.is_open ()); // Output file format, separate line for each run is appended // to the ${subs_id}_tests.dat file // // 1, message count, msg size [B], test time [ms], // throughput [msg/s],throughput [Mb/s] // outf << "1," << msg_count_ << "," << msg_size_ << "," << test_time << "," << msg_thput << "," << tcp_thput << std::endl; outf.close (); // Send sync message. transport_->send (1); // All subscribers finished, now we can shutdown. size_t size = transport_->receive (); assert (size == 1); }