[project @ 1997-03-14 05:16:26 by sof]
[ghc-hetmet.git] / ghc / lib / cbits / freeFile.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1997
3 %
4 \subsection[freeFile.lc]{Giving up files}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 /* sigh, the standard channels are handled differently,
12    we don't want them freed via the ForeignObj finaliser,
13    as we probably want to use these channels before we
14    *really* shutdown (dumping stats etc.)
15 */
16 void freeStdChannel(fp)
17 StgForeignObj fp;
18 { return; }
19
20 void freeFile(fp)
21 StgForeignObj fp;
22 {
23     int rc;
24
25     if ( fp == NULL || (rc = unlockFile(fileno((FILE *)fp))) ) {
26         /* If the file handle has been explicitly closed
27          * (via closeFile()) or freed, we will have given
28          * up our process lock, so we silently return here.
29          */
30        return;
31     }
32
33     /*
34      * The finaliser for the FILEs embedded in Handles. The RTS
35      * assumes that the finaliser runs without problems, so all
36      * we can do here is fclose(), and hope nothing went wrong.
37      *
38      * Assume fclose() flushes output stream.
39      */
40
41     rc = fclose((FILE *)fp);
42     /* Error or no error, we don't care.. */
43
44     /* 
45     if ( rc == EOF ) {
46        fprintf(stderr. "Warning: file close ran into trouble\n");
47     }
48     */
49
50     return;
51 }
52 \end{code}