From f80a8832b0d235e6c4e83a023d9d5a4085364f99 Mon Sep 17 00:00:00 2001 From: borutr Date: Mon, 10 Mar 2003 20:07:28 +0000 Subject: [PATCH] added set pipeSet, added function closePipes, which closes all pipes in pipeSet set git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2365 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCglue.c | 42 ++++++++++++++++++++++++++++++++++-------- src/SDCCglue.h | 1 + 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 13b5a8dd..dcca79fe 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -46,9 +46,26 @@ unsigned maxInterrupts = 6; int allocInfo = 1; symbol *mainf; extern char *VersionString; +set *pipeSet = NULL; /* set of pipes */ set *tmpfileSet = NULL; /* set of tmp file created by the compiler */ set *tmpfileNameSet = NULL; /* All are unlinked at close. */ +/*-----------------------------------------------------------------*/ +/* closePipes - closes all pipes created by the compiler */ +/*-----------------------------------------------------------------*/ +DEFSETFUNC (closePipes) +{ + FILE *pfile = item; + int ret; + + if (pfile) { + ret = pclose (pfile); + assert(ret != -1); + } + + return 0; +} + /*-----------------------------------------------------------------*/ /* closeTmpFiles - closes all tmp files created by the compiler */ /* because of BRAIN DEAD MS/DOS & CYGNUS Libraries */ @@ -56,9 +73,12 @@ set *tmpfileNameSet = NULL; /* All are unlinked at close. */ DEFSETFUNC (closeTmpFiles) { FILE *tfile = item; + int ret; - if (tfile) - fclose (tfile); + if (tfile) { + ret = fclose (tfile); + assert(ret == 0); + } return 0; } @@ -70,12 +90,14 @@ DEFSETFUNC (closeTmpFiles) DEFSETFUNC (rmTmpFiles) { char *name = item; + int ret; - if (name) - { - unlink (name); + if (name) { + ret = unlink (name); + assert(ret == 0); Safe_free (name); - } + } + return 0; } @@ -86,6 +108,10 @@ void rm_tmpfiles (void) { /* close temporary files */ + applyToSet (pipeSet, closePipes); + /* close temporary files */ + deleteSet (&pipeSet); + applyToSet (tmpfileSet, closeTmpFiles); /* remove temporary files */ applyToSet (tmpfileNameSet, rmTmpFiles); @@ -1837,7 +1863,7 @@ tempfile(void) char fnamebuf[PATH_MAX]; if ((fd = tempfileandname(fnamebuf, sizeof fnamebuf)) == -1) { - fprintf(stderr, "Can't create temporary file name!"); + fprintf(stderr, "Can't create temporary file!"); exit(1); } @@ -1846,7 +1872,7 @@ tempfile(void) addSetHead(&tmpfileNameSet, tmp); if ((fp = fdopen(fd, "w+b")) == NULL) { - perror("Can't create temporary file name!"); + perror("Can't create temporary file!"); exit(1); } diff --git a/src/SDCCglue.h b/src/SDCCglue.h index e2a61cae..0f078d2d 100644 --- a/src/SDCCglue.h +++ b/src/SDCCglue.h @@ -37,6 +37,7 @@ int printIvalCharPtr (symbol *, sym_link *, value *, FILE *); extern symbol *interrupts[]; extern set *publics; extern set *tmpfileSet; +extern set *pipeSet; extern set *tmpfileNameSet; void rm_tmpfiles (void); -- 2.30.2