for consistent behavior we must not close the file pointer when it was passed as argument
This commit is contained in:
@ -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 */
|
||||
|
||||
@ -26,6 +26,7 @@ namespace LAMMPS_NS
|
||||
{
|
||||
class TextFileReader {
|
||||
std::string filetype;
|
||||
bool closefp;
|
||||
static constexpr int MAXLINE = 1024;
|
||||
char line[MAXLINE];
|
||||
FILE *fp;
|
||||
|
||||
Reference in New Issue
Block a user