use platform code for reading/writing of compressed text file via a pipe
This commit is contained in:
@ -32,33 +32,20 @@ Reader::Reader(LAMMPS *lmp) : Pointers(lmp)
|
||||
generic version for ASCII files that may be compressed
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Reader::open_file(const char *file)
|
||||
void Reader::open_file(const std::string &file)
|
||||
{
|
||||
if (fp != nullptr) close_file();
|
||||
|
||||
if (utils::strmatch(file,"\\.gz$")) {
|
||||
if (platform::has_zip_extension(file)) {
|
||||
compressed = 1;
|
||||
|
||||
#ifdef LAMMPS_GZIP
|
||||
auto gunzip = fmt::format("gzip -c -d {}",file);
|
||||
|
||||
#ifdef _WIN32
|
||||
fp = _popen(gunzip.c_str(),"rb");
|
||||
#else
|
||||
fp = popen(gunzip.c_str(),"r");
|
||||
#endif
|
||||
|
||||
#else
|
||||
error->one(FLERR,"Cannot open gzipped file without gzip support");
|
||||
#endif
|
||||
fp = platform::zip_read(file);
|
||||
if (!fp) error->one(FLERR,"Cannot open compressed file for reading");
|
||||
} else {
|
||||
compressed = 0;
|
||||
fp = fopen(file,"r");
|
||||
fp = fopen(file.c_str(),"r");
|
||||
}
|
||||
|
||||
if (fp == nullptr)
|
||||
error->one(FLERR,"Cannot open file {}: {}",
|
||||
file, utils::getsyserror());
|
||||
if (!fp) error->one(FLERR,"Cannot open file {}: {}", file, utils::getsyserror());
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -69,7 +56,7 @@ void Reader::open_file(const char *file)
|
||||
void Reader::close_file()
|
||||
{
|
||||
if (fp == nullptr) return;
|
||||
if (compressed) pclose(fp);
|
||||
if (compressed) platform::pclose(fp);
|
||||
else fclose(fp);
|
||||
fp = nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user