for consistent behavior we must not close the file pointer when it was passed as argument

This commit is contained in:
Axel Kohlmeyer
2021-04-26 12:12:19 -04:00
parent 8af1530e29
commit dbd7d454b9
2 changed files with 4 additions and 3 deletions

View File

@ -41,7 +41,7 @@ using namespace LAMMPS_NS;
* \param filetype Description of file type for error messages */
TextFileReader::TextFileReader(const std::string &filename, const std::string &filetype)
: filetype(filetype), ignore_comments(true)
: filetype(filetype), closefp(true), ignore_comments(true)
{
fp = fopen(filename.c_str(), "r");
@ -58,7 +58,7 @@ TextFileReader::TextFileReader(const std::string &filename, const std::string &f
* \param filetype Description of file type for error messages */
TextFileReader::TextFileReader(FILE *fp, const std::string &filetype)
: filetype(filetype), fp(fp), ignore_comments(true)
: filetype(filetype), closefp(false), fp(fp), ignore_comments(true)
{
if (fp == nullptr) throw FileReaderException("Invalid file descriptor");
}
@ -66,7 +66,7 @@ TextFileReader::TextFileReader(FILE *fp, const std::string &filetype)
/** Closes the file */
TextFileReader::~TextFileReader() {
fclose(fp);
if (closefp) fclose(fp);
}
/** Read the next line and ignore it */