Refactoring how the binary output is closed
This change implements the fix suggested by @gonccalo.
This commit is contained in:
@@ -819,13 +819,7 @@ int DLLEXPORT EN_closeQ(EN_Project p)
|
|||||||
if (!p->Openflag) return 102;
|
if (!p->Openflag) return 102;
|
||||||
closequal(p);
|
closequal(p);
|
||||||
p->quality.OpenQflag = FALSE;
|
p->quality.OpenQflag = FALSE;
|
||||||
|
closeoutfile(p);
|
||||||
if (p->outfile.OutFile != NULL)
|
|
||||||
{
|
|
||||||
fclose(p->outfile.OutFile);
|
|
||||||
p->outfile.OutFile = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ void freedata(Project *);
|
|||||||
int openfiles(Project *, const char *, const char *,const char *);
|
int openfiles(Project *, const char *, const char *,const char *);
|
||||||
int openhydfile(Project *);
|
int openhydfile(Project *);
|
||||||
int openoutfile(Project *);
|
int openoutfile(Project *);
|
||||||
|
void closeoutfile(Project *);
|
||||||
|
|
||||||
int buildadjlists(Network *);
|
int buildadjlists(Network *);
|
||||||
void freeadjlists(Network *);
|
void freeadjlists(Network *);
|
||||||
|
|||||||
@@ -173,18 +173,8 @@ int openoutfile(Project *pr)
|
|||||||
int errcode = 0;
|
int errcode = 0;
|
||||||
|
|
||||||
// Close output file if already opened
|
// Close output file if already opened
|
||||||
if (pr->outfile.TmpOutFile != pr->outfile.OutFile &&
|
closeoutfile(pr);
|
||||||
pr->outfile.TmpOutFile != NULL)
|
|
||||||
{
|
|
||||||
fclose(pr->outfile.TmpOutFile);
|
|
||||||
pr->outfile.TmpOutFile = NULL;
|
|
||||||
}
|
|
||||||
if (pr->outfile.OutFile != NULL)
|
|
||||||
{
|
|
||||||
fclose(pr->outfile.OutFile);
|
|
||||||
pr->outfile.OutFile = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If output file name was supplied, then attempt to
|
// If output file name was supplied, then attempt to
|
||||||
// open it. Otherwise open a temporary output file.
|
// open it. Otherwise open a temporary output file.
|
||||||
pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b");
|
pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b");
|
||||||
@@ -209,6 +199,33 @@ int openoutfile(Project *pr)
|
|||||||
return errcode;
|
return errcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void closeoutfile(Project *pr)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: none
|
||||||
|
** Output: none
|
||||||
|
** Purpose: closes binary output file.
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
if (pr->outfile.TmpOutFile != pr->outfile.OutFile)
|
||||||
|
{
|
||||||
|
if (pr->outfile.TmpOutFile != NULL)
|
||||||
|
{
|
||||||
|
fclose(pr->outfile.TmpOutFile);
|
||||||
|
pr->outfile.TmpOutFile = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pr->outfile.OutFile != NULL)
|
||||||
|
{
|
||||||
|
if (pr->outfile.OutFile == pr->outfile.TmpOutFile)
|
||||||
|
{
|
||||||
|
pr->outfile.TmpOutFile = NULL;
|
||||||
|
}
|
||||||
|
fclose(pr->outfile.OutFile);
|
||||||
|
pr->outfile.OutFile = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void initpointers(Project *pr)
|
void initpointers(Project *pr)
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
** Input: none
|
** Input: none
|
||||||
|
|||||||
Reference in New Issue
Block a user