From 831045a741e9aa654c9aba325ac62c3129f02732 Mon Sep 17 00:00:00 2001 From: sof Date: Fri, 14 Mar 1997 05:16:26 +0000 Subject: [PATCH] [project @ 1997-03-14 05:16:26 by sof] FILE finaliser --- ghc/lib/cbits/freeFile.lc | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ghc/lib/cbits/freeFile.lc diff --git a/ghc/lib/cbits/freeFile.lc b/ghc/lib/cbits/freeFile.lc new file mode 100644 index 0000000..5c78076 --- /dev/null +++ b/ghc/lib/cbits/freeFile.lc @@ -0,0 +1,52 @@ +% +% (c) The GRASP/AQUA Project, Glasgow University, 1997 +% +\subsection[freeFile.lc]{Giving up files} + +\begin{code} + +#include "rtsdefs.h" +#include "stgio.h" + +/* sigh, the standard channels are handled differently, + we don't want them freed via the ForeignObj finaliser, + as we probably want to use these channels before we + *really* shutdown (dumping stats etc.) +*/ +void freeStdChannel(fp) +StgForeignObj fp; +{ return; } + +void freeFile(fp) +StgForeignObj fp; +{ + int rc; + + if ( fp == NULL || (rc = unlockFile(fileno((FILE *)fp))) ) { + /* If the file handle has been explicitly closed + * (via closeFile()) or freed, we will have given + * up our process lock, so we silently return here. + */ + return; + } + + /* + * The finaliser for the FILEs embedded in Handles. The RTS + * assumes that the finaliser runs without problems, so all + * we can do here is fclose(), and hope nothing went wrong. + * + * Assume fclose() flushes output stream. + */ + + rc = fclose((FILE *)fp); + /* Error or no error, we don't care.. */ + + /* + if ( rc == EOF ) { + fprintf(stderr. "Warning: file close ran into trouble\n"); + } + */ + + return; +} +\end{code} -- 1.7.10.4