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 */
|
* \param filetype Description of file type for error messages */
|
||||||
|
|
||||||
TextFileReader::TextFileReader(const std::string &filename, const std::string &filetype)
|
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");
|
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 */
|
* \param filetype Description of file type for error messages */
|
||||||
|
|
||||||
TextFileReader::TextFileReader(FILE *fp, const std::string &filetype)
|
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");
|
if (fp == nullptr) throw FileReaderException("Invalid file descriptor");
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ TextFileReader::TextFileReader(FILE *fp, const std::string &filetype)
|
|||||||
/** Closes the file */
|
/** Closes the file */
|
||||||
|
|
||||||
TextFileReader::~TextFileReader() {
|
TextFileReader::~TextFileReader() {
|
||||||
fclose(fp);
|
if (closefp) fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read the next line and ignore it */
|
/** Read the next line and ignore it */
|
||||||
|
|||||||
@ -26,6 +26,7 @@ namespace LAMMPS_NS
|
|||||||
{
|
{
|
||||||
class TextFileReader {
|
class TextFileReader {
|
||||||
std::string filetype;
|
std::string filetype;
|
||||||
|
bool closefp;
|
||||||
static constexpr int MAXLINE = 1024;
|
static constexpr int MAXLINE = 1024;
|
||||||
char line[MAXLINE];
|
char line[MAXLINE];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|||||||
Reference in New Issue
Block a user